Xcode 9.3 - Nspredicate Bool Crash

How to write a BOOL predicate in Core Data?

From Predicate Programming Guide:

You specify and test for equality of Boolean values as illustrated in the following examples:

NSPredicate *newPredicate = [NSPredicate predicateWithFormat:@"anAttribute == %@", [NSNumber numberWithBool:aBool]];
NSPredicate *testForTrue = [NSPredicate predicateWithFormat:@"anAttribute == YES"];

You can also check out the Predicate Format String Syntax.

Fetch request not working in Swift 4.1

The placeholder %@ is for objects, the placeholder for a Bool is %d

However there is a simpler syntax if the argument is a constant

requestData.predicate = NSPredicate(format: "delete == FALSE")

App crash on sign in (xcode 9.3) EXC_BAD_ACCESS (code=1, address=0x1)

Have a similar issue with Facebook login - a work for me was found in the Xcode 9.3 release notes:

https://developer.apple.com/library/content/releasenotes/DeveloperTools/RN-Xcode/Chapters/Introduction.html#//apple_ref/doc/uid/TP40001051-CH1-DontLinkElementID_1

To quote them

In circumstances where protocol methods or base class methods defined
in Objective-C claim to take non-null arguments of type id in their
headers, but get invoked with nil values at runtime, Swift code
compiled by Xcode 9.3 that overrides those methods may crash when the
Swift implementations are invoked. (38675815) Workaround: Change the
Swift override to take a value of type Any?. For example, if you
implement the UIApplicationDelegate protocol's
application(_:open:sourceApplication:annotation:) method:

class AppDelegate: UIApplicationDelegate {
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
return true
}

The program may crash when passed nil as the annotation argument.
Avoid the crash by making the annotation argument have type Any?:

class AppDelegate: UIApplicationDelegate {
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any?) -> Bool {
return true
}


Related Topics



Leave a reply



Submit