Tag: nscoder

Objective C – 如何使用initWithCoder方法?

我有我的类打算加载一个nib文件和实例化对象的以下方法: – (id)initWithCoder:(NSCoder*)aDecoder { if(self = [super initWithCoder:aDecoder]) { // Do something } return self; } 如何实例化这个类的对象? 这个NSCoder是什么? 我如何创build它? MyClass *class = [[MyClass alloc] initWithCoder:aCoder];

我如何使用NSCoder快速编码枚举?

背景 我想使用NSCoding协议编码一个string样式的枚举,但我正在运行到转换为和返回从string的错误。 解码和编码时出现以下错误: string不能转换为舞台 额外的参数ForKey:在调用 码 enum Stage : String { case DisplayAll = "Display All" case HideQuarter = "Hide Quarter" case HideHalf = "Hide Half" case HideTwoThirds = "Hide Two Thirds" case HideAll = "Hide All" } class AppState : NSCoding, NSObject { var idx = 0 var stage = Stage.DisplayAll override init() {} […]