CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:
$ gem install cocoapods
To integrate SwiftyContacts into your Xcode project using CocoaPods, specify it in your Podfile:
pod 'SwiftyContacts'
Then, run the following command:
$ pod install
Swift Package Manager
The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler. It is in early development, but SwiftyContacts does support its use on supported platforms.
Once you have your Swift package set up, adding SwiftyContacts as a dependency is as easy as adding it to the dependencies value of your Package.swift.
guard let group = group.mutableCopy() as? CNMutableGroup else {
return
}
try updateGroup(group)
Deletes a group from the contact store.
try deleteGroup(group)
Find the contacts that are members in the specified group.
let contacts = try fetchContacts(in: "My Group")
Add a new member to a group.
try addContact(contact, to: group)
Removes a contact as a member of a group.
try deleteContact(contact, from: group)
closures
Requests access to the user’s contacts
requestAccess { result in
switch result {
case let .success(bool):
print(bool)
case let .failure(error):
print(error.localizedDescription)
}
}
Fetch all contacts from device
fetchContacts { result in
switch result {
case let .success(contacts):
print(contacts)
case let .failure(error):
print(error.localizedDescription)
}
}
Fetch contacts matching a name.
fetchContacts(matchingName: "Satish") { result in
switch result {
case let .success(contacts):
print(contacts)
case let .failure(error):
print(error.localizedDescription)
}
}
Fetch contacts matching an email address.
fetchContacts(matchingEmailAddress: "satish.babariya@gmail.com") { result in
switch result {
case let .success(contacts):
print(contacts)
case let .failure(error):
print(error.localizedDescription)
}
}
Fetch contacts matching a phone number.
fetchContacts(matching: CNPhoneNumber(stringValue: "+919426678969")) { result in
switch result {
case let .success(contacts):
print(contacts)
case let .failure(error):
print(error.localizedDescription)
}
}
Fetch contacts matching contact identifiers.
fetchContacts(withIdentifiers: []) { result in
switch result {
case let .success(contacts):
print(contacts)
case let .failure(error):
print(error.localizedDescription)
}
}
Fetch contacts matching group identifier
fetchContacts(withGroupIdentifier: "") { result in
switch result {
case let .success(contacts):
print(contacts)
case let .failure(error):
print(error.localizedDescription)
}
}
Find the contacts in the specified container.
fetchContacts(withContainerIdentifier: "") { result in
switch result {
case let .success(contacts):
print(contacts)
case let .failure(error):
print(error.localizedDescription)
}
}
Fetch a contact with a given identifier.
fetchContact(withIdentifier: "") { result in
switch result {
case let .success(contact):
print(contact)
case let .failure(error):
print(error.localizedDescription)
}
}
Adds the specified contact to the contact store.
let contact = CNMutableContact()
contact.givenName = "Satish"
addContact(contact) { result in
switch result {
case let .success(contact):
print(contact)
case let .failure(error):
print(error.localizedDescription)
}
}
Updates an existing contact in the contact store.
guard let contact = contact.mutableCopy() as? CNMutableContact else {
return
}
contact.givenName = "Satish"
updateContact(contact) { result in
switch result {
case let .success(contact):
print(contact)
case let .failure(error):
print(error.localizedDescription)
}
}
Deletes a contact from the contact store.
guard let contact = contact.mutableCopy() as? CNMutableContact else {
return
}
deleteContact(contact) { result in
switch result {
case let .success(contact):
print(contact)
case let .failure(error):
print(error.localizedDescription)
}
}
Fetches all groups matching the specified predicate.
fetchGroups() { result in
switch result {
case let .success(groups):
print(groups)
case let .failure(error):
print(error.localizedDescription)
}
}
Adds a group to the contact store.
addGroup("My Group") { result in
switch result {
case let .success(group):
print(group)
case let .failure(error):
print(error.localizedDescription)
}
}
Updates an existing group in the contact store.
guard let group = group.mutableCopy() as? CNMutableGroup else {
return
}
updateGroup(group) { result in
switch result {
case let .success(group):
print(group)
case let .failure(error):
print(error.localizedDescription)
}
}
Deletes a group from the contact store.
guard let group = group.mutableCopy() as? CNMutableGroup else {
return
}
deleteGroup(group) { result in
switch result {
case let .success(group):
print(group)
case let .failure(error):
print(error.localizedDescription)
}
}
Find the contacts that are members in the specified group.
fetchContacts(in: "My Group") { result in
switch result {
case let .success(contacts):
print(contacts)
case let .failure(error):
print(error.localizedDescription)
}
}
Add a new member to a group.
addContact(contact, to: group) { result in
switch result {
case let .success(contact):
print(contact)
case let .failure(error):
print(error.localizedDescription)
}
}
Removes a contact as a member of a group.
removeContact(contact, from: group) { result in
switch result {
case let .success(contact):
print(contact)
case let .failure(error):
print(error.localizedDescription)
}
}
SwiftyContacts
A Swift library for Contacts framework.
Requirements
Installation
CocoaPods
CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:
To integrate SwiftyContacts into your Xcode project using CocoaPods, specify it in your
Podfile
:Then, run the following command:
Swift Package Manager
The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the
swift
compiler. It is in early development, but SwiftyContacts does support its use on supported platforms.Once you have your Swift package set up, adding SwiftyContacts as a dependency is as easy as adding it to the
dependencies
value of yourPackage.swift
.Get started
async-await
Requests access to the user’s contacts
Request the current authorization status
Fetch all contacts from device
Fetch contacts matching a name.
Fetch contacts matching an email address.
Fetch contacts matching a phone number.
To fetch contacts matching contact identifiers.
To fetch contacts matching group identifier
find the contacts in the specified container.
Fetch a contact with a given identifier.
Add contact to the contact store.
Update contact to the contact store.
Delete contact to the contact store.
Adds a group to the contact store.
Fetches all groups in the contact store.
Updates an existing group in the contact store.
Deletes a group from the contact store.
Find the contacts that are members in the specified group.
Add a new member to a group.
Removes a contact as a member of a group.
closures
Requests access to the user’s contacts
Fetch all contacts from device
Fetch contacts matching a name.
Fetch contacts matching an email address.
Fetch contacts matching a phone number.
Fetch contacts matching contact identifiers.
Fetch contacts matching group identifier
Find the contacts in the specified container.
Fetch a contact with a given identifier.
Adds the specified contact to the contact store.
Updates an existing contact in the contact store.
Deletes a contact from the contact store.
Fetches all groups matching the specified predicate.
Adds a group to the contact store.
Updates an existing group in the contact store.
Deletes a group from the contact store.
Find the contacts that are members in the specified group.
Add a new member to a group.
Removes a contact as a member of a group.
Author
Satish Babariya, satish.babariya@gmail.com
License
SwiftyContacts is available under the MIT license. See the LICENSE file for more info.