This is my code
TWRequest *twRequest = [[TWRequest alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@", kTwitterURLBase, kTwitterMethodHelpConfiguration]]
parameters:nil
requestMethod:TWRequestMethodGET];
[twRequest setAccount:[self twitterAccount]];
[twRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
// Handling
}];
The method twitterAccount
- (ACAccount *)twitterAccount {
NSString *identifier = [[Session getInstance] selectedAccountIdentifier];
ACAccount *account = nil;
if ([identifier length] > 0) {
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
account = [accountStore accountWithIdentifier:identifier];
}
return account;
}
As debugger says, the account is correctly returned but when I print it in the console I get nothing, a blank space; but the account object has a reference.
Just after the request begins to be performed I get an EXC_BAD_ACCESS error. The stack says that the error occurs when sending a wrong message [ACAccount accountType]
.
It's obvious that is a memory problem, and I new with ARC so I guess that the problem would be there.
Any help?
I don't know why the hell I have to do this but if I declare an instance variable for the ACAccountStore to be retained and change the method this way
- (ACAccount *)twitterAccount {
NSString *identifier = [[Session getInstance] selectedAccountIdentifier];
ACAccount *account = nil;
if ([identifier length] > 0) {
if (accountStore_ == nil) {
accountStore_ = [[ACAccountStore alloc] init];
}
account = [accountStore_ accountWithIdentifier:identifier];
}
return account;
}
all goes perfect. Why? :\