• 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
Generics Problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Generics Problem
      • From: Jonathan Hull <email@hidden>
    • Re: Generics Problem
      • From: Quincey Morris <email@hidden>
  • Prev by Date: Slow Keyboard in iOS 9.0
  • Next by Date: Re: Generics Problem
  • Previous by thread: Slow Keyboard in iOS 9.0
  • Next by thread: Re: Generics Problem
  • Index(es):
    • Date
    • Thread