ios - CloudKit fetchUserRecordIDWithCompletionHandler completion code not calling? -
i trying fetch current user id cloudkit using fetchuserrecordidwithcompletionhandler when run code, completion handler skipped over.
let container = ckcontainer.defaultcontainer() let publicdatabase = container.publicclouddatabase var userid: ckrecordid! container.fetchuserrecordidwithcompletionhandler( { recordid, error in if error == nil { userid = recordid } else { nslog("\(error.localizeddescription)") } }) let predicate = nspredicate(format: "personid = \(userid)") let query = ckquery(recordtype: "person", predicate: predicate)
because of this, value of userid stays nil
, , query throws exception because of it.
the completion handler run once fetch request complete, happen asynchronously. cannot use result of fetch request after call. move query completion handler of other part of code can called or otherwise triggered handler.
Comments
Post a Comment