0

i use this code for assigning value to varible in block i am using ios7 xcode5 its not working for me.

_Block NSString *temp=Nil;    
[UIView animateWithDuration:0.7f delay:0.03f usingSpringWithDamping:30.0f initialSpringVelocity:30.0f options:UIViewAnimationOptionCurveLinear animations:^{
        [vwBottomMain setFrame:CGRectMake(0.0f, vwBottomMain.frame.origin.y-39, vwBottomMain.frame.size.width,vwBottomMain.frame.size.height)];
    } completion:^(BOOL finished) {
       temp=@"test";
    }];

1 Answer 1

1

Although you don't show the rest of this method, the most likely problem is that your completion handler is asynchronous but you're expecting results immediately.

Try running the following code to see what order things are happening in. It should demonstrate that the assignment happens after the test.

__block NSString *temp = nil;
[UIView animateWithDuration:0.7f delay:0.03f usingSpringWithDamping:30.0f initialSpringVelocity:30.0f options:UIViewAnimationOptionCurveLinear animations:^{
    NSLog(@"Animation section");
} completion:^(BOOL finished) {
    NSLog(@"Completion handler");
    temp = @"test";
}];
NSLog(@"String test %@", temp);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.