it is called statement expression and is gcc extension to C. It purpose is scoping. as soon as the variable is assigned, it is fully configured.
BTW:
self.backgroundView = (
{
UIView * view = [[UIView alloc] initWithFrame:self.bounds];
view.backgroundColor = [UIColor whiteColor];
view;
});
in this example the property must be strong
to work. but is not ideal for views, as the super view is holding it strong.
You should mark the property weak
and do this:
UIView *backgroundView = (
{
UIView * view = [[UIView alloc] initWithFrame:self.bounds];
view.backgroundColor = [UIColor whiteColor];
view;
});
[self.view addSubview:backgroundView];
self.backgroundView = backgroundView;
alternatively you can use implicitly declared blocks
UIView *backgroundView = ^{
UIView * view = [[UIView alloc] initWithFrame:self.bounds];
view.backgroundColor = [UIColor whiteColor];
return view;
}();
[self.view addSubview:backgroundView];
self.backgroundView = backgroundView;