Swift enum and NSCoding

I have a "Thing" object with a String property and an NSImage property; the Thing class has encodeWithCoder: and decodeWithCoder: methods, and I can archive and unlock the [Thing] array using NSKeyedArchiver / Unarchiver.

So far so good. Now I want to extend the Thing class with an array of directions, where "Direction" is the following enumeration:

enum Direction{

case North(direction:String)
case East(direction:String)
case South(direction:String)
case West(direction:String)

}

In other words, the data I want to save is

thing1.directions: Direction = [.North("thing2"), .South("thing3")]

(In a better world, I will use direct links to my things, not just their names, but I understand that this will easily create link loops - cannot set a link to another thing until this thing has been created - so I I’m looking for a quick and dirty method to save my application data and continue.)

, , Thing. ( , .)

NSCoding? , , [String: String] "" "" "thing2" "thing3" enum , ? , , NSCoding, (String, String) " " AnyObject ".

.

+4
2

, , , description , . ( - ), , , .

+5

All Articles