I am familiar with the __block operator, which makes a variable "assignable" inside a block. But I see that when using some Objective-C functions that use Blocks as arguments in methods, some variables can be assigned even if they are not declared using this __block operator.
Here are 2 codes, for example:
[UIView animateWithDuration:2 animations:^ { self.animatedView.backgroundColor = [UIColor blueColor]; self.animatedView.center = CGPointMake(100, 100); }];
(animatedView is a simple UIView associated with IBOutlet).
int myInt = 10; NSMutableString* mString = [NSMutableString stringWithString:@"Mutable Hello"]; NSString* imString = @"Imutable Hello"; void (^myBlock)(void) = ^ { [mString appendString:@" Block"];
My question is: How can I assign values ββto the properties of a UIView instance?
I do not access the object and do not change it, like my mString.
I would expect the "center" property to behave like my myInt, since it is directly related to the C structure, and not to the pointer to the object.
I would expect 'backgroundColor' to behave like my imString, since it is a pointer to an object that is assigned by the new object, right?
I could not find a satisfactory explanation in the documentation ... I would appreciate it if anyone could provide it or contact me.
variable-assignment ios objective-c block objective-c-blocks
Ohad regev
source share