IOS various type of object initialization

I tried to integrate RESideMenu into my application. I tried to figure out how this works in order to customize a little more. Than I came across this initialization that I had never seen before. I could not find any white papers or any questions on SO, which explains this a bit more. If so, point me in the right direction.

Here is the code I'm talking about

self.tableView = ({ UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, (self.view.frame.size.height - 54 * 5) / 2.0f, self.view.frame.size.width, 54 * 5) style:UITableViewStylePlain]; tableView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleWidth; tableView.delegate = self; tableView.dataSource = self; tableView.opaque = NO; tableView.backgroundColor = [UIColor clearColor]; tableView.backgroundView = nil; tableView.separatorStyle = UITableViewCellSeparatorStyleNone; tableView.bounces = NO; tableView.scrollsToTop = NO; tableView; }); 

So, this is a new language feature that allows us to initialize objects in a different way. It’s kind of like Object Initializer in C# .

It would make some difference if I initialized as follows

 self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, (self.view.frame.size.height - 54 * 5) / 2.0f, self.view.frame.size.width, 54 * 5) style:UITableViewStylePlain]; [self.tableView setDelegate:self]; [self.tableView setDataSource:self]; [self.tableView setOpaque:NO]; .... ... 

Last question: does this type of initialization apply to any UIKit class or to any Foundation class?

EDIT If I comment on this last line of code in the initialization, which is equal to tableView; This gives me a compilation error that the Implicit conversion of "BOOL" (aka 'signed char') to 'UITableView *' is forbidden by ARC , why is this happening? The last line is a return expression or what?

Thanks.

+7
ios objective-c ios7
source share
1 answer

Just FTR, no matter if you use regular code.

(As with json, let's say now you can just say dict [@ "someKey"] directly, but there is no fundamental difference.)

Thanks for pointing this out!

+1
source share

All Articles