objective c - iPhone help with singleton class -


greetings,

i'm looking @ matt gallagher's macro creating singleton classes. http://cocoawithlove.com/2008/11/singletons-appdelegates-and-top-level.html

basically, have app multiple views , want able access "global" data each of these views using singleton class.

i have 3 strings want access in class: nsstring *uname, nsstring *details , nsstring *selecteddetails.

do need make 3 singleton classes static variable in each?

also, how , set string variables uname, details , selecteddetails?

i'm bit mixed singleton stuff (i encountered such things today!) , wondering if point me in right direction.

many in advance,

here code i've done:

#import <foundation/foundation.h>  @interface details : nsobject{  } +(xxx *)sharedxxx; @end   #import "details.h" #import "synthesizesingleton.h"  @implementation details synthesize_singleton_for_class(xxx); @end 

do need make 3 singleton classes static variable in each?

no. create 1 has three.

also, how , set string variables uname, details , selecteddetails?

you reference singleton, following:

mysingleton *singleton = [mysingleton sharedinstance]; 

then use other object:

singleton.uname = @"example"; 

are sure need singleton though? if it's user data, storing nsuserdefaults?


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -