Tom Tom - 10 months ago 94
iOS Question

CVaListPointer when using objectsWhere() querying Realm database

I'm updating my code to swift 3.0. I use Realm for the database. I have the following line of code:

let thisJob = Jobs.objectsWhere("identifier == '\(identify)'")

The compiler throws an error because an extra argument is required. "Missing argument for parameter 'args' in call" The parameter is a CVaListPointer. I'm not sure how I'm supposed to use this argument. I tried:

let thisJob = Jobs.objectsWhere("identifier == '\(identify)'", args: CVaListPointer)

However, the compiler error with that line is "Cannot convert value of type CVaListPointer.Type to expected argument CVaListPointer."

Answer Source

Varargs in Objective-C interfaces aren't imported in Swift, which is why Realm has made a Swift wrapper for Realm Objective-C available: RLMSupport.swift. Add that to your project's source files as described in Realm's installation instructions and you'll be able to use Jobs.objectsWhere("identifier == '\(identify)'").

Though if identify can at all contain characters that should be escaped when doing string interpolation, you're better off passing it as a format argument:

Jobs.objectsWhere("identifier == %@", identify)