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

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


  • Follow-Ups:
    • Re: Generics Question
      • From: Michael de Haan  <email@hidden>
References: 
 >Generics Question (From: Michael de Haan  <email@hidden>)
 >Re: Generics Question (From: Michael de Haan  <email@hidden>)

  • Prev by Date: Re: CGFloat and literal floats in Swift
  • Next by Date: Re: CGFloat and literal floats in Swift
  • Previous by thread: Re: Generics Question
  • Next by thread: Re: Generics Question
  • Index(es):
    • Date
    • Thread