I was writing a fetch request predicate as follows:

deleteRequest.predicate = NSPredicate(format: "id != %@", selectedEventId)

This is all well and good except it was aborting the app on the selectedEventId variable saying EXC_BAD_ACCESS. It took me a while to realize this was because I declared selectedEventId as the Int Swift type.

Changing selectedEventId to NSNumber fixed the problem:

var selectedEventId: NSNumber = 0

So apparently you have to use the NS* types in your predicates. I’m sure the Swift docs mentioned this somewhere or other.