swift2 - NSManagedObject.setValue(value: AnyObject?, forKey key: String) causes error in Swift 2.0 -
i have piece of code working ok in xcode6 (swift 1.2) not swift 2:
class func findorcreate<t: nsmanagedobject>(type: t.type, attribute: string, value: anyobject?) -> t { if let object = t.mr_findfirstbyattribute(attribute, withvalue: value) as? t { return object } else { let object = t.mr_createentity() as! t if let value:anyobject = value { object.setvalue(value, forkey: attribute) } return object } }
error shows on line containing object.setvalue message:
ambiguous use of 'setvalue(_:forkey:)'
i think not recognise object of nsmanagedobject type i'm not 100% sure, clue why happens appreciated.
i've posted same question on apple forum , got answer workaround problem:
let object = t.mr_createentity() as! nsmanagedobject if let value:anyobject = value { object.setvalue(value, forkey: attribute) } return object as! t
this works expected. i've submitted bug report apple well.
Comments
Post a Comment