KNContactBook
public class KNContactBook
KNContactBook class is a collection of KNContact objects to help with
contact grouping, sorting and selecting random elements.
Version
1.1.0 *-
The contact book identifier or name.
Declaration
Swift
public var id: String -
An read-only list of all identifiers used to retrieve the contacts by in the contact book. These can be custom, but by default they use the
KNContacts.idvalue.Declaration
Swift
public var identifiers: [String] { get } -
A read-only array list of all contacts in the contact book.
Declaration
Swift
public var contacts: [KNContact] { get } -
A read-only array list of all contact identifiers stored in the contact book. It represents the identifiers of KNContacts stored in the contact book, as opposed to how the contact book identifies the entries.
Declaration
Swift
public var contactIdentifiers: [String] { get } -
The number of entries in the contact book
Declaration
Swift
public var count: Int { get } -
Initialiser with an identifier representing a way to name or identify the contact book.
Version
1.0.0
Declaration
Swift
public init(id: String) -
Retrieves a
KNContactfrom the contact book by using the passed key identifier.Version
1.1.0
Warning
This method force unwraps the value and it can return nil if asked to return an element that doesn’t exist. If unsure if the KNContact exists in the contact book, use
KNContactBook().getOptional(forKey:)instead.Declaration
Swift
public func getContact(by contactID: String) -> KNContact!Parameters
byA string representing an identifier to retrieve a contact from the contact book.
Return Value
If found, it returns the
KNContactobject from the contact book. Otherwise nil. -
Retrieves multiple
KNContactobjects from the contact book by using the passed array of KNContacts.Version
1.1.0
Parameters
byAn array of
KNContactto retrieve updated information for a contact from the contact book.Return Value
If found, it returns an array of
KNContactobjects from the contact book. -
Retrieves multiple
KNContactobjects from the contact book by using the passed array of KNContacts.Version
1.1.0
Declaration
Swift
public func getContacts(by contactIds: [String]) -> [KNContact]Parameters
byAn array of strings to retrieve updated information for multiple contacts from the contact book.
Return Value
If found, it returns an array of
KNContactobjects from the contact book. -
Appends a
KNContactto the contact book, identified with the passed id parameterVersion
1.0.0
Declaration
Swift
public func add(_ contact: KNContact, id: String)Parameters
contactA
KNContactobject to be added to the contact book. Required.idA String representing a way to uniquely identify the contact to be added. Required.
-
Removes a
KNContactfrom the contact book if it can find it in the contact book by the passed String identifier.Version
1.0.0
Declaration
Swift
public func remove(_ id: String)Parameters
idA string value representing the unique identifier to attempt removal from the contact book.
-
A method to return a number of random elements from the contact book. If the number of contacts in the contact book is lower than the requested number, or lower than the number after excluding the passed contact, it will return an array list of the rest of the available contacts, which count can be lower than requested or even empty.
Version
1.0.0
Parameters
numberAn integer representing the desired number of random elements. Required.
exceptAn array list of
KNContactsto be excluded from being selected when choosing random contact. Optional. Defaults to including all contact.Return Value
Returns an array of randomly selected
KNContactobjects from the contact book. -
Checks if the contact book contains the passed
KNContact.Version
1.0.0
Declaration
Swift
public func contains(element: KNContact) -> BoolParameters
elementAn
KNContactobject to be checked if it already exists in the contact book.Return Value
Return a boolean representing whether the contact book containts the passed
KNContact. -
Resets the contact book by invalidating the stored contact entries.
Version
1.0.0Declaration
Swift
public func reset()
View on GitHub
Install in Dash
KNContactBook Class Reference