Does NSLog correct missing value / failure?

My applications are imported from Facebook using Social.framework and ACAccount . I save the Facebook account identifier to NSUserDefaults so that the application can automatically import new ones on subsequent launches. The first import works fine. The problem is reinitializing ACAccount on subsequent launches.

So, I have get facebookAccount , which looks like this:

 - (ACAccount *)facebookAccount { if(!_facebookAccount) { ACAccountStore *accountStore = [[ACAccountStore alloc] init]; NSString *accountIdentifier = [[NSUserDefaults standardUserDefaults] valueForKey:SWFacebookAccountIdentifierKey]; if(accountIdentifier) _facebookAccount = [accountStore accountWithIdentifier:accountIdentifier]; } return _facebookAccount; } 

This returns some kind of incomplete ACAccount object:

 type:(null) identifier: B6E94A67-AF94-408F-A618-6CD4D78564DC accountDescription: Facebook username: samvermette@gmail.com objectID: x-coredata://589C098E-F829-4284-841B-EE4A0003FF21/Account/p2 enabledDataclasses: {( )} enableAndSyncableDataclasses: {( )} properties: { fullname = "Sam Vermette"; uid = 716308665; } parentAccount: (null) owningBundleID:(null) 

This is logged from a method that ends up using this object. As you can see, the value of type is null , which causes my application to throw the following exception:

NSInvalidArgumentException ', reason:' Invalid account type for this request

Now the strangest thing is that if I add NSLog(_facebookAccount) right before return in my recipient, the type key is not null and my application will not work. I understand that the NSLog fixing this may be a hint of what's wrong with my code, but I can't figure out what exactly. Any ideas?

+4
source share
1 answer

The problem ended up with ARC automatically releasing the account store to which the ACAccount objects ACAccount .

I fixed this by assigning a strong property to my account store

 @property (nonatomic, strong) ACAccountStore *accountStore; 
+4
source

All Articles