Compare commits
No commits in common. "0895013cdcf7c3099f5df08001404f266cd756c0" and "ee4d976b2b83ff205acb4dbd6677d2ae9c0de18e" have entirely different histories.
0895013cdc
...
ee4d976b2b
@ -1,40 +0,0 @@
|
|||||||
//
|
|
||||||
// String.swift
|
|
||||||
// EmployeeDirectory
|
|
||||||
//
|
|
||||||
// Created by Matt Bruce on 1/20/25.
|
|
||||||
//
|
|
||||||
|
|
||||||
import Foundation
|
|
||||||
|
|
||||||
extension String {
|
|
||||||
/// Formats a string into a US phone number format (XXX-XXX-XXXX).
|
|
||||||
/// Non-numeric characters are removed, and formatting is applied based on the length of the string.
|
|
||||||
/// - Returns: A formatted phone number as a string.
|
|
||||||
internal func formatUSNumber() -> String {
|
|
||||||
// format the number
|
|
||||||
return format(with: "XXX-XXX-XXXX", phone: self)
|
|
||||||
}
|
|
||||||
|
|
||||||
internal func format(with mask: String, phone: String) -> String {
|
|
||||||
let numbers = filter { $0.isNumber }
|
|
||||||
var result = ""
|
|
||||||
var index = numbers.startIndex // numbers iterator
|
|
||||||
|
|
||||||
// iterate over the mask characters until the iterator of numbers ends
|
|
||||||
for ch in mask where index < numbers.endIndex {
|
|
||||||
if ch == "X" {
|
|
||||||
// mask requires a number in this place, so take the next one
|
|
||||||
result.append(numbers[index])
|
|
||||||
|
|
||||||
// move numbers iterator to the next index
|
|
||||||
index = numbers.index(after: index)
|
|
||||||
|
|
||||||
} else {
|
|
||||||
result.append(ch) // just append a mask character
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ public class EmployeeCellViewModel: ObservableObject {
|
|||||||
// Initialize properties
|
// Initialize properties
|
||||||
self.uuid = employee.uuid.uuidString
|
self.uuid = employee.uuid.uuidString
|
||||||
self.fullName = employee.fullName
|
self.fullName = employee.fullName
|
||||||
self.phoneNumber = employee.phoneNumber?.formatUSNumber()
|
self.phoneNumber = employee.phoneNumber
|
||||||
self.emailAddress = employee.emailAddress
|
self.emailAddress = employee.emailAddress
|
||||||
self.biography = employee.biography
|
self.biography = employee.biography
|
||||||
self.team = employee.team
|
self.team = employee.team
|
||||||
|
|||||||
@ -15,7 +15,6 @@
|
|||||||
## What do you think is the weakest part of your project?
|
## What do you think is the weakest part of your project?
|
||||||
|
|
||||||
## Did you copy any code or dependencies? Please make sure to attribute them here!
|
## Did you copy any code or dependencies? Please make sure to attribute them here!
|
||||||
### String.swift extension for dealing with TelephoneNumber from a generic regEx formatter I found on stackoverflow.
|
|
||||||
|
|
||||||
## Is there any other information you’d like us to know?
|
## Is there any other information you’d like us to know?
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user