I have class named Building :
@interface Building : NSObject
@property (nonatomic,retain)NSString* node;
@property (nonatomic,retain)NSString* subnode;
@property (nonatomic,retain)NSString* supernode;
@property (nonatomic,retain)Node *reference;
@end
I have another class named:Node
@property (nonatomic,retain)NSMutableArray* strArray;
@property (nonatomic,retain)NSString * strName;
I declared instance of Building from third class .I have set strName from third class by using the reference of the building:
building.reference.strName=strVal;
But this giving me null value .How can i set this value by using the reference of the Building class.
Make sure you are initialising
referenceinBuilding‘s-initmethod. For example (assumingNodealso inherits directly fromNSObject):In addition you could write a designated initialiser method to pass in an existing Node when initialising, e.g.
-initWithNode: (Node)myNode. Then you would get yourBuilding‘s-initmethod to call[self initWithNode:[[Node alloc] init].Then to initialise a
Buildingobject, you can call[[Building alloc] init](to get a Building with a blank Node) or[[Building alloc] initWithNode:myNodeObject](to get a Building with a Node you already instantiated).Note that if Node doesn’t inherit directly from NSObject (which doesn’t do anything in it’s own
init), you should call the superclassinitroutine as well, so your initialiser would become: