Can't pass Date to NSPredicate(format: …) with

2019-04-03 18:17发布

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.

1条回答
看我几分像从前
2楼-- · 2019-04-03 18:47

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)
查看更多
登录 后发表回答