iosswiftxcodecontactscncontainer

How do I get access to the externalIdentifier of a CNContainer object in iOS using Swift with Xcode?


How do I get access to the externalIdentifier of a CNContainer object?

externalIdentifier is not an instance property of the CNContainer object. I printed to the debug window the description property of a CNContainer object. I show that below, with "externalIdentifier" in bold.

<CNContainer: 0x2829a43f0: identifier=32B14F4B-7299-4AA5-BADD-85344DB3D7B8, name=Contacts, type=3 ( CardDAV ), iOSLegacyIdentifier=1346, accountIdentifier=012AF8C6-A3AB-4AD6-8C91-5FB5266CC8E6, enabled=1, permissions=<CNContainerPermissions: 0x2819a21e0: canCreateContacts=NO, canDeleteContacts=NO, canCreateGroups=NO>, externalIdentifier=/dav/brenebrownfan/Contacts/, externalModificationTag=c7e1249ffc03eb9ded908c236bd1996d, externalSyncTag=(nil), externalSyncData={length = 95, bytes = 0x62706c69 73743030 d2010203 045e6d61 ... 00000000 0000003a }, constraintsPath=(nil), meIdentifier=635, restrictions=0, guardianRestricted=0, lastSyncDate=2019-09-25 08:14:59 +0000>


Solution

  • Swift:

    let externalIdentifier = container.value(forKey: "externalIdentifier") as? String

    Objective-C:

    NSString *externalIdentifier = [container valueForKey:@"externalIdentifier"];