0

I have this very simple code:

class ESTime: NSObject {

   let hours:Int
   let minutes:Int

   init(withHours hours:Int, andMinutes minutes:Int)
   {
      self.hours   = hours
      self.minutes = minutes
   }
}

It doesn't compile. The error message is:

'with' is for the first parameter of an initialiser; did you mean to name this parameter 'hours'?

However, if I change withHours into anything else like byHours or fromHoursit compiles ok. Why so? What's wrong with with?

Andrey Chernukha
  • 21,488
  • 17
  • 97
  • 161
  • I think this is a simple naming convention. How about `init(hours hours:Int, minutes minutes:Int)` – freshking Sep 11 '14 at 09:44
  • @freshking it produces a warning 'hours hours can be expressed more succinctly as '#hours''. If I then change hours hours to #hours it produces another warning 'extraneous # parameter; hours is already keyword argument name' – Andrey Chernukha Sep 11 '14 at 09:48
  • Im sorry, I meant `init(Hours hours:Int, Minutes minutes:Int)` – freshking Sep 11 '14 at 09:51

0 Answers0