Last active
March 16, 2022 08:42
-
-
Save ashalva/822302eea9ca1a4019d418804f405126 to your computer and use it in GitHub Desktop.
Generates random contacts Swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private func saveRandomContact() { | |
let store = CNContactStore() | |
let contact = CNMutableContact() | |
// Name | |
contact.givenName = UUID().uuidString | |
// Phone | |
contact.phoneNumbers.append( | |
CNLabeledValue( | |
label: "mobile", | |
value: CNPhoneNumber( | |
stringValue: "+372\((0..<8).map { _ in String(Int.random(in: 0...9)) }.joined())" | |
) | |
) | |
) | |
// Save | |
let saveRequest = CNSaveRequest() | |
saveRequest.add(contact, toContainerWithIdentifier: nil) | |
try? store.execute(saveRequest) | |
} | |
let timer = Timer.scheduledTimer(withTimeInterval: 0.25, repeats: true) { [weak sefl] timer in | |
self?.saveRandomContact() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment