Reputation: 114
I'm trying to get today's date
import Foundation
class Date {
var calendar = NSCalendar.currentCalendar()
var day = calendar.component(NSCalendarUnit.Day, fromDate: NSDate())
}
But I keep getting error
Instance member 'calendar' cannot be used on type 'Date'
Upvotes: 1
Views: 2233
Reputation: 236260
You can't access calendar property at instantiation time:
Try like this:
class Date {
let calendar = NSCalendar.currentCalendar()
var day: Int {
return calendar.component(.Day, fromDate: NSDate())
}
}
print(Date().day) // 17
Upvotes: 2