KNContact

public struct KNContact
extension KNContact: Hashable
extension KNContact: Comparable
extension KNContact: Equatable

KNContact class is a wrapper class which gives quick access to helper methods for a CNContact, like their full name, birthday and age information, first email address or phone number.

Author

dragosrobertn

Version

1.2.2 *
  • id

    Quick access to the contacts identifier.

    Declaration

    Swift

    public var id: String { get }
  • A CNContact object representing the wrapped contact information.

    Declaration

    Swift

    public var info: CNContact
  • Initialises a KNContact object by wrapping a CNContact.

    Author

    dragosrobertn

    Version

    1.0.0

    Declaration

    Swift

    public init(for contact: CNContact)

    Parameters

    contact

    A CNContact.

  • Initialises a KNContact object by wrapping a CNContact.

    Author

    dragosrobertn

    Version

    1.0.2

    Declaration

    Swift

    public init(_ contact: CNContact)

    Parameters

    contact

    A CNContact.

  • Returns the full name of contacts using a formatting style (fullName or phoneticFullName).

    Author

    dragosrobertn

    Version

    1.2.1

    Declaration

    Swift

    public func fullName(format: CNContactFormatterStyle = .fullName) -> String

    Parameters

    format

    A CNContactFormatterStyle enum option. Optional. Defaults to .fullName

    Return Value

    A string representing the full name. It can be an empty string.

  • Returns the birthday of the contact as an optional date, if the contact has birthday information is available.

    Author

    dragosrobertn

    Version

    1.1.0

    Declaration

    Swift

    public func getBirthday(forCurrentYear: Bool = false) -> Date?

    Parameters

    forCurrentYear

    A boolean value representing if the birthday date should be returned for the current year. Optional. Defaults to false.

    Return Value

    A date representing the contact’s birthday or nil.

  • Helper method to return a formatted birthday using a KNTimeFormat.

    Author

    dragosrobertn

    Version

    1.1.0

    Declaration

    Swift

    public func formatBirthday(with format: KNDateTimeFormat = .dayAndMonth,
                           forCurrentYear : Bool = false) -> String

    Parameters

    with

    A KNTimeFormat enum option. Optional. Defaults to KNTimeFormat.dayAndMonth

    forCurrentYear

    A boolean value representing if the birthday date should be returned for the current year. Optional. Defaults to false.

    Return Value

    Returns a string representing a formatted birthday using the KNTimeFormat passed. If the contact doesn’t contain birthday information returns an empty string.

  • Helper method to return a formatted birthday using a string representing a date formatt.

    Author

    dragosrobertn

    Version

    1.1.0

    Declaration

    Swift

    public func formatBirthday(with format: String,
                           forCurrentYear: Bool = false) -> String

    Parameters

    with

    A string representing the date format desired to display the birthday. Required.

    forCurrentYear

    A boolean value representing if the birthday date should be returned for the current year. Optional. Defaults to false.

    Return Value

    Returns a string representing a formatted birthday using the format string passed. If the format is invalid or the contact doesn’t contain birthday information returns an empty string.

  • Helper method to get the first phone number available for the contact as string.

    Author

    dragosrobertn

    Version

    1.1.0

    Declaration

    Swift

    public func getFirstPhoneNumber() -> String

    Return Value

    Returns a string representing the first phone number available for a contact, or empty if the contact doesn’t have any phone numbers associated.

  • Helper method to get the first email address available for the contact as string.

    Author

    dragosrobertn

    Version

    1.1.0

    Declaration

    Swift

    public func getFirstEmailAddress() -> String

    Return Value

    Returns a string representing the first email address available for a contact, or empty if the contact doesn’t have any email addresses associated.

  • Helper method to find out if current date matches the contact’s birthday.

    Author

    dragosrobertn

    Version

    1.0.0

    Declaration

    Swift

    public func isBirthdayToday() -> Bool

    Return Value

    Returns a boolean value representing whether current date is the contact’s birthday.

  • Helper method to find out if current date matches the contact’s birthday.

    Author

    dragosrobertn

    Version

    1.2.2

    Declaration

    Swift

    public func birthdayMatches(date: Date) -> Bool

    Parameters

    date

    The date to which to compare the contact’s birthday

    Return Value

    Returns a boolean value representing whether the passed date matches the contact’s birthday

  • Helper method to find out if contact has an upcoming birthday in the following days.

    Author

    dragosrobertn

    Version

    1.2.1

    Declaration

    Swift

    public func isBirthdayComing(in days: Int, startingDate: Date = Date()) -> Bool

    Parameters

    in

    The number of days as an integer representing the number of days to check if the birthday is upcoming

    startingDate

    The date from which to start checking if the birthday is upcoming. Default is today’s date and the starting date will be excluded..

    Return Value

    Returns a bool representing whether the contact’s birthday is in the interval between the starting date and the number of following days provided by the days param. False if the contact doesn’t have birthday information available.

  • Helper method to find out if a contact’s age.

    Author

    dragosrobertn

    Version

    1.1.0

    Declaration

    Swift

    public func getAge(atNextBirthday: Bool = false) -> Int?

    Return Value

    Returns an optional integer representing the contact’s age if the birthday information including the year is available. Otherwise it returns nil.

  • Helper method to retrieve a contact’s age as string with option for current or turning age and an ordinal value e.g. If the contact is currently 29, it will return “29” for current age, “30” for age at next birthday and “30th” if ordinal representation.

    Author

    dragosrobertn

    Version

    1.1.0

    Declaration

    Swift

    public func getAgeAsString(atNextBirthday: Bool = false, asOrdinal: Bool = false) -> String!

    Return Value

    Returns an unwrapped String representing the contact’s age as an ordinal if the birthday information including the year is available. Otherwise it returns nil.

  • Implementation of Comparable protocol, by comparing the contact identifiers

    Declaration

    Swift

    public static func < (lhs: KNContact, rhs: KNContact) -> Bool
  • Implementation of Equatable protocol, by checking if the contact identifiers match

    Declaration

    Swift

    public static func == (lhs: KNContact, rhs: KNContact) -> Bool