I use the Pinterest iOS SDK to share an item in my iPad app. The following code fragment will always fail with a message sent to deallocated instance in the comment line:
NSString *clientId = [NSMutableString stringWithString:@"1431665"]; NSLog(@"clientId: %@", clientId); Pinterest *pinterest = [[Pinterest alloc] initWithClientId:clientId]; NSLog(@"gone: %@", clientId);
I am using NSMutableString stringWithString to simulate conditions in my application. I really do not use this line in my code.
Even if clientId not displayed in the last line, the application crashes when the block exits. I guess this is because ARC is trying to release a link that has already been released.
It seems that the Pinterest SDK should do something elusive and destroy the line I'm going through. Is there any way around this while they fix their code?
EDIT 1
Simplified test case.
EDIT 2
It looks like the Pinterest SDK is using the clientId argument. Based on the clang of the ARC documentation , the way to point this to clang is to point this out with __attribute((ns_consumed)) .
New question : Is it possible to specify this ARC without changing the method signature for adding an attribute?
EDIT 3
So it works, but it is ugly, how is sin? Is there another way?
NSString *clientId = [NSMutableString stringWithString:@"1431665"]; [clientId performSelector:NSSelectorFromString(@"retain")];
source share