Hi Everyone,
I've quite a bit of experience coding in Java etc. I'm trying to port a program from Java to Objective C but i'm struggling with one aspect:
I have a main class called 'Body' which creates instances of many other classes. Lots of theses classes inherit from a few parents classes. They all need to reference to each other, and in particular back to the 'Body' class (to which most of them belong)
In Java I passed a refence to the class in the constructor:
which was then stored as a pointer to the main Body class in the new class:
And these pointers were inherited throught my OOP so I could refence this 'Body' class anywhere.
I've tried doing the same thing with Objective C and I can't. I know i've probably got some deep misunderstanding here, but if you do this:
Would this just create two pointers to the same object in ObjC?
I can't even seem to:
#import "Body.h"
In the interface of the other class files as it gives me an error when I compile - although I can import all my other classes.
So how do you pass a pointer of a class to a another class in ObjC?
Many Thanks
Kenneth
I've quite a bit of experience coding in Java etc. I'm trying to port a program from Java to Objective C but i'm struggling with one aspect:
I have a main class called 'Body' which creates instances of many other classes. Lots of theses classes inherit from a few parents classes. They all need to reference to each other, and in particular back to the 'Body' class (to which most of them belong)
In Java I passed a refence to the class in the constructor:
Code:
Dog dog = new Dog(this);
which was then stored as a pointer to the main Body class in the new class:
Code:
private Body body;
public Dog(Body bodyRef) {
body = bodyRef;
//now do things with this refence throughout the class
body.doCoolThings();
}
And these pointers were inherited throught my OOP so I could refence this 'Body' class anywhere.
I've tried doing the same thing with Objective C and I can't. I know i've probably got some deep misunderstanding here, but if you do this:
Code:
Body bodyRef = [[Body alloc] init];
Body body = bodyRef;
Would this just create two pointers to the same object in ObjC?
I can't even seem to:
#import "Body.h"
In the interface of the other class files as it gives me an error when I compile - although I can import all my other classes.
So how do you pass a pointer of a class to a another class in ObjC?
Many Thanks
Kenneth
Last edited: