How to define CoreData relationship in Swift?

前端 未结 4 1534
天命终不由人
天命终不由人 2020-12-17 18:04

In CoreData, I have defined an unordered to-many relationship from Node to Tag. I\'ve created an Swift entity like this:

import Cor         


        
4条回答
  •  别那么骄傲
    2020-12-17 18:18

    Building on @Keenle's answer, if you want to be cheeky and concise and be able to say

    node.tags.append(tag)
    

    one can wrap the call to self.mutableSetValueForKey:

    class Node: NSManagedObject {
    
        var tags: NSMutableOrderedSet {
            return self.mutableOrderedSetValueForKey("tags")
        }
    }
    

提交回复
热议问题