7

I was trying to integrate RESideMenu to my application. I was trying to understand how it works to be able to customize a little bit more. Than, i've encountered this initialisation that i've never seen before. I couldn't seem to find any official docs or any questions on SO which explains it a little bit more. If it does, please 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, Is it a new language feature that allows us to initialise objects a different way. It's kind of like Object Initializer in C#.

It would be any difference, if i had initialized like following

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 kind of initialisation apply to any UIKit class or any Foundation class ?

EDIT If i comment this last line of code in the initialisation which is tableView; It gives me compile error which is Implicit conversion of 'BOOL' (aka 'signed char') to 'UITableView *' is disallowed with ARC, why is this happening ? The last line is kind of return statement or what ?

Thanks.

limon
  • 3,222
  • 5
  • 35
  • 52
  • In response to your edit: I'm assuming that the entire block evaluates to whatever the last line evaluates to. – Shawn Bush May 26 '14 at 16:16

1 Answers1

1

Just FTR, there is no difference if you use the conventional code.

(Much like with json, say, you can now very simply say dict[@"someKey"] directly - but there's no fundamental difference.)

Thanks for pointing this out !!

Fattie
  • 27,874
  • 70
  • 431
  • 719