iOS DeveloperiOS 开发

复合语句在 Objective-C 中的使用

2016-08-09  本文已影响66人  iFire

之前无意中看到一个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;
    });
上一篇 下一篇

猜你喜欢

热点阅读