开发者

Core Data relation type question

Hia,

assumed I have a one to one or one to may relation. Lets say class Foo has a one to one reference to the managed class Bar.

Foo.h
Bar * bar;
@property (nonatomic, retain) Bar * bar;
Foo.m
@syntesize bar;

I would access Foo this way:

Foo * myFoo= [fetched result what ever];

Using myFoo.bar.whatEverPoperty is working, but saving myFoo.bar in something like Bar * myBar is not.

Any idea why?

Edit:

SomeClass.h
Bar * myBarRef;
@property (nonatomic, retain) Bar * myBarRef;
SomeClass.m
@synthesize myBarRef;

now I create an object of that class:

Som开发者_如何学编程eClass * mySomeClass= [[SomeClass Alloc]init];

and store the reference there: mySomeClass.myBarRef= myFoo.bar; (EXC_BAD_ACCESS)

occasional he highlight this line instead of the above:

@synthesize myBarRef; (EXC_BAD_ACCESS)

Could the problem be lazy loading? If yes, how force bar to be load with foo?


EXC_BAD_ACCESS means that you are accessing uninitialized memory; probably a released object.

If the crash occurs in the line mySomeClass.myBarRef = myFoo.bar; either mySomeClass or myFoo is uninitialized or released.

You should re-read the memory management rules.

If you still cannot find the bug, use the debugger. It'll tell you in which method exactly the bad access happens.

You can (and always should) also switch on zombie support (set the environment variable NSZombieEnabled to YES.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜