3

Xcode 12 比 Xcode 11 有很多改进, 我遇到的一个具体案例

 3 years ago
source link: https://codechina.org/2020/07/xcode-12-xcode-11-improvement/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Xcode 12 比 Xcode 11 有很多改进, 我遇到的一个具体案例 – Tinyfool的个人网站

最近同时使用 Xcode 11 和 Xcode beta (也就是12),发现,后者性能提升超级明显,而编译器的理解能力也提升很多。

比如,我的一个SwiftUI代码里面,有一个稍微复杂一点的判断逻辑,有三个 if/else 分支,如下:

Group {
    if(index>0 && item.rating>4.0) {
        PoiLargeImageCell(item:item)
    }else if(index==0){
        InvisibleCell(largeHeadView:self.$largeHeadView)
        PoiCell(item: item)
    }else {
        PoiCell(item: item)
    }
}

这个代码在 Xcode 12 可以正常编译,没有任何问题。但是,在 Xcode 11 下就会直接报错,而且是那种完全文不对题的错误信息。错误信息不是在 Swift 5 发布后有改善了么?但是在这个问题下仍旧文不对题,所以,我只能把这个稍微复杂一点的 if/else 语句改为两个 Group 嵌套的做法,如下,这样在 Xcode 11 就可以正常编译了。

Group {
    if(index==0){
        ZStack{
            InvisibleCell(largeHeadView:self.$largeHeadView)
            PoiCell(item: item)
        }
    }else {
        Group {
            if(index>0 && item.rating>4.0){
                PoiLargeImageCell(item:item)
            }else {
                PoiCell(item: item)
            }
        }
    }
}

为了迁就编译器,代码变啰嗦多了。不过暂时需要这么做,期待 Xcode 12 早日正式发布。这么多年以来,第一次感觉苹果的 Beta 版本这么靠谱,感觉苹果今年果然有点进步。

提交上出现的错误信息

今天我用 Xcode 11 提交一个 app ,遇到了一个以前没见过的错误信息,“Profile doesn’t include the com.apple.application-identifier entitlement.”。查了下,原来跟 MacOS Big Sur 有关系,跟 Xcode 11 和 Xcode 12 beta 也有关系。解决方法很搞笑,那就是用 Xcode 11来编译打包,用 Xcode 12 beta 来 upload app。详情可以参考苹果开发者论坛的相关帖子


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK