{"id":24755977,"url":"https://github.com/dragosrobertn/kncontacts","last_synced_at":"2025-10-03T22:37:53.138Z","repository":{"id":56917437,"uuid":"178767688","full_name":"dragosrobertn/KNContacts","owner":"dragosrobertn","description":"Wrapper for CNContacts for easier access, ordering and scheduling.","archived":false,"fork":false,"pushed_at":"2021-03-03T00:28:54.000Z","size":423,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-27T19:05:09.551Z","etag":null,"topics":["cocoapod","ios","swift"],"latest_commit_sha":null,"homepage":"https://dragosrobertn.github.io/KNContacts/","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dragosrobertn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-04-01T02:01:16.000Z","updated_at":"2023-02-01T03:31:12.000Z","dependencies_parsed_at":"2022-08-21T03:50:32.825Z","dependency_job_id":null,"html_url":"https://github.com/dragosrobertn/KNContacts","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dragosrobertn%2FKNContacts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dragosrobertn%2FKNContacts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dragosrobertn%2FKNContacts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dragosrobertn%2FKNContacts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dragosrobertn","download_url":"https://codeload.github.com/dragosrobertn/KNContacts/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":236021139,"owners_count":19082415,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cocoapod","ios","swift"],"created_at":"2025-01-28T13:30:00.207Z","updated_at":"2025-10-03T22:37:53.066Z","avatar_url":"https://github.com/dragosrobertn.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# KNContacts \n[![Cocoapods](https://img.shields.io/cocoapods/v/KNContacts.svg)](https://cocoapods.org/pods/KNContacts) ![CI](https://github.com/dragosrobertn/KNContacts/workflows/CI/badge.svg) [![codecov](https://codecov.io/gh/dragosrobertn/KNContacts/branch/master/graph/badge.svg)](https://codecov.io/gh/dragosrobertn/KNContacts) [![codebeat badge](https://codebeat.co/badges/a2cc6f89-a90d-4583-a9fd-b50a4e66767a)](https://codebeat.co/projects/github-com-dragosrobertn-kncontacts-master) ![contributions](https://img.shields.io/badge/contributions-welcome-informational.svg)\n\nKNContacts is wrapper for CNContacts for easier access to information like current age and age at next birthday, full contact name, creating contact books (groups), ordering them and creating contact schedules.\n\n### More information\n\nKNContacts framework features a couple of classes, structs and enums to facilitate access to contacts, contact books and schedule of contacts.\n\n| Type            | Name                                    | Description  |\n| ------------- | -------------------------------- | -------------- |\n| struct          | [KNContact](https://github.com/dragosrobertn/KNContacts/blob/master/KNContacts/KNContact.swift)                           | Wrapper struct for CNContact, provides access to helper methods and original contact details. |\n| class           | [KNContactBook](https://github.com/dragosrobertn/KNContacts/blob/master/KNContacts/KNContactBook.swift)                   | Collection of KNContacts with methods for adding, removing, sorting and retrieving specific or random elements |\n| struct          | [KNContactBookOrdering](https://github.com/dragosrobertn/KNContacts/blob/master/KNContacts/KNContactBookOrdering.swift)   | Helper ordering methods to sort contacts in KNContactBook  |\n| struct          | [KNContactsSchedule](https://github.com/dragosrobertn/KNContacts/blob/master/KNContacts/KNContactsSchedule.swift)         | Dictionary wrapper for creating contact schedule for using custom time formats for scheduling and retrieving at a particular time  |\n| struct          | [KNDatesUtils](https://github.com/dragosrobertn/KNContacts/blob/master/KNContacts/KNDatesUtils.swift)                     | Date formatting helper methods |\n| enum            | [KNTimeFormat](https://github.com/dragosrobertn/KNContacts/blob/master/KNContacts/KNTimeFormat.swift)                     | Enum with pre-defined time formats |\n\n## Documentation\n[You can check the full documentation here.](https://dragosrobertn.github.io/KNContacts/)\n\n## Usage\n\n*Sample initialisation and usage*\n\n### `KNContact` and `KNContactBook`\n[KNContact](https://github.com/dragosrobertn/KNContacts/blob/master/KNContacts/KNContact.swift) is a wrapper structure and you can initialise a new obejct by passing in a CNContact or CNMutableContact object. [KNContactBook](https://github.com/dragosrobertn/KNContacts/blob/master/KNContacts/KNContactBook.swift) is a collection of KNContact objects which can be sorted and random elements extracted.\n\n```swift\nimport Contacts\nimport KNContacts\n\nvar contactBook = KNContactBook(id: \"allContacts\")\n\n// Retrieve or create your CNContact list from a store - KNContacts does *not* handle authorisation for you.\n// Make sure you have all necessary key descriptors.\n\nvar keys = [CNContactGivenNameKey, CNContactMiddleNameKey, CNContactFamilyNameKey,\n            CNContactEmailAddressesKey, CNContactBirthdayKey, CNContactPhoneNumbersKey,\n            CNContactFormatter.descriptorForRequiredKeys(for: .fullName)] as! [CNKeyDescriptor]\n\nlet requestForContacts = CNContactFetchRequest(keysToFetch: keys)\n\ndo {\n    try CNContactStore().enumerateContacts(with: requestForContacts) { (cnContact, _) in\n        let knContact = KNContact(cnContact)\n        contactBook.add(knContact)\n    }\n} catch let error {\n    // Handle error somehow!\n    print(error)\n}\n\n// And then perform actions on KNContactBook\nlet randomContacts = contactBook.randomElements(number: 1)\nlet randomElements = contactBook.randomElements(number: 3, except: randomContacts)\n\nrandomElements.forEach({ (contact) in \n    print(contact.fullName(format: .fullName))\n    if (contact.isBirthdayToday()) {\n        print(\"It's their birthday today!\")\n    } else if (contact.isBirthdayComing(in: 7)) {\n        print(\"Birthday coming up in the next week!\")\n    } else {\n        print(\"Birthday on \\(contact.formatBirthday())\")\n    }\n})\n```\n### `KNContactsSchedule`,  `KNContactBookOrdering`, `KNDatesUtils`\n\n[KNContact](https://github.com/dragosrobertn/KNContacts/blob/master/KNContacts/KNContact.swift) can also return ordered array of elements. Two options are provided in [KNContactBookOrdering](https://github.com/dragosrobertn/KNContacts/blob/master/KNContacts/KNContactBookOrdering.swift)\nBut the `toArray(orderedBy:)` method can take any sorting function.\n[KNDatesUtils](https://github.com/dragosrobertn/KNContacts/blob/master/KNContacts/KNDatesUtils.swift) provides easy access to string date formatters.\n\n```swift\nlet order = KNContactBookOrdering.thisYearsBirthday\nlet contactsSortedByBirthday = contactBook.contacts.sorted(by: order)\n\n// And finally schedules can be created for easier retrieval at a later date.\nvar thisWeeksBirthdaySchedule = KNContactsSchedule(name: \"birthdaysThisYear\")\n\nfor numberOfDays in 1...7 {\n    let birthdayList = contactsSortedByBirthday.filter({ $0.isBirthdayComing(in: numberOfDays) }).map({ $0.id })\n    let date = Calendar.current.date(byAdding: .day, value: numberOfDays, to: Date())!\n    let dateString = KNDatesUtils.formatter(with: .fullDate).string(from: date)\n    thisWeeksBirthdaySchedule.add(list: birthdayList, to: dateString)\n}\n\n// And retrieve schedule by date\nlet tomorrow = Calendar.current.date(byAdding: .day, value: 1, to: Date())!\nlet schedule = thisWeeksBirthdaySchedule.getSchedule(for: tomorrow)\n```\n\n### Requirements\n| KNContacts version |  Swift Version | Package Managers Supported              |\n|------------------------|-----------------|------------------------------------|\n| from `v1.3.0`          | Swift 5.0         | Swift Package Manager, Cocoapods |\n| from `v1.2.0`          | Swift 5.0         | Cocoapods                        |\n| up to `v1.1.1`         | Swift 4.2         | Cocoapods                        |\n\n### Usage\nKNContacts is currently available using CocoaPods and Swift Package Manager. Just add this snippet into your podfile to use the latest version.\n\n#### Cocoapods\n\n```ruby\npod 'KNContacts'\n```\n\nor specify the desired version.\n```ruby\npod 'KNContacts', '~\u003e 1.0.0'\n```\n#### Swift Package Manager\nOnce you have SPM set up, add this package to the dependencies. SPM has been supported only since version 1.3.0.\n\n```swift\ndependencies: [\n    .package(url: \"https://github.com/dragosrobertn/KNContacts.git\", .upToNextMajor(from: \"1.3.0\"))\n]\n```\n\n### Applications using KNContacts\n- [KINN - Contacts Manager](https://itunes.apple.com/app/kinn/id1343398089)\n\nIf your app uses KNContacts, feel free to submit a Pull Request.\n\n### Contributing\nPull requests are welcome, all changes should be accompanied by tests and a passing build. \n\nIssues or features requests are welcome, feel free to create implementations yourself. The development of this framework is done using trunk based development strategy so please create your pull requests against the master branch and ensure the build is passing.\n\n### License\n[This library is MIT Licensed](https://github.com/dragosrobertn/KNContacts/blob/master/LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdragosrobertn%2Fkncontacts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdragosrobertn%2Fkncontacts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdragosrobertn%2Fkncontacts/lists"}