- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 NSString 对象的 NSMutableaArray。所以我正在使用 NSKeyedArchiever 将它保存到磁盘。所以当我尝试使用
- (void)encodeWithCoder:(NSCoder *)aCoder {
[aCoder encodeObject:self.EventsList forKey:@"Events"];
}
我遇到了一个错误
Event encodeWithCoder:]: unrecognized selector sent to instance 0x7fd06b542780
这是我的部分代码:
//-------------------Events.h--------------------------
@interface Event : NSObject
@property (strong,nonatomic) NSString *nameOfEvent;
@property (strong,nonatomic) NSString *dateOfEvent;
@property (strong,nonatomic) NSString *placeOfEvent;
@property int priorityOfEvent;
@end
//---------------Singleton.h ----------------
@interface GlobalSingleton : NSObject <NSCoding, NSCopying> {
NSMutableArray *EventsList;
}
@property (nonatomic,retain) NSMutableArray *EventsList;
+(GlobalSingleton *)sharedFavoritesSingleton;
@end
//----------------Singleton.m------------------------
....
@implementation GlobalSingleton
@synthesize EventsList;
....
....
- (void)encodeWithCoder:(NSCoder *)aCoder {
NSLog (@"%@",EventsList); // not nil
[aCoder encodeObject:self.EventsList forKey:@"Events"];
}
- (id)initWithCoder:(NSCoder *)aDecoder {
if ((self = [super init])) {
NSMutableArray *temp = [[NSMutableArray alloc] initWithArray:[aDecoder decodeObjectForKey:@"Events"]];
self.EventsList = temp;
}
return self;
}
- (id)copyWithZone:(NSZone *)zone {
GlobalSingleton *copy = [[GlobalSingleton allocWithZone:zone] init];
copy.EventsList = self.EventsList;
return copy;
}
@end
我使用 JSON 格式的 ASIFormDataRequest 从 Web 服务器获取文本数据,然后我将这个对象添加到 NSMutableArray,它也是一个单例,所以它看起来像这样:
NSDictionary *responseDict = [responseString JSONValue];
GlobalSingleton *Singleton = [GlobalSingleton sharedFavoritesSingleton];
for (NSDictionary *str in responseDict) {
Event *newEvent = [[Event alloc] init];
newEvent.nameOfEvent = [str objectForKey:@"EventName"];
newEvent.dateOfEvent = [str objectForKey:@"EventDate"];
newEvent.placeOfEvent = [str objectForKey:@"EventPlace"];
[Singleton.EventsList addObject:newEvent];
}
//------------------Save this data stored in NSMutableArray to disk-------------------------
[NSKeyedArchiver archiveRootObject:Singleton toFile:[self save_path]];
因此,再次执行停止:
[aCoder encodeObject:self.EventsList forKey:@"Events"];
但是当我尝试编写单个 NSString 对象时,一切都没有错误。
最佳答案
eventList
不包含 NSStrings
,它包含 Event
对象。
您的 Event
类需要实现 encodeWithCoder:
- 如异常消息所述,Event
类未实现此方法。
此外,您应该对单例使用小写的 s,因为它是一个实例,而不是一个类,您可能不应该使用单例。
关于ios - 将 NSStrings 的 NSMutableArray 保存到磁盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29340789/
我在服务器启动时创建一个缓存(服务器启动每次都需要10分钟)。目前我正在使用内存缓存(Ehcache)。现在我想建立一个机制,以便一旦数据被缓存我应该能够在几秒钟内启动服务器。比如将缓存的持久副本写入
我编写 json 结构的方式使得文件(在进行了一个月的测量后)存储在磁盘上时仍然只有 100 MB 左右。但是现在文件大约是 20mb,但我看到我的脚本需要的内存大约是 200/300 mb。显然,脚
Solaris9 x86下如何挂载和永久挂载windows fat32分区 临时挂载Shell 命令; mout –F pcfs /dev/dsk/c1d0p0:c /mnt/c mount
磁盘ID中的资源组名称大小写不敏感。重现此问题的步骤 - 在 Azure 中创建独立磁盘,检查 ID。对于例如 -“/subscriptions/subscriptionID/resourceGrou
我已将附加数据磁盘的备份还原到新虚拟机。当我发出命令 sudo blkid 时,我发现它与附加到原始虚拟机的数据磁盘具有相同的 UUID,因此我无需更改 fstab 即可在启动时挂载它。然而,它似乎是
在用户态中,执行磁盘 IO 就像链接 C 库一样简单,或者,如果您喜欢冒险,可以直接执行系统调用。我想知道内核本身是如何执行 IO 的。 换句话说,假设我在裸机上以特权模式运行应用程序。我将如何访问通
我已将附加数据磁盘的备份还原到新虚拟机。当我发出命令 sudo blkid 时,我发现它与附加到原始虚拟机的数据磁盘具有相同的 UUID,因此我无需更改 fstab 即可在启动时挂载它。然而,它似乎是
我正在尝试使用 laravel 和 ffmpeg 创建缩略图。但是我收到了这个错误。 磁盘 [视频] 没有配置驱动程序。 我的代码 public function index() { FFMp
我的目标是读/写 usb。 首先必须打开并读取 usb 低级别,如“程序” 我使用 visual c++ 和 winAPI 下面是我的测试代码 char path[64]; sprintf(path,
内核缓冲区缓存何时为空?这似乎不是 LINE Buffering。如果我写 () 一个没有换行符的字符串,它会立即输出到文件。 另外,socket文件的输入输出缓冲区是否也像Disk I/O一样使用内
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a software
我有一个大型调用中心,有 250 个并发调用。队列日志的队列应用程序平面文件。该系统使用 Asterisk 和 Queuemetrics。两个服务都在同一台服务器上运行。规范为 16 核和 64 GB
我在使用安装了 Centos7 的 VMWare VM 时遇到问题。 lsblk 命令给出如下内容 df -h 给出这个 我正在尝试将 root lvm 扩展到分区,但无论我如何尝试都无法做到这一点。
在基于内存的计算模型中,通过考虑数据结构,可以抽象地完成唯一需要进行的运行时计算。 但是,关于高性能磁盘 I/O 算法的文档并不多。因此,我提出了以下一组问题: 1) 我们如何估计磁盘 I/O 操作的
我不是在寻找调用命令行实用程序的代码,它可以解决问题。我实际上很想知道用于创建 RAM 磁盘的 API。 编辑 动机:我有一个第三方库,它需要一个目录名,以便以某种方式处理该目录中的文件。我将这些文件
MySQL 数据库显示磁盘 I/O 利用率持续保持在 100% 左右。数据库服务器有 24 GB 内存。 我们尝试优化查询,但效果不佳。 请检查如下所示的当前配置参数: 参数 当前值 key_buff
这是交易。我们本可以采用完全静态 html 的方式来解决性能问题,但由于该站点将是部分动态的,因此这对我们来说行不通。我们想到的是使用 memcache + eAccelerator 来加速 PHP
对于游戏 Minecraft,运行服务器应用程序时的一般方法是在 RAMDisk 中运行它,因为它使用数百个小文件来生成世界,I/O 速度是主要瓶颈。 在最近的尝试中,我尝试使用 Dokan/ImDi
当我查找文件中的某个位置并写入少量数据(20 字节)时,幕后发生了什么? 我的理解 据我所知,可以从磁盘写入或读取的最小数据单位是一个扇区(传统上是 512 字节,但该标准现在正在改变)。这意味着要写
如何使用golang获取xen服务器的内存、磁盘、网络和cpu信息? 是否有任何可用的软件包? 最佳答案 与其他服务器有什么不同?如果没有 - 有一堆 Go 包可以做到这一点,我正在使用这个 - ht
我是一名优秀的程序员,十分优秀!