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.
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 !!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With