我尝试保存数据对象,这次是使用CoreData。现在,这些类看起来像这样:
class Game: NSManagedObject {
@NSManaged var id: String
@NSManaged var name: String
@NSManaged var matches: NSOrderedSet
}
class Match: NSManagedObject {
@NSManaged var date: String
@NSManaged var id: String
@NSManaged var players: NSOrderedSet
@NSManaged var parentGame: Game
}
class Player: NSManagedObject {
@NSManaged var history: String
@NSManaged var id: String
@NSManaged var name: String
@NSManaged var totalScore: NSNumber
@NSManaged var parentMatch: Match
}
所以Game类有一个NSOrderedSet,它应该包含一堆Match对象,依此类推。因此,使用CoreData,如何将Matches添加到Game类中的Set中,将Players添加到匹配中?然后如何添加它们后如何配置它们?
答案 0 :(得分:1)
使我的类继承自NSCoding和NSObject
您继承自NSObject
并实施NSCoding
协议。
NSUserDefaults
,则需要对每个属性进行编码和解码。 http://nshipster.com/nscoding/