The formatting error for the NSPredicate statement has been fixed. Unable to parse format string

I get an exception when trying to create an NSPredicate object that looks like this:

let searchPredicate = NSPredicate(format: "addonCategoryId IN \(idsArray)")

where idsArrayconsists of objects Intin the swift array. An exception occurs on this line. The console says:

2015-10-08 08: 21: 42.878 bkApp [2569: 510538] *** Application terminated due to uncaught exception "NSInvalidArgumentException", reason: "Unable to parse format string" addonCategoryId IN [5404, 5406] ""

What could be the problem? Thanks for watching. :)

+4
source share
1 answer

NSPredicate Objective-C. .

let searchPredicate = NSPredicate(format: "addonCategoryId IN \(idsArray)")
// result: addonCategoryId IN [5404, 5406]

:

let searchPredicate = NSPredicate(format: "addonCategoryId IN %@", idsArray)
// result: addonCategoryId IN {5404, 5406}

[] vs. {}, NSPredicate , .

+5

Source: https://habr.com/ru/post/1610678/


All Articles