iphone - How do you deal with singleton objects in your app? -
the first approach comes mind put singleton object in appdelegate object property. in way can access anywhere using
#import "myappdelegate.h" // ... [[(myappdelegate *)[uiapplication sharedapplication] delegate] singletonobj] the downside have explicitly cast , import header of delegate tell class you're working singletonobj property of delegate. , think makes code smell little.
the second approach create legit singleton class. this, however, require more work. , think 1 singleton class, more enough.
i'm not programmer appreciate corrections on reasoning, , opinions on subject.
best practice ever put uiapplicationdelegate-related things in appdelegate class. evarr.
decide if need singleton. if do, make legit singleton class. will easier in long run; did notice how long took type monster of line, tried singleton object out of appdelegate? agh.
(also, little bit of idiom: classes start capital letter, , methods start lowercase letter; hence, problem meant [[(myappdelegate *)[uiapplication sharedapplication] delegate] singletonobj].)
Comments
Post a Comment