In relation, to my question:
My problem here is, how to create a predicate when working with “many to many” relations.
For example, I would like to return all instances of words that matches 1 tag (or more tags)
I will give a try here
let request: NSFetchRequest<Words> = Words.fetchRequest()
let predicate = NSPredicate(format: "withTagsOf CONTAINS %@", tag). // where tag is NSObject instance of Tags
I know that CONTAINS is for String Comparison, I just don’t know what to use if it is array
Then what more, if I need to get words that matches multiple tags?
Detail for reference:
I sumarized my 2 entity here
extension Words {
@nonobjc public class func fetchRequest() -> NSFetchRequest<Words> {
return NSFetchRequest<Words>(entityName: "Words")
}
@NSManaged public var character: String?
@NSManaged public var id: UUID?
//..... I removed other properties to simplify
@NSManaged public var withTagsOf: NSSet?
@NSManaged public var hasExamplesOf: NSSet?
}
extension Tags {
@nonobjc public class func fetchRequest() -> NSFetchRequest<Tags> {
return NSFetchRequest<Tags>(entityName: "Tags")
}
@NSManaged public var category: Int16
@NSManaged public var id: UUID?
@NSManaged public var name: String?
@NSManaged public var withWordsOf: NSSet?
}
//
Thanks in advance