Author Topic: Chapter 7 - "#" doesn't work any more  (Read 6711 times)

Bublovskiy

  • Newbie
  • *
  • Posts: 5
    • View Profile
Chapter 7 - "#" doesn't work any more
« on: November 14, 2015, 05:10:12 PM »
Good day,

Enjoying the second book very much. So explicably written. Though I just want to notice a little thing.
I've been trying to use "#" as it's presented in the given example (p.103 in iBooks):

func multiply (#a: Double, time  b:Double) -> Double {
 return a*b
}

Got a message saying "# has been removed from Swift......Fix it Replace # with a"

I guess now the only way to determine external and internal names of a parameter is by using the syntax:  func multiply (a a: Double, time  b:Double)

Is it correct ?

Thank you.
Maxim.




kjmcneish

  • Administrator
  • *****
  • Posts: 719
    • View Profile
Re: Chapter 7 - "#" doesn't work any more
« Reply #1 on: November 14, 2015, 07:11:32 PM »
Maxim,

Glad you're enjoying the book!

Yes, you're right...I missed this one in the recent update. You no longer use the hash tag, but you simply repeat the parameter name. Here's the updated text:

If you would prefer to give the first parameter in your method both an external and internal name, you can repeat the parameter name, and Swift will create an external parameter name that is the same as the internal parameter name. For example, if you insert an a before the first parameter name:

Code: [Select]
func multiply(a a: Double, times b: Double) -> Double
{
    return a * b;
}

Then you call the method like this:
calculator.multiply(a:5, times: 10)

All the best!
Kevin

Bublovskiy

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Chapter 7 - "#" doesn't work any more
« Reply #2 on: November 14, 2015, 09:31:52 PM »
Thank you very much Kevin!