netigger netigger - 1 year ago 168
iOS Question

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

Is this how I'm supposed to pass a

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.

Answer Source

The %@ format expect a Foundation object as parameter, 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)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download