Unable to parse the format string in RealmSwift

Model

class News: Object {
dynamic var ExternalId: String?
dynamic var Title: String?
dynamic var Preview: String?
dynamic var Description: String?
dynamic var PublicationDate: Date?
dynamic var ExternalUrl: String?
dynamic var ImageUrl: String?
dynamic var ViewTypeName: String?
dynamic var Status: Bool = true
dynamic var Like: Bool = false
dynamic var AuthorizedOnly: Bool = false

override static func primaryKey() -> String? {
    return "ExternalId"
}

Use code:

self.news = try! Realm().objects(News.self).filter("Like == YES").sorted(byProperty: "PublicationDate", ascending: true)

Error:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse the format string "Like == YES"'

I try:

Like = YES
Like = true
Like = 1

But it's not work!

please help!

Upvotes: 2

Views: 2964

Answers (1)

Dmitry
Dmitry

Reputation: 7350

It seems like NSPredicate treats Like as a keyword not the property name. As a workaround you can use something like that:

.filter(NSPredicate(format: "%K == true", "Like"))

Upvotes: 4

Related Questions