1

in my view controller.m i have a string like this

 NSString *valueToSave = @"someValue";

and would like to safe the text with NSUserDefauls in Appdelegate.m

 [[NSUserDefaults standardUserDefaults]
 setObject:valueToSave forKey:@"preferenceName"];

how can i use the NSString in the other file? This doesn't work:

#import "viewcontroller.m";
Holger Just
  • 52,918
  • 14
  • 115
  • 123
Johannes Knust
  • 891
  • 1
  • 11
  • 18
  • 1
    Same as [this question](http://stackoverflow.com/questions/538996/constants-in-objective-c/539191#539191). – Kurt Revis May 09 '12 at 17:22

1 Answers1

1

In a header file have extern NSString *valueToSave;. Then in a (1 and only 1) .m file have NSString *valueToSave = @"someValue";


A second option would be to use a #define. Simply put #define kValueToSave (@"someValue") in a header file and use it where you need it.

Jeffery Thomas
  • 42,202
  • 8
  • 92
  • 117