ios NSKeyedArchiver 释放 = 访问错误

发布于 2024-12-11 10:09:34 字数 469 浏览 0 评论 0原文

我有一个菜鸟问题,我希望你能指出我正确的方向。基本上我有一个实现复制协议的自定义类。但是,当我在执行期间保存类时,我发布了自定义类,并且访问权限很差。我可以在仪器中看到保留计数为-2。我使用以下方法保存自定义类:

-(void)storeDataInFile:(NSString*)dataFileName DataArray:(NSArray*)dataToStore 
{
    //Get the path
    NSString *path = [self pathToDocumentsForDataFile:dataFileName];
    //Archive the file
    [NSKeyedArchiver archiveRootObject:dataToStore toFile:path];
}

我是否使用该方法保存带有字符串的数组,它可以完美地工作。关于我的自定义课程,我应该更深入地研究什么?

问候

I have an noob problem and I would like you yo point me in the right direction. Basicly I have a custom class which implements the copying protocol. However when I save the class during execution the custom class i released and I get a bad access. I can see in instruments that the retain count is -2. I save the custom class with the following method:

-(void)storeDataInFile:(NSString*)dataFileName DataArray:(NSArray*)dataToStore 
{
    //Get the path
    NSString *path = [self pathToDocumentsForDataFile:dataFileName];
    //Archive the file
    [NSKeyedArchiver archiveRootObject:dataToStore toFile:path];
}

Is I use the method sor saving a array with strings it works flawless. What should I look deeper into regarding my custom class?

Regards

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

椒妓 2024-12-18 10:09:34

我解决了这个问题,但是我只在评论中提供了解决方案,该评论显然已被删除。所以我只是想发布答案,表明这是一个菜鸟错误。
从更早的测试实现中,我在类中有以下方法

    - (id)copyWithZone:(NSZone *)zone
{
    return self;
}

//retain is counted up
- (id)retain {
    return self;
}

- (unsigned)retainCount {
    return UINT_MAX;
}

这些方法破坏了我的保留计数:)

I soved this issue, however I only provided the solution in a comment which apprantly has been deleted. So I just wanted to post the answer which indicates it was a noob mistake.
From an eralier test implementation I had the following method in the class

    - (id)copyWithZone:(NSZone *)zone
{
    return self;
}

//retain is counted up
- (id)retain {
    return self;
}

- (unsigned)retainCount {
    return UINT_MAX;
}

These methods ruined my retain count :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文