Question

I am a beginner in Ios developement and I'm developping a tabed application but I would like a property accessible from each view so i write this in appDelegate: @property (strong, nonatomic) NSString *test; But now I don't know how to access this string from my firstViewController.m and secondViewController.m

Was it helpful?

Solution

You need to create Object of Appdelegate class like:-

AppDelegate *del = [[UIApplication sharedApplication]delegate];

and used this defined string in any class using del.test. Do not forget to import your Appdelegate class in to particular class that you want to use it's string. And also @synthesize your string in .m appdelegate class as well.

UPDATE:-

If you wish to use Appdelegate Object in particular class then Import App-delegate in to .h file like:-

enter image description here

and .m class in ViewDidLoad

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top