Reputation: 87
I am in a function of class A(tableview controller) where I have an object of class B(UserDetails class).Something like:
-(void) connectionFinishedLoading:(NSURLConnection*) connection :(UserDetails *) user{
//some code
user=A;
}
I want to use the value of "user" object in a function(different from the Class A function) of class C(table view controller).Something like:
-(void)newfunction :(NSURLConnection*) connection{
//I want to use the value of "user" here.
}
Thanks.
Upvotes: 0
Views: 74
Reputation: 4249
Best possible way to store a value and use it in various classes is to use property of appDelegate class.
create a property in your appDelegate class say NSString *user; synthesize it
Create an instance of AppDelegate in connectionDidFinishLoading like
YourAppDelegate *appDelegate = (YourAppDelegate *)[[UIApplication sharedApplication]delegate];
appDelegate.user = A;
Further in
-(void)newfunction :(NSURLConnection*) connection{
//I want to use the value of "user" here.
YourAppDelegate *appDelegate = (YourAppDelegate *)[[UIApplication sharedApplication]delegate];
NSLog(@"%@",appDelegate.user);
}
Upvotes: 0
Reputation: 10045
Store the object you need to use in different classes in a shared placeholder class like Singleton. Then simply get its shared instance and retrieve the object you need. Google a bit to get a pattern.
Upvotes: 1