1

i have completely implemented the twitter iOS5 account and assuming user has granted permissionin in the settings page.

I want use the same account in various views on the app but dont want to keep asking the user for granting access.

Is there a way to persistently store this?

carbonr
  • 6,049
  • 5
  • 46
  • 73

1 Answers1

2

Several methods could be used here.

You could use a property on custom singleton class to hold onto and share the object.

This is a good pattern here - Create singleton using GCD's dispatch_once in Objective C

You could use the AppDelegate class and keep it as a property on the class but that pattern wise isn't so good IMHO as it treats the AppDelegate as a junk-yard for things you don't know what to do with and you also end up with ugly casts all over the place.

((MyAppDelegate *)[[UIApplication sharedApplication] delegate]).acaccountobject

Technically the singleton and the AppDelegate are the same principal but as mentioned the AppDelegate is not a junkyard.

Community
  • 1
  • 1
Warren Burton
  • 17,451
  • 3
  • 53
  • 73
  • I couldn't store ACAccount object to singleton class I made. I can store usual objects like NSArray on the singleton class, but somehow, ACAccount can't be stored. You don't have any problems on that? – Umeumeume Jun 26 '12 at 06:02
  • Are you declaring the property on the ACAccount object as strong? – Warren Burton Jun 26 '12 at 06:55
  • Yes, like this on ARC. @property (nonatomic, strong) ACAccount *account; Dont know why. :( – Umeumeume Jun 30 '12 at 00:24