Here's a code snippet that compiles and works as expected, but I get a warning for depricated use of the unit .NSYearCalendarUnit.
This is within XCode 7 (Swift 2.0)
Playground execution failed: /var/folders/37/2hl0kpw50lv18q1d48gbbb5r0000gn/T/./lldb/16158/playground8.swift:52:20: warning: 'NSYearCalendarUnit' was deprecated in iOS 8.0: Use NSCalendarUnitYear instead
var TermEndDate = NSDate()
if (TermYears>0) {
TermEndDate = userCalendar.dateByAddingUnit(
NSCalendarUnit.NSYearCalendarUnit,
value: TermYears,
toDate: TermStartDate,
options: .WrapComponents )!
}
if (leaseMonths>0) {
TermEndDate = userCalendar.dateByAddingUnit(
NSCalendarUnit.NSMonthCalendarUnit,
value: TermMonths,
toDate: TermEndDate,
options: .WrapComponents )!
}
/var/folders/37/2hl0kpw50lv18q1d48gbbb5r0000gn/T/./lldb/16158/playground8.swift:60:5: error: 'NSCalendarUnit.Type' does not have a member named 'NSCalendarUnitMonth'
NSCalendarUnit.NSCalendarUnitMonth,
^ ~~~~~~~~~~~~~~~~~~~
I've dug through the documentation and can't find what I'm doing wrong.
Thoughts?
Thanks!!!
They renamed some enums / options to be more consistent.
In Swift, it would now be NSCalendarUnit.Year (type NSCalendarUnit, case .Year). If you double command-click on NSCalendarUnit (or NSYearCalendarUnit) in Xcode in your playground, it will pull up the Swift version of the header.
And as far as the example code goes, OptionSets are handled differently now in Swift 2.0 and use set syntax instead of bitwise operators to join and test them.
See the Xcode 7 beta release notes or https://forums.developer.apple.com/thread/3623 for more info on that.