0

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];

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

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).

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

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

Thank you very much!

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

4

1 回答 1

0

@dynamic是一个标志,它只是告诉编译器该方法将在运行时存在并且现在不警告它。你不应该使用@synthesizeCore Data 属性。

你怎么知道你的热点是设置核心数据属性?你分析过代码吗?根据我的经验,更改 Core Data 中的一个属性不会很慢,它会是 1/1000 秒或更快。每次更改该属性时是否都保存到磁盘?你在通话中做其他事情吗?

我会首先分析代码并找出热点的真正位置。使用仪器并确认。

于 2010-09-01T19:35:56.490 回答