iPhone CoreData属性:对managedObjects的更改太慢 [英] iPhone CoreData properties: changes to managedObjects are too slow

查看:211
本文介绍了iPhone CoreData属性:对managedObjects的更改太慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的iPhone应用程序中有一个CoreData模型,它链接到具有超过50k条记录的SQL数据库。当我生成记录类时,Xcode对属性使用@dynamic指令。我有一个名为ISFAV的属性,NSNumber类型(CoreData不使用BOOL或Integer,它使用对象类型)。缩短,当用户以这种方式点击按钮时,更改ISFAV属性:

I have a CoreData model in my iPhone app, which is linked to a SQL Database with more than 50k records. When I generate the records classes, Xcode uses the @dynamic directive for properties. I have a property named "ISFAV", NSNumber type (CoreData does not use BOOL or Integer, it uses object types). Being short, I change the ISFAV property when the user taps on a button in this way:

 if (![record.ISFAV intValue]) 

record.ISFAV = [NSNumber numberWithInt:1];

record.ISFAV=[NSNumber numberWithInt:1];

else
record.ISFAV = [NSNumber numberWithInt:0];

else record.ISFAV=[NSNumber numberWithInt:0];

非常简单。但是如果我尝试在同一按钮上连续多次点击,iPhone会花费太多时间(按钮保持在保持状态一段时间,逐渐增加)。即使我更改记录,添加\从收藏中顺序移动许多记录(而不是添加\从收藏夹中删除相同的记录),也会发生这种情况。

Quite simple. But if I try to tap many times on the same button sequentially, the iPhone takes too much time (the button remains in the hold state for a time that increase progressively). This happens even if I change record, adding\removing many records from favorites sequentially (instead of adding\deleting the same record from favorites).

原始访问器方法@synthesize,问题似乎解决了。

If I change the original accessor method to @synthesize, the problem seems to be solved.

对CoreData中的访问器方法使用synthesize指令是正确的吗?

Is it correct to use the synthesize directive for accessor methods in CoreData?

非常感谢!

@edit
使用synthesize指令,在保存上下文时,不会对CoreData模型进行任何更改:-\问题仍未解决: \

@edit Using the synthesize directive, no changes are made to the CoreData model when I save the context :-\ The problem is still unsolved :-\

推荐答案

@dynamic 是一个标志,该方法将在运行时存在,并且不会立即警告它。您不应该在Core Data属性中使用 @synthesize

@dynamic is a flag that just tells the compiler that the method will exist at run time and to not warn about it now. You should not be using @synthesize with Core Data properties.

您如何知道您的热点是设置核心数据属性?你有代码吗?在我的经验中,更改Core Data中的一个属性不会很慢,它将是1/1000秒或更快。每次更改该属性时,您是否保存到磁盘?你在呼叫中做其他事情吗?

How do you know your hotspot is with setting the Core Data property? Have you profiled the code? In my experience, changing one attribute in Core Data is not going to be slow, it will be 1/1000th of a second or faster. Are you saving to disk each time you change that one property? Are you doing something else in the call?

我会首先对代码进行配置,找出热点真正在哪里。使用仪器并确认。

I would profile the code first and find out where the hotspot really is. Use Instruments and confirm.

这篇关于iPhone CoreData属性:对managedObjects的更改太慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆