Skip to content

Instantly share code, notes, and snippets.

@skreutzberger
Last active August 31, 2018 04:13
Show Gist options
  • Save skreutzberger/3f51fe7885eda4f25aee to your computer and use it in GitHub Desktop.
Save skreutzberger/3f51fe7885eda4f25aee to your computer and use it in GitHub Desktop.
get iCloud User ID
import CloudKit
/// async gets iCloud record ID object of logged-in iCloud user
func iCloudUserIDAsync(complete: (instance: CKRecordID?, error: NSError?) -> ()) {
let container = CKContainer.defaultContainer()
container.fetchUserRecordIDWithCompletionHandler() {
recordID, error in
if error != nil {
print(error!.localizedDescription)
complete(instance: nil, error: error)
} else {
print("fetched ID \(recordID?.recordName)")
complete(instance: recordID, error: nil)
}
}
}
@lukasstehr
Copy link

container.fetchUserRecordIDWithCompletionHandler() { ... } should probably be container.fetchUserRecordIDWithCompletionHandler({ ... })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment