Global variables is a good sign of a bad design. I am guessing, based on your previous comment, that what you want to do is sending a string from one view controller, to another. There are two proper ways to do this:
Let the sending class also define a protocol for receiving the result string. This is how for example a UIImagePickerController
and all other Cocoa controllers for user input does it. An example:
@protocol MyTextInputDelegate;
@interface MyTextInput : UIViewController {
id<MyTextInputDelegate> textInputDelegate;
}
@property(nonatomic,assign) id<MyTextInputDelegate> textInputDelegate;
// More interfaces here...
@end
@protocol MyTextInputDelegate
-(void)textInput:(MyTextInput*)textInput didInputText:(NSString*)text;
@end
Then let the class that needs the result conform to the MyTextInputDelegate
protocol, and set it as the delegate. This way you avoid global variables, and there is no question of who owns the text object.
The other method would be to send the result as a NSNotification
. This is slightly harder setup, and should only be used if you want a loose connection between the sender and the receiver.