On Jul 26, 2015, at 15:49 , Michael de Haan  <[email protected]> wrote:
> 
> func genericTFor<T>(s:String) -> T {
> 
>    return T(s)!
> 
> }
> 
> 
> 
> let intFromStr = intFor("9")
> let intFromStrB:Double = genericTFor("9")
> <<<<<<<<<<<<<<<<
> 
> in other words, write a generic function that will return an Int, Double for 
> a given string value, depending upon the input i.e. T

Generics aren’t templates, which is what you’d need for this to work. However, 
what are you really trying to do? Your last example can just as well be written:

        let intFromStrB = Double (“9”)

What you really need to do depends on what you’re really trying to achieve.



_______________________________________________

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]

Reply via email to