ios - CoreData conditionally fetching on NSDate using NSPredicate (swift) -
basically have entity called timeloc has 3 attributes: time, latitude , longitude. , types date, double , double respectively. got stuck when trying make request filter on attribute time.
here code:
... var appdel: appdelegate = (uiapplication.sharedapplication().delegate as! appdelegate) var context: nsmanagedobjectcontext = self.managedobjectcontext! var request = nsfetchrequest(entityname: "timeloc") var endtime = nsdate() var starttime = nsdate(timeintervalsincenow: -65) let predicate = nspredicate(format: "time>= \(starttime) , time<= \(endtime)") request.predicate = predicate var results: nsarray = context.executefetchrequest(request, error: nil)! ...
and got following error: 'unable parse format string "time>= 2015-07-14 03:24:03 +0000 , time<= 2015-07-14 03:25:08 +0000"'
how should fix this? have googled bit solutions found in objective-c. great if can answer me in swift.
edit: v-xtreme suggested, answer problem can find in glauco neves's answer this question
i guess sending parameters predicate in nsdate format :
let predicate = nspredicate(format: "time>= \(starttime) , time<= \(endtime)")
here starttime , endtime of type nsdate . try convert in string format , pass predicate . should work .
reference : nspredicate: filtering objects day of nsdate property
Comments
Post a Comment