Reputation: 21
I'm getting this error in line/code that I'm using to return a grouped events. I read a lot of this error, but found only posts that explains this error about buttons, text labels or views. Is it wrong syntax or what?
class someManager: NSObject {
func eventFrom(from startDate: NSDate, to endDate: NSDate) -> [Any] {
let groupedEvents = NSMutableArray()
// some code
let sortDescriptor = NSSortDescriptor.init(key: "startDate", ascending: true)
return groupedEvents.sortedArray(using: [sortDescriptor]) // error here
}
}
*/
@property(nonatomic, copy) NSDate *startDate;
// cmd + press on startDate
/*
Full error message:
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[AppName.EventListController 0x170225340 valueForUndefinedKey:]: this class is not key value coding-compliant for the key startDate.'
All EventListController:
class EventListController: NSObject {
var AstartDate = Date()
var Aevents = NSArray()
}
Upvotes: 0
Views: 504
Reputation: 1862
I think that your mutable array contains object of NSDate type. If you want to sort this array you can apply the sort
function from Array Swift class
var groupEvent: [Date] = [ Date() ]
groupEvent.sort(by: { $0 < $1 })
or
groupEvent.sort()
Upvotes: 1