I am trying to save a record which I have make in the CloudKit dashboard.
@IBAction func signUpPressed(_ sender: AnyObject) {
let authInfo = AuthInfo()
authInfo.email = emailField.text!
authInfo.firstName = firstField.text!
authInfo.lastName = lastField.text!
authInfo.username = usernameField.text!
authInfo.password = passwordField.text!
let container = CKContainer.default()
let privateData = container.privateCloudDatabase
let record = CKRecord(recordType: "Authentication")
record.setValue(authInfo.email, forKey: "email")
record.setValue(authInfo.username, forKey: "username")
record.setValue(authInfo.firstName, forKey: "firstName")
record.setValue(authInfo.lastName, forKey: "lastName")
record.setValue(authInfo.password, forKey: "password")
privateData.save(record, completionHandler: { record, error in
if error != nil {
print(error)
} else {
}
And, I'm pretty sure that my code is ok. (CloudKit framework is definitely imported properly and CloudKit is enabled properly with valid developer account and container, no issue there) However I get an error saying that I my have an authorised account when I try and run this code. However, other similar questions seemed to have been solved by making sure that you are logged in to iCloud on the simulator (I am using Xcode 8), however I have checked and double checked that I am logged in to iCloud, so I have no idea what the issue is. How can I get around this. Is it actually something to do with my code?