For example, if you create an entity called "Data" in CoreData, you can use
Suppose you create Type:Date Attribute, "day" in it.
And when I tried to pull the day for a particular date (I will ignore the time), I got the following code:
let appDel: AppDelegate=UIApplication.sharedApplication().delegate as!AppDelegate
Let PersonContext: NSManagedObjectContext=appDel.managedObjectContext!
let PersonRequest: NSFetchRequest=NSFetchRequest(entityName: "Data")
PersonRequest.returnsObjectsAsFaults=false
let predict = NSPredicate(format: "%K=???"", "day", ????)
PersonRequest.predicate=predicate
var results:NSArray!=PersonContext.executeFetchRequest(PersonRequest, error:nil)</code>
In the letter prediction in the fifth line, what kind of code should I type in the ???? section?
I'm at a loss because I don't know if I should search for the desired date.
How can I pull a specific date from the entity?
It may be insufficient explanation, but if anyone understands, please explain.
swift coredata
let calendar:NSCalendar!=NSCalendar(identifier:NSCalendarIdentifierGregorian)
let targetDay: NSDate!= calendar.dateWithEra (1, year: 2015, month:5, day:12, hour:0, minute:0, second:0, nanosecond:0)
let predict = NSPredicate(format: "SELF.day BETWEEN{%@,%@}", targetedDay, NSDate(timeInterval: 24*60*60-1, sinceDate: targetedDay))
For example, you can create a specific NSDate
and take the next 24 hours - 1 second in BETWEEN
. You can use SELF.day
for day
.
If you have data up to milliseconds, you should use SELF.day>=%@ANDSELF.day<%@
to determine the exact duration.
© 2025 OneMinuteCode. All rights reserved.