Skip to content

Instantly share code, notes, and snippets.

@ashalva
Last active March 16, 2022 08:42
Show Gist options
  • Save ashalva/822302eea9ca1a4019d418804f405126 to your computer and use it in GitHub Desktop.
Save ashalva/822302eea9ca1a4019d418804f405126 to your computer and use it in GitHub Desktop.
Generates random contacts Swift
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