Why can't I use signatures on a CKRecord object in swift?

It bothered me a little. Is there a reason I need to do this to set the object to CKRecord.

task.record?.setObject(task.reference, forKey:ReferenceField) 

instead of this

 task.record?[ReferenceField] = task.reference 

From what I read in the docs, CKRecord should be index-friendly

+4
source share
1 answer

This subscriber is only available from Objective-C, as it is implemented using objectForKeyedSubscript: and setObject:forKeyedSubscript: Fortunately, it is easy to extend CKRecord to enable Swift recharge:

 extension CKRecord { subscript(key: String) -> AnyObject! { get { return self.objectForKey(key) } set(newValue) { self.setObject(newValue as CKRecordValue, forKey: key) } } } 

NSHipster has a post in Objective-C subscriptip if you want to know more. I am surprised that Swift does not automatically connect.

+4
source

Source: https://habr.com/ru/post/978772/


All Articles