之前无意中看到一个OC中写复合语句的介绍,在这里分享一下
以前写代码我都是这么写的
self.webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
_webView.delegate = self;
_webView.backgroundColor = [UIColor whiteColor];
_webView.scrollView.scrollEnabled = NO;
[self.view addSubview:_webView];
现在写代码可以这么写了,我比较喜欢这种写法
self.webView = ({
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
webView.delegate = self;
webView.backgroundColor = [UIColor whiteColor];
webView.scrollView.scrollEnabled = NO;
[self.view addSubview:webView];
webView;
});