ContactDictionaryParser
public struct ContactDictionaryParser : ContactParser
Default implementation of the ContactParser protocol.
Parse contact data from json. Each key from JSON represents property name from CNMutableContact type.
Example:
{
"contactType": "person",
"givenName": "Michael"
}
DateComponents is represented as a JSON dictionary:
Example:
{
"birthday": {
"year": 2016,
"month": 5,
"day": 19
}
}
CNLabeledValue is represented as a JSON dictionary.
The dictionary key is used as label.
The value from the dictionary for the key is used as value.
Example:
{
"date1": {
"year": 2017,
"month": 2,
"day": 17
}
}
Dates, social profiles, phone numbers, email addresses, url addresses, postal addresses, contact relationships and instant message addresses are constructed as a list of dictionaries.
Example:
{
"phoneNumbers": [
{
"work": {
"stringValue": "0 1234567890"
}
},
{
"mobile": {
"stringValue": "0 1234567890"
}
},
{
"nil": {
"stringValue": "0 1234567890"
}
}
]
}
Note
"nil" in the dictionary keys are converted to nil value.
Seealso
Seealso
For full example check contacts.json file in the test project.
-
Contact store used for saving contacts.
Declaration
Swift
public var store: CNContactStore
-
Initialize parser with contact store.
Declaration
Swift
public init(with store: CNContactStore = CNContactStore())Parameters
storeContact store used for saving contacts.
-
Parse JSON dictionary (represented as
Any) and return parsed contact object.Declaration
Swift
public func parse(_ data: Any) throws -> CNMutableContactParameters
dataJSON dictionary to parse.
Return Value
Parsed contact.
ContactDictionaryParser Structure Reference