0

Here is my AppDelegate.h(And i have synthesized this properties in Appdelegate.m)

{
    NSString *uName;
    NSDictionary *messagesDict;
    NSString *serve1r;
    NSDictionary *firstGet;
}
@property (strong, nonatomic) UIWindow *window;
@property (copy, readwrite) NSString *uName;
@property (copy, readwrite) NSString *serve1r;
@property (retain, nonatomic) NSDictionary *firstGet;

I have tree View controllers, via a textfield i enter some user infos and want to share these objects(username, server IP..) in the other view controllers. I assing new variables in the other classes(SecondVC and ThirdVC) like below:

MyDelegate *sharedDa= (MyDelegate *)([[UIApplication sharedApplication]delegate]);

After this point, i can see the uName in the second class(log it or display on e textfield) but i cant see anything in the third class. What is wrong with my code can anyone help?

il-os
  • 203
  • 3
  • 10
  • For instance, in FirstVC i set the username and server as: sharedData.serve1r=_server.text; sharedData.uName=_username.text; but in second class, i cant get the value of the server(i call them as: [sharedDa uName], [sharedDa serve1r]). By doing this, i can get the value of _username.text but the _server.text comes as nil(i mean, [sharedDa serve1r] is empty) – il-os Mar 01 '12 at 13:49

2 Answers2

1

It depends how you set this properties in your view controllers, because with copy property you will use a particular type of setter/getter. (see here: NSString property: copy or retain? )

I advice you to use (strong, nonatomic), so you will retain always the pointer to the same object. (if, of course - and it should be - the appDelegate instance is always the same)

Community
  • 1
  • 1
0

Probably the other class is not actually importing MyDelegate.h

Oscar Gomez
  • 18,436
  • 13
  • 85
  • 118
  • :) No that is not true. I didn't want to mess people's mind with a lot of code but there isn't any problem with such things – il-os Mar 01 '12 at 13:25
  • And i think it is because of copy/readwrite/retain.. something like that. But i cant be sure-and cant realize exactly – il-os Mar 01 '12 at 13:27