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

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -