This has bothered me for a little while. Is there a reason why I need to do this to set an object on a CKRecord.
task.record?.setObject(task.reference, forKe
That subscripting is only available from Objective-C, since it's implemented using objectForKeyedSubscript:
and setObject:forKeyedSubscript:
. Happily, it's easy to extend CKRecord
to allow Swift subscripting:
extension CKRecord {
subscript(key: String) -> AnyObject! {
get {
return self.objectForKey(key)
}
set(newValue) {
self.setObject(newValue as CKRecordValue, forKey: key)
}
}
}
NSHipster has a post on Objective-C subscripting if you want to know more. I'm surprised Swift doesn't bridge that automatically.