App crashed on NSPredicate with out stack trace

时间:2018-10-02 09:18:49

标签: ios swift nspredicate

I have to filter out some data from a list in a Realm database. I have saved record of students in database. I have seen it and confirm it using Realm database browser. To filter data from database Realm used predicate in their examples under the DOCS and samples. So the following is the predicate where my app is crashing:

let resultPredicate = NSPredicate(format: "IsRecordDeleted == false AND StdListId == %@ AND UserId == %@ AND Status == %@", stdModel.Id, 45,Status.Active.rawValue)

here Status.Active.rawValue is my enum that is returning an integer value.

If I remove the following part from the string predicate it runs as expected:

let resultPredicate = NSPredicate(format: "IsRecordDeleted == false AND StdListId == %@",stdModel.Id)

So I'm thinking that I might have some value null or anything wrong with the values etc. I have double checked it, but all values are there and were right as expected.

I am really clueless as there is no stacktrace or log whatever you can say it. I am new to iOS and Swift. I tried to read Predicate on Apple doc but those were in Objective-C.

Is there someone who can simply tell me what I am doing wrong and what should be done when writing the predicate? Or at least give me one example to write predicate having multiple placeholders and values.

0 个答案:

没有答案