Okay this is the first place in my app I’m using a block for anything so is there some setup or Xcode setting I need to check? This seems to me a simple use of blocks, not doing anything fancy but it crashes out on: tweetViewController.completionHandler = ^(TWTweetComposeViewControllerResult result) in the iOS 6 simulator.
- (void) showTweetComposer
{
TWTweetComposeViewController *tweetViewController = [[TWTweetComposeViewController alloc] init];
[self presentViewController:tweetViewController animated:YES completion:nil];
tweetViewController.completionHandler = ^(TWTweetComposeViewControllerResult result)
{
[self dismissModalViewControllerAnimated:YES];
};
[tweetViewController release];
}
thread #1: tid = 0x1c03, 0x02e3d09f libobjc.A.dylib`objc_msgSend + 19, stop reason = EXC_BAD_ACCESS (code=2, address=0x0)
frame #0: 0x02e3d09f libobjc.A.dylib`objc_msgSend + 19
frame #1: 0x02e28cc9 libobjc.A.dylib`objc_setProperty_nonatomic_copy + 49
frame #2: 0x051c38b2 Social`-[SLTwitterComposeViewController setCompletionHandler:] + 47
frame #3: 0x001e2e06 MyApp`-[SocialViewController showTweetComposer] + 246 at SocialViewController.m:137
frame #4: 0x001e2ff7 MyApp`-[SocialViewController tweetToFriendsRowTouched] + 247 at SocialViewController.m:150
frame #5: 0x02e3f663 libobjc.A.dylib`-[NSObject performSelector:] + 62
frame #6: 0x0018b4f1 MyApp`-[GroupedTableViewController tableView:didSelectRowAtIndexPath:] + 401 at GroupedTableViewController.m:143
This happens whether I’m logged into twitter or not.
EDIT: I added a simple block based code snippet to the beginning for my showTweetComposer method to test that any kind of blocks are working in my code:
[UIView animateWithDuration:0.2 animations:^{
self.view.alpha = 0.0;
} completion:^(BOOL finished){
[self.view removeFromSuperview];
}];
Now it is crashing on this new block. So, it would seem there’s something in my project that needs to be set to support using blocks but I’m not sure what that would be. My iOS deployment target is set to iOS 4.3.
Okay, solved. This gist is, don’t weak-link against libSystem.dylib using -weak_library
Found the answer here