Re: Generics Question
Re: Generics Question
- Subject: Re: Generics Question
- From: Quincey Morris <email@hidden>
- Date: Sun, 26 Jul 2015 23:14:26 +0000
On Jul 26, 2015, at 15:49 , Michael de Haan <email@hidden> 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@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