美文网首页iOS DeveloperiOS 开发
复合语句在 Objective-C 中的使用

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

作者: iFire | 来源:发表于2016-08-09 15:38 被阅读66次

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

相关文章

网友评论

    本文标题:复合语句在 Objective-C 中的使用

    本文链接:https://www.haomeiwen.com/subject/kgrdsttx.html