7

before Swift3, in a my project I used this function:

var components = (calendar as NSCalendar).components([.year, .monthSymbols, .firstWeekday, .timeZone, .hour, .minute], from: data_corrente)

Now I'm changing the project using swift 3 (xCode8 beta5) but I have this error:

Type 'NSCalendar.Unit has no member 'monthSymbol'

Can someone explain where is the problem and help me to solve it? I think is a migration problem

Lorenzo
  • 3,293
  • 4
  • 29
  • 56
  • 1
    Instead of downcasting to NSCalendar, just use Calendar, with "dateComponents" and short syntax for components: http://stackoverflow.com/a/38720438/2227743 – Eric Aya Aug 13 '16 at 09:51
  • 1
    Are you using the same project as the guy in this question: http://stackoverflow.com/questions/38920909/xcode-8-and-swift-3-nscalendar ? `timeZone`, `monthSymbol` and `firstWeekday` have never been calendar units / components. – vadian Aug 13 '16 at 09:59
  • I removed forstWeekDay and monthSymbol... even if in the previous version all were compiled with success – Lorenzo Aug 13 '16 at 10:01
  • Swift 3 is still beta ... – vadian Aug 13 '16 at 10:02
  • When I use Xcode 7 ... the compiler don't show me error.. – Lorenzo Aug 13 '16 at 10:03
  • Which calendar class in Swift 2 requires to be bridged to `NSCalendar`? – vadian Aug 13 '16 at 10:09

1 Answers1

9

In Swift3 with Xcode8 beta. You can use Calendar instead of NSCalendar as like this:

let calendar = Calendar.current
let component = calendar.dateComponents([.day,.month,.year], from: Date())
technerd
  • 14,144
  • 10
  • 61
  • 92