after migration to swift3, I have an issue that cannot fix
let fetchRequest: NSFetchRequest<User> = User.fetchRequest()
fetchRequest.predicate = NSPredicate(format: "id == %@", id)
my App crashes on second line, bad access, no reason. types are right, no log, nothing, just bad access. any suggestions?
Found a reason, predicate is wrong, cause id is Int64 type, have no idea what kind of predicate I need for this version of swift
The
%@
format expect a Foundation object as argument, compare "Predicate Format String Syntax" in the "Predicate Programming Guide".You can bridge the
Int64
toNSNumber
:or change the format to "long long":
Bridging all number types to
NSNumber
is possible as of Swift 3.0.1 (Xcode 8.1) with the implementation of SE-0139 Bridge Numeric Types to NSNumber and Cocoa Structs to NSValue.