从笔尖加载UIView未使用的Swift 3

Kex*_*Kex 1 ios swift swift3

自从迁移到Swift 3以获取以下代码:

func setup() {

        Bundle.main.loadNibNamed("SomeNib", owner: self, options: nil)?[0] as! UIView
        self.addSubview(customView)
        customView.frame = self.bounds


    }
Run Code Online (Sandbox Code Playgroud)

我现在收到警告:Expression of type 'UIView' is unused.我在这做错了什么?

Joe*_*Joe 7

您从未声明并设置customView,这就是编译器抱怨不使用结果的原因loadNibNamed.

let customView = Bundle.main.loadNibNamed("SomeNib", owner: self, options: nil)?[0] as! UIView