Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/SwiftyContacts/SwiftyContacts
A Swift library for Contacts framework.
https://github.com/SwiftyContacts/SwiftyContacts
async-await contact-management contacts contacts-manager contacts-wrapper framework hacktoberfest ios macos swift watchos
Last synced: 2 days ago
JSON representation
A Swift library for Contacts framework.
- Host: GitHub
- URL: https://github.com/SwiftyContacts/SwiftyContacts
- Owner: SwiftyContacts
- License: mit
- Created: 2017-09-02T18:09:59.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2022-10-08T19:56:14.000Z (about 2 years ago)
- Last Synced: 2024-04-18T21:40:08.489Z (7 months ago)
- Topics: async-await, contact-management, contacts, contacts-manager, contacts-wrapper, framework, hacktoberfest, ios, macos, swift, watchos
- Language: Swift
- Homepage:
- Size: 42.7 MB
- Stars: 250
- Watchers: 9
- Forks: 45
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# SwiftyContacts
[![Language: Swift 5](https://img.shields.io/badge/language-Swift%205-f48041.svg?style=flat-square)](https://developer.apple.com/swift)
[![Version](https://img.shields.io/cocoapods/v/SwiftyContacts.svg?style=flat-square)](http://cocoapods.org/pods/SwiftyContacts)
[![License](https://img.shields.io/cocoapods/l/SwiftyContacts.svg?style=flat-square)](http://cocoapods.org/pods/SwiftyContacts)
[![Platform](https://img.shields.io/badge/platforms-iOS%209.0+%20%7C%20macOS%2010.12+%20%7C%20watchOS%203.0+-333333.svg?style=flat-square)](http://cocoapods.org/pods/SwiftyContacts)
[![Swift Package Manager](https://img.shields.io/badge/Swift%20Package%20Manager-compatible-brightgreen.svg?style=flat-square)](https://github.com/apple/swift-package-manager)
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat-square)](https://github.com/Carthage/Carthage)
[![CocoaPods compatible](https://img.shields.io/cocoapods/v/SwiftyContacts.svg?style=flat-square)](https://cocoapods.org/pods/SwiftyContacts)
[![RxSwift: Supported](https://img.shields.io/badge/RxSwift-Supported-f48041.svg?style=flat-square)](https://github.com/ReactiveX/RxSwift)
[![Read the Docs](https://img.shields.io/readthedocs/pip.svg?style=flat-square)](https://swiftycontacts.firebaseapp.com/)A Swift library for Contacts framework.
- [SwiftyContacts](#swiftycontacts)
- [Requirements](#requirements)
- [Installation](#installation)
- [CocoaPods](#cocoapods)
- [Swift Package Manager](#swift-package-manager)
- [Get started](#get-started)
- [async-await](#async-await)
- [Requests access to the user's contacts](#requests-access-to-the-users-contacts)
- [Request the current authorization status](#request-the-current-authorization-status)
- [Fetch all contacts from device](#fetch-all-contacts-from-device)
- [Fetch contacts matching a name.](#fetch-contacts-matching-a-name)
- [Fetch contacts matching an email address.](#fetch-contacts-matching-an-email-address)
- [Fetch contacts matching a phone number.](#fetch-contacts-matching-a-phone-number)
- [To fetch contacts matching contact identifiers.](#to-fetch-contacts-matching-contact-identifiers)
- [To fetch contacts matching group identifier](#to-fetch-contacts-matching-group-identifier)
- [find the contacts in the specified container.](#find-the-contacts-in-the-specified-container)
- [Fetch a contact with a given identifier.](#fetch-a-contact-with-a-given-identifier)
- [Add contact to the contact store.](#add-contact-to-the-contact-store)
- [Update contact to the contact store.](#update-contact-to-the-contact-store)
- [Delete contact to the contact store.](#delete-contact-to-the-contact-store)
- [Adds a group to the contact store.](#adds-a-group-to-the-contact-store)
- [Fetches all groups in the contact store.](#fetches-all-groups-in-the-contact-store)
- [Updates an existing group in the contact store.](#updates-an-existing-group-in-the-contact-store)
- [Deletes a group from the contact store.](#deletes-a-group-from-the-contact-store)
- [Find the contacts that are members in the specified group.](#find-the-contacts-that-are-members-in-the-specified-group)
- [Add a new member to a group.](#add-a-new-member-to-a-group)
- [Removes a contact as a member of a group.](#removes-a-contact-as-a-member-of-a-group)
- [closures](#closures)
- [Requests access to the user's contacts](#requests-access-to-the-users-contacts-1)
- [Fetch all contacts from device](#fetch-all-contacts-from-device-1)
- [Fetch contacts matching a name.](#fetch-contacts-matching-a-name-1)
- [Fetch contacts matching an email address.](#fetch-contacts-matching-an-email-address-1)
- [Fetch contacts matching a phone number.](#fetch-contacts-matching-a-phone-number-1)
- [Fetch contacts matching contact identifiers.](#fetch-contacts-matching-contact-identifiers)
- [Fetch contacts matching group identifier](#fetch-contacts-matching-group-identifier)
- [Find the contacts in the specified container.](#find-the-contacts-in-the-specified-container-1)
- [Fetch a contact with a given identifier.](#fetch-a-contact-with-a-given-identifier-1)
- [Adds the specified contact to the contact store.](#adds-the-specified-contact-to-the-contact-store)
- [Updates an existing contact in the contact store.](#updates-an-existing-contact-in-the-contact-store)
- [Deletes a contact from the contact store.](#deletes-a-contact-from-the-contact-store)
- [Fetches all groups matching the specified predicate.](#fetches-all-groups-matching-the-specified-predicate)
- [Adds a group to the contact store.](#adds-a-group-to-the-contact-store-1)
- [Updates an existing group in the contact store.](#updates-an-existing-group-in-the-contact-store-1)
- [Deletes a group from the contact store.](#deletes-a-group-from-the-contact-store-1)
- [Find the contacts that are members in the specified group.](#find-the-contacts-that-are-members-in-the-specified-group-1)
- [Add a new member to a group.](#add-a-new-member-to-a-group-1)
- [Removes a contact as a member of a group.](#removes-a-contact-as-a-member-of-a-group-1)
- [Author](#author)
- [License](#license)## Requirements
- iOS 11.0+ / Mac OS X 10.13+ / watchOS 4.0+
- Xcode 13.0+## Installation
### CocoaPods
[CocoaPods](http://cocoapods.org) is a dependency manager for Cocoa projects. You can install it with the following command:
```bash
$ gem install cocoapods
```To integrate SwiftyContacts into your Xcode project using CocoaPods, specify it in your `Podfile`:
```ruby
pod 'SwiftyContacts'
```Then, run the following command:
```bash
$ pod install
```### Swift Package Manager
The [Swift Package Manager](https://swift.org/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`.
```swift
dependencies: [
.package(url: "https://github.com/SwiftyContacts/SwiftyContacts.git", .upToNextMajor(from: "4.0.0"))
]
```## Get started
### async-await
#### Requests access to the user's contacts
```swift
let access = try await requestAccess()
```#### Request the current authorization status
```swift
let status = authorizationStatus()
print(status == CNAuthorizationStatus.authorized)
```#### Fetch all contacts from device
```swift
let contacts = try await fetchContacts()
```#### Fetch contacts matching a name.
```swift
let contacts = try await fetchContacts(matchingName: "Satish Babariya")
```#### Fetch contacts matching an email address.
```swift
let contacts = try await fetchContacts(matchingEmailAddress: "[email protected]")
```#### Fetch contacts matching a phone number.
```swift
let contacts = try await fetchContacts(matching: CNPhoneNumber(stringValue: "+919426678969"))
```#### To fetch contacts matching contact identifiers.
```swift
let contacts = try await fetchContacts(withIdentifiers: ["id1", "id2" ... ])
```#### To fetch contacts matching group identifier
```swift
let contacts = try await fetchContacts(withGroupIdentifier: "")
```#### find the contacts in the specified container.
```swift
let contacts = try await fetchContacts(withContainerIdentifier: "")
```#### Fetch a contact with a given identifier.
```swift
let contact = try await fetchContact(withIdentifier: "")
```#### Add contact to the contact store.
```swift
let contact = CNMutableContact()
contact.givenName = "Satish"
try addContact(contact)
```#### Update contact to the contact store.
```swift
guard let contact = contact.mutableCopy() as? CNMutableContact else {
return
}
contact.givenName = "Satish"
try updateContact(contact)
```#### Delete contact to the contact store.
```swift
guard let contact = contact.mutableCopy() as? CNMutableContact else {
return
}
try deleteContact(contact)
```#### Adds a group to the contact store.
```swift
try addGroup("My Group")
```#### Fetches all groups in the contact store.
```swift
let groups = try await fetchGroups()
```#### Updates an existing group in the contact store.
```swift
guard let group = group.mutableCopy() as? CNMutableGroup else {
return
}
try updateGroup(group)
```#### Deletes a group from the contact store.
```swift
try deleteGroup(group)
```#### Find the contacts that are members in the specified group.
```swift
let contacts = try fetchContacts(in: "My Group")
```#### Add a new member to a group.
```swift
try addContact(contact, to: group)
```#### Removes a contact as a member of a group.
```swift
try deleteContact(contact, from: group)
```### closures
#### Requests access to the user's contacts
```swift
requestAccess { result in
switch result {
case let .success(bool):
print(bool)
case let .failure(error):
print(error.localizedDescription)
}
}
```#### Fetch all contacts from device
```swift
fetchContacts { result in
switch result {
case let .success(contacts):
print(contacts)
case let .failure(error):
print(error.localizedDescription)
}
}
```#### Fetch contacts matching a name.
```swift
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.
```swift
fetchContacts(matchingEmailAddress: "[email protected]") { result in
switch result {
case let .success(contacts):
print(contacts)
case let .failure(error):
print(error.localizedDescription)
}
}
```#### Fetch contacts matching a phone number.
```swift
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.
```swift
fetchContacts(withIdentifiers: []) { result in
switch result {
case let .success(contacts):
print(contacts)
case let .failure(error):
print(error.localizedDescription)
}
}
```#### Fetch contacts matching group identifier
```swift
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.
```swift
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.
```swift
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.
```swift
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.
```swift
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.
```swift
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.
```swift
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.
```swift
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.
```swift
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.
```swift
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.
```swift
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.
```swift
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.
```swift
removeContact(contact, from: group) { result in
switch result {
case let .success(contact):
print(contact)
case let .failure(error):
print(error.localizedDescription)
}
}
```## Author
Satish Babariya, [email protected]
## License
SwiftyContacts is available under the MIT license. See the LICENSE file for more info.