PatriciaW PatriciaW - 1 year ago 87
Swift Question

SWIFT: How do I create a predicate with an Int value?

I hope that no one tells me to RTFM because I have been struggling with this for some time here and on Apple Developer and doing lots of searching.

I am getting an EXC-BAD-ACCESS error on this statement:

var thisPredicate = NSPredicate(format: "(sectionNumber == %@"), thisSection)

thisSection has an Int value of 1 and displays the value 1 when I hover over it. But in the debug area I see this:

thisPredicate = (_ContiguousArrayStorage ...)

Another predicate using a String shows as ObjectiveC.NSObject
Why is this happening?

Answer Source

You might try String Interpolation Swift Standard Library Reference. That would look something like this:

let thisSection = 1
let thisPredicate = NSPredicate(format: "sectionNumber == \(thisSection)")