您需要提供以下实现init()
:
class MyClass {
init () {}
}
Swift 文档指出:
“Swift provides a default initializer for any structure or base class that provides
default values for all of its properties and does not provide at least one initializer
itself. The default initializer simply creates a new instance with all of
its properties set to their default values.”
Apple Inc. “The Swift Programming Language.”
但以上显然不是真的;在行动:
1> class MyClass1 {}
2> MyClass1()
/var/folders/.../expr.DO8uJ4.swift:2:1: error: 'MyClass1' is not constructible with '()'
MyClass1()
^
2> class MyClass {
3. init () {}
4. }
5> MyClass()
$R0: __lldb_expr_3.MyClass = {}