Tag: 归档

iCloud – 如何保存包含自定义对象数组的存档

我已经开发了一个小应用程序,通过归档一组自定义对象在iOS中本地存储,其中包含: @property (nonatomic, copy) NSString *name; @property (nonatomic, copy) NSString *dateCreated; @property (nonatomic, copy) NSString *desc; @property (nonatomic, copy) NSString *url; 我想要使​​用iCloud同步所述档案,我相信推荐的机制是通过一个UIDocument子类。 所有UIDocument的例子我发现使用1个单一的NSString的单个实例,所以我有点困惑如何去同步整个自定义对象的数组,但利用UIDocument(就像我今天通过NSCoding本地做的那样)。 我是否应该创build一个包含上面列出的属性的UIDocument对象数组,是否应该创build一个包含上述数据对象实例的UIDocument实例,然后创build一个包含所有实例的数组,或者应该1个单个UIDocument包含完整的数组自定义对象? 我做了一些研究,但我仍然困惑。 最后,我需要同步只有一个文件,其中包含所述自定义对象的数组。 在此先感谢您的帮助 我今天有一个自定义类,如上所述的4个string称为片段,并在我的根视图控制器我有一个NSMutableArray调用列表,我添加该片段类的每个新的实例。 self.list = [[NSMutableArray alloc] init]; Snippet *newEntry = [[Snippet alloc] init]; [self.list addObject:newEntry]; 我应该创build一个拥有自定义对象数组的UI文档子类吗?

浮点INFINITY可以归档NSCoder,但不是dearchived

我必须将值为INFINITY的float归档,然后将其归档。 这是我的示例代码: 要归档的对象: @interface CodeInf : NSObject <NSCoding> @end @implementation CodeInf – (void)encodeWithCoder:(NSCoder *)encoder { float inf = INFINITY; [encoder encodeFloat: inf forKey:@"INFINITY"]; } – (id)initWithCoder:(NSCoder *)decoder { if (self = [super init]) { float decodedInf = [decoder decodeFloatForKey: @"INFINITY"]; } return self; } @end 这里是归档/解码代码: CodeInf *myCodeInf = [[CodeInf alloc] init]; NSData *data = […]

有没有比用NSCoder编码和解码所有东西更好的方式来保存自定义类到NSUserDefaults?

我当前的类有大约50行只是编码和解码variables,以便我的类是NSUserDefaults兼容。 有没有更好的方法来处理这个问题? 例: init(coder aDecoder: NSCoder!) { lightEnabled = aDecoder.decodeBoolForKey("lightEnabled") soundEnabled = aDecoder.decodeBoolForKey("soundEnabled") vibrateEnabled = aDecoder.decodeBoolForKey("vibrateEnabled") pulseEnabled = aDecoder.decodeBoolForKey("pulseEnabled") songs = aDecoder.decodeObjectForKey("songs") as! [Song] currentSong = aDecoder.decodeIntegerForKey("currentSong") enableBackgroundSound = aDecoder.decodeBoolForKey("enableBackgroundSound") mixSound = aDecoder.decodeBoolForKey("mixSound") playSoundInBackground = aDecoder.decodeBoolForKey("playSoundInBackground") duckSounds = aDecoder.decodeBoolForKey("duckSounds") BPMBackground = NSKeyedUnarchiver.unarchiveObjectWithData(aDecoder.decodeObjectForKey("BPMBackgorund") as! NSData) as! UIColor! BPMPulseColor = NSKeyedUnarchiver.unarchiveObjectWithData(aDecoder.decodeObjectForKey("BPMPulseColor") as! NSData) as! UIColor! TempoBackGround = […]

在有效架构中使用armv7s有什么优势?

我正在开发支持iOS 4.3及更高版本的iOS应用程序。 由于一些框架,我不能归档为armv7s,所以我已经删除armv7s的支持。 会降低应用程序性能吗? 使用armv7的优点是什么?