*beginner iOS programmer, please explain with patience
suppose i have 2 classes - Foo, Bar
in class Bar, i have a pointer to an instance of Foo, which i set during init. (and because i dont know how to properly import Foo and Bar with each other, i end up setting the type to id instead of Foo)
@implementation Bar{
id pointerToInstanceOfFoo;
}
how do i write my dealloc function for Bar? or DO I even override the dealloc function?
right now i have
-(void)dealloc{
pointerToInstanceOfFoo = NULL;
[super dealloc];
}
i still want that pointer to Foo to be around when Bar dies, but am i doing things right? several questions:
- if Foo and Bar imports from each other, how do i do this? or is this bad software design?
- right now i have the pointer "pointerToInstanceOfFoo" set in the @implementation... is this equivalent to declaring a private pointer in class Bar?
- should i instead be using
@property (nonatomic, weak) id pointerToInstanceOfFooinstead? if so, why do i keep getting this error about no weak pointers in ARC? - do i need
delete pointerToInstanceOfFoo;in the dealloc function??
Sorry for the confusion, any explanations/answers would be greatly appreciated!!
P.S. i'm using XCode 4.4 and running on iOS 5.0 with cocos2d v2.1 beta... i think it's using arc