Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Let's debug...
- Let's break your predicate first:
- let afterPredicate = NSPredicate(format: "timestamp >= %f, startTimeStamp)
- let beforePredicate = NSPredicate(format: "timestamp < %f", endTimeStamp)
- let combinedPredicate = NSCompoundPredicate(andPredicateWithSubpredicates: [afterPredicate, beforePredicate])
- With:
- func executeRequest(predicate: NSPredicate) -> [Item] {
- let request = NSFetchRequest<Item>(entityName: "Item")
- request.predicate = predicate
- var items: [Item] = []
- context.performAndWait {
- do {
- let fetched = try context.fetch(request)
- items.append(contentsOf: fetched)
- } catch {
- print(error)
- }
- }
- return items
- }
- Now, let's test it:
- let after = executeRequest(predicate: afterPredicate)
- print("After: \(after)")
- let before = executeRequest(predicate: beforePredicate)
- print("Before: \(before)")
- let combined = executeRequest(predicate: combinedPredicate)
- print("Combined: \(combined)")
- let all = executeRequest(predicate: NSPredicate(value: true))
- let filterAfter = all.filter { afterPredicate.evaluate(with: $0) }
- print("FilterAfter: \(filterAfter)")
- let filterBefore = all.filter { beforePredicate.evaluate(with: $0) }
- print("FilterBefore: \(filterBefore)")
- let filterCombined = all.filter { predicate.evaluate(with: $0) }
- print("FilterCombined: \(filterCombinedAfter)")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement