First you need to find out what the current login in userId is. You can do this by running the fetchUserRecordIDWithCompletionHandler method in the container. Then you can get more (currently only the first and last name) by running the discoveryUserInfoWithUserRecordID command in this container.
You can expand the Users table with additional custom fields, but I would not recommend it. The Users table is a special system table with some limitations. It would be better to create a separate post type with user preferences. For ease of access, just add the CKReference to the users table.
You should also be aware that a user can log out and log in with a different iCloud account while your application is running. You can fix this by running the code below immediately after starting your application. Of course you must implement your own logic when you see NSLog
var ubiquityIdentityDidChangeNotificationToken = NSNotificationCenter.defaultCenter().addObserverForName(NSUbiquityIdentityDidChangeNotification, object: nil, queue: nil) { _ in NSLog("The user's iCloud login changed: should refresh all user data.") }
Edwin vermeer
source share