views:

477

answers:

1

I have a NSString declared in my AppDelegate. I am trying to read/write that string from my View class but it's giving me error about getter/setter method not found.

Here's how i am accessing it:

MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];

appDelegate.myString = @"test";
+3  A: 

How do you have the myString property defined?

In order to access it as you say, you need at 3 things:

In the interface, have a variable defined and a @property, and in the implementation a @synthetize.

Something like:

// MyAppDelegate.h
@interface MyAppDelegate

NSString *myString;

@end

@property NSString *myString;


// MyAppDelegate.m
@implementation MyAppDelegate

@synthetize myString;

@end
pgb
thanks! i was missing @synthesize and @property
Technically, you don't need a property or a syntehsize - you simply need a setter and a getter, namely the methods -(NSString*) myString and - (void) setMyString: (NSString*) inString. @property simply declares those methods for you, and @synthesize simply writes the code for you, but you can use dot notation to access it without actually using @property or @synthesize.
Peter N Lewis