Generics Problem
Generics Problem
- Subject: Generics Problem
- From: Michael de Haan <email@hidden>
- Date: Sat, 19 Sep 2015 10:54:51 -0700
I am calling this function,
func createMOforEntityName<T, U >(entityName:String, context:NSManagedObjectContext, key:String, keyAttribute: U) -> (Bool, T) {
guard let mo:T = self.moExistsWith(entityName, key:key, keyAttribute: keyAttribute) else {
let mo:T = NSEntityDescription.insertNewObjectForEntityForName(entityName, inManagedObjectContext: context) as! T
return (false, mo)
}
return (true, mo)
}
with this call:
let (already_Exists, aNewMO:ESLSizeMO) = createMOforEntityName("ESLSizeEntity", context: self.managedObjectContext, key:"sizeName", keyAttribute: sizeName)
In this case, sizeName is a String, but key attribute could also be a Double. The Error is on the calling line:
Cannot invoke 'createMOforEntityName' with an argument list of type '(String, context: NSManagedObjectContext, key: String, keyAttribute: String)'
The hint says: 'Expected an argument list of type '(String, context: NSManagedObjectContext, key: String, keyAttribute: U)’
My question is how to call “createMOforEntityName” when ‘U’ could either be a String, or a Double.
Thanks in advance.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden