Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't pass Date to NSPredicate(format: ...) without "as CVarArg"

Is this how I'm supposed to pass a Date to NSPredicate.init(format predicateFormat: String, arguments argList: CVaListPointer).

let endDate = Date()
NSPredicate(format: "endDate == %@", endDate as CVarArg)

It looks kinda clumsy, and I suspect I'm doing something wrong.

like image 948
netdigger Avatar asked Sep 20 '16 06:09

netdigger


1 Answers

The %@ format expect a Foundation object as argument, compare "Predicate Format String Syntax" in the "Predicate Programming Guide".

Therefore you have to cast the overlay type Date back to its Foundation counterpart NSDate:

let endDate = Date()
let pred = NSPredicate(format: "endDate == %@", endDate as NSDate)
like image 53
Martin R Avatar answered Oct 30 '22 17:10

Martin R