Reputation: 3637
I have a message
array. Each message has a timestamp
property that's an Int
. I'm trying to sort out the array based on the most recent date, but I'm getting an error saying:
Value of type 'Int' has no member 'intValue'
self.messages.sort(by: { (message1, message2) -> Bool in
return message1.timestamp!.intValue > message2.timestamp!.intValue
})
Upvotes: 0
Views: 2362
Reputation: 236370
The error message it is pretty self explanatory timestamp it is not a NSNumber
it is an Int
therefore you can compare them directly. If you are sure the timestamp will never be nil it is better change its declaration to non-optional:
messages.sort { $0.timestamp > $1.timestamp }
Upvotes: 2