I have realm with lists of other realm-objects.
import RealmSwift
class Company: Object {
dynamic var id = 0
dynamic var city = 0
dynamic var title = ""
dynamic var address = ""
dynamic var schedule = ""
dynamic var workBreak = ""
let categories = List<CompanyCategory>()
let phones = List<CompanyPhone>()
let sites = List<CompanySite>()
let emails = List<CompanyEmail>()
let services = List<CompanyService>()
let branches = List<CompanyBranche>()
}
class CompanyCategory: Object {
dynamic var id = 0
dynamic var name = ""
}
So, I have category id and I want to see which companies is refer to this category. Company may have several categories.
I find solution in Java and it works in my android app. Can somebody help me to write right predication? Sorry for my bad english (:
Realm Swift uses Cocoa's NSPredicate to represent queries. You can find some examples of the supported syntax in the Filtering section of the Realm Swift documentation , and more information about the syntax on NSPredicate Cheatsheet . From those two documents you'll arrive at something like the following for your query:
realm.objects(Company).filter("ANY categories.id = %@", id)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.