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.id
value.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
KNContact
from 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
by
A string representing an identifier to retrieve a contact from the contact book.
Return Value
If found, it returns the
KNContact
object from the contact book. Otherwise nil. -
Retrieves multiple
KNContact
objects from the contact book by using the passed array of KNContacts.Version
1.1.0
Parameters
by
An array of
KNContact
to retrieve updated information for a contact from the contact book.Return Value
If found, it returns an array of
KNContact
objects from the contact book. -
Retrieves multiple
KNContact
objects 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
by
An array of strings to retrieve updated information for multiple contacts from the contact book.
Return Value
If found, it returns an array of
KNContact
objects from the contact book. -
Appends a
KNContact
to the contact book, identified with the passed id parameterVersion
1.0.0
Declaration
Swift
public func add(_ contact: KNContact, id: String)
Parameters
contact
A
KNContact
object to be added to the contact book. Required.id
A String representing a way to uniquely identify the contact to be added. Required.
-
Removes a
KNContact
from 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
id
A 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
number
An integer representing the desired number of random elements. Required.
except
An array list of
KNContacts
to be excluded from being selected when choosing random contact. Optional. Defaults to including all contact.Return Value
Returns an array of randomly selected
KNContact
objects from the contact book. -
Checks if the contact book contains the passed
KNContact
.Version
1.0.0
Declaration
Swift
public func contains(element: KNContact) -> Bool
Parameters
element
An
KNContact
object 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()