i want to pass a variable from a viewcontroller to another the way i do is at the first viewcontroller header file i declared a variable
1.h:
NSString *string;
and at the second viewcontroller i have import the 1.h in my 2.m file,the way i call the variable is
2.m:
NSString *string2 = 1.string
however it return an error can somebody teach me how to do,because of i dont have the strong basic at Object Oriented programming ,thanks
Just defining and declaring the two strings is not enough. That makes sure that each class has a variable called string or string2 – but when your program is running, it is actual objects that must refer to specific instances of string1 (or string2).
It’s like designing a house with a letterbox – the letterbox is there on the plan of the house, but nothing happens until a specific letter gets sent to a specific house.
What you need to do is wire up the actual instances of your class, possibily in an init method, like this:
Then in 1.m, you create the second controller, and wire the strings up, like this: