I am building an iOS application using Swift in which, I have a UIWebView that invokes the ViewController to have it perform certtain actions.
So the ViewController performs a series of actions and one of them is to get determine what day of the week it its. Using the following code,
let today = NSDate()
let calendar = NSCalendar(calendarIdentifier: NSGregorianCalendar)!
var components:Int = calendar.component(.WeekdayCalendarUnit, fromDate: today)
let oneDay = 60 * 60 * 24
let yesterday = today.dateByAddingTimeInterval(-(Double(oneDay)))
var yDayDay = calendar.component(.WeekdayCalendarUnit, fromDate: yesterday)
println("\(yDayDay)")
Now, this line
var components:Int = calendar.component(.WeekdayCalendarUnit, fromDate: today)
Throws the the following error,
<NSInvalidArgumentException> -[_NSCopyOnWriteCalendarWrapper component:fromDate:]: unrecognized selector sent to instance 0x15e921d0
On a device running iOS 7.1. The code works perfectly fine on iOS8 and above. So I cannot understand exactly what is causing this error on iOS 7.1. I assume it also applies to iOS7.
The functionality that I am trying to achieve with that method is to determine the day of the week. So now I have something that works on iOS8, but not iOS7.1 and below, how do I achieve that on both OS's. I assume I am not going to get an answer and the way this will play out is, the question may get downvoted and closed. But I wanted to give it a go none the less.