I have this piece of code that works fine in Xcode6 (Swift 1.2) but not with 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 } }
The error appears in the line containing object.setValue, with the message:
Ambiguous use of 'setValue (_: forKey :)'
I think that it does not recognize an object of type NSManagedObject, but I'm not 100% sure, suggesting why this is very much appreciated.
source share