且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

当需要自引用时,如何在Swift中初始化CBCentralManager

更新时间:2023-02-03 08:03:04

在初始化每个没有默认值且不是默认值的非lazy属性之前,无法在init方法中使用self可选(默认值为nil).

There is no way to use self in an init method prior to initializing every non-lazy property that has no default value and is not optional (which have a default value of nil).

如果您总是在init中初始化centralManager,并且没有可能使其成为nil的代码,那么我想说CBCentralManager!声明是一个不错的选择.这是隐式展开的可选类型的主要目的之一.

If you always initialize centralManager in init, and you have no code that will potentially make it nil, I would say that the CBCentralManager! declaration is a good choice. That is one of the main purposes of the implicitly unwrapped optional type.