> On Sep 19, 2015, at 1:46 PM, Jens Alfke <[email protected]> wrote:
>
>
>> On Sep 19, 2015, at 11:26 AM, Quincey Morris
>> <[email protected]
>> <mailto:[email protected]>> wrote:
>>
>> It looks like Swift is incapable of resolving the specialization of U when
>> there is more than one generic type specifier:
>
> Maybe it’s because the second type-spec T isn’t defined when the function is
> called. In both Michael’s and your examples, it doesn’t look to me as though
> the compiler has enough information at the call site to figure out what T
> should be. In Michael’s case I think T needs to be bound to the return type
> of self.moExistsWith, but working that out requires parsing the interior of
> the function being called (createMOforEntityName). That’s the sort of thing
> C++ can do because templates are really a type of macro expansion, but I’m
> not sure Swift’s compiler works that way.
>
> —Jens
Jens, Jonathan and Quincey
Thanks.
Just for completeness, here is the missing function… not sure if that changes
things. Mean time, I will try the suggestions.
func moExistsWith<T,U>(entityName:String, key:String , keyAttribute:U) -> T? {
var predicate:NSPredicate! = nil
self.entityName = entityName
if keyAttribute is Double {
predicate = NSPredicate(format: "%K == %f", key, keyAttribute as!
Double)
} else if keyAttribute is String {
predicate = NSPredicate(format: "%K == %@", key, keyAttribute as!
String)
}
let results = self.fetchAll(predicate!, sortDescriptors: nil)
if results!.count == 0 {
return nil
}
let foundMO = results!.last
return foundMO as? T
}
_______________________________________________
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]