• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Generics Problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Generics Problem


  • Subject: Re: Generics Problem
  • From: Michael de Haan  <email@hidden>
  • Date: Sat, 19 Sep 2015 19:16:22 -0700

> On Sep 19, 2015, at 1:46 PM, Jens Alfke <email@hidden> wrote:
>
>
>> On Sep 19, 2015, at 11:26 AM, Quincey Morris <email@hidden <mailto:email@hidden>> 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@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


References: 
 >Generics Problem (From: Michael de Haan  <email@hidden>)
 >Re: Generics Problem (From: Quincey Morris <email@hidden>)
 >Re: Generics Problem (From: Jens Alfke <email@hidden>)

  • Prev by Date: Re: Generics Problem
  • Next by Date: Tracking down source of [_NSControllerObjectProxy copyWithZone:]… error
  • Previous by thread: Re: Generics Problem
  • Next by thread: Re: Generics Problem
  • Index(es):
    • Date
    • Thread