I know that we can easily use the objects declare in our appDelegate class by doing this
myAppDelegate *alpha= (myAppDelegate *)[[UIApplication sharedApplication]delegate];
hence from above we can use the alpha object to fetch the value of other objects in myAppDelegate class.
but suppose if I have a Class A and i have declared a NSString *hello in its .h and synthesize it in .m file.
Now in Class B I create an object of class A i.e
A *classA = [[A alloc]init];
A.hello = [NSString stringWithFormat:@"Kawa banga"];
[classA release];
Now in Class C I create an object of Class A again
A *classA = [[A alloc] init];
NSLog(@"%@",classA.hello);
It gives me null.
How can I get the value of my hello object in different class.
When you declare
helloas a property of classA, it’s an instance variable. That means it’s separate for each instance ofAyou create (withalloc&init).It looks like you might want to share just 1 instance of
A. An easy way of doing this is to add it as a property of yourmyAppDelegateclass. (By the way, class names in Cocoa are usually begin with upper-case letter to distinguish them for variable names)Once you’ve done that, you’ll be able to access it with: