Last active
March 11, 2019 11:31
-
-
Save sisoje/a9226fc4c00613cc62648140480783ef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func inPredicateBad<S: Sequence>(_ values: S) -> NSComparisonPredicate { | |
let ex1 = NSExpression(forKeyPath: \S.Element.self) | |
let ex2 = NSExpression(forConstantValue: values) | |
return NSComparisonPredicate(leftExpression: ex1, rightExpression: ex2, modifier: .direct, type: .in) | |
} | |
func inPredicateOk<S: Sequence>(_ values: S) -> NSComparisonPredicate { | |
let ex1 = NSExpression.expressionForEvaluatedObject() | |
let ex2 = NSExpression(forConstantValue: values) | |
return NSComparisonPredicate(leftExpression: ex1, rightExpression: ex2, modifier: .direct, type: .in) | |
} | |
func refetch<S: Sequence>(_ context: NSManagedObjectContext, _ sequence: S) throws -> [S.Element] where S.Element: NSManagedObject { | |
let request = S.Element.fetchRequest() as! NSFetchRequest<S.Element> | |
request.predicate = inPredicateBad(sequence) | |
return try context.fetch(request) | |
} | |
let crashArray = try! refetch(currentBackgroundContext, arrayOfFaultedObjectsFromAnotherContext) | |
/* Crash log example: | |
CoreData: error: SQLCore dispatchRequest: exception handling request: <NSSQLFetchRequestContext: 0x600001797020> , unimplemented SQL generation for predicate : (#self IN {<DMStatusSendingPending: 0x600000d3a210> (entity: DMStatusSendingPending; id: 0x90de07f9ad97c6de <x-coredata://43CA7069-0B00-4104-A655-982F4A525339/DMStatusSendingPending/p44> ; data: <fault>)}) with userInfo of (null) | |
libc++abi.dylib: terminating with uncaught exception of type NSException | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment