If you only need U to be a String or a Double, have you tried using a protocol instead (and then having both String & Double adhere to it). It doesn’t explain the compiler error, but it might work.
I would also recommend using as? instead of as! here. Thanks, Jon > On Sep 19, 2015, at 10:54 AM, Michael de Haan <[email protected]> wrote: > > 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 protected]) > > 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: > https://lists.apple.com/mailman/options/cocoa-dev/jhull%40gbis.com > > This email sent to [email protected] _______________________________________________ Cocoa-dev mailing list ([email protected]) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [email protected]
