There is no type initializer in Swift----One answer is to use static, it is the same as class final.

Posted feng9exe

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了There is no type initializer in Swift----One answer is to use static, it is the same as class final.相关的知识,希望对你有一定的参考价值。

“Unlike stored instance properties, you must always give stored type properties a default value. This is because the type itself does not have an initializer that can assign a value to a stored type property at initialization time.”

Excerpt From: Apple Inc. “The Swift Programming Language.” iBooks


You could use a type property which default value is a closure. So the code in the closure would be executed when the type property (or class variable) is set.

But class stored properties not yet supported (tested in Xcode 8).

One answer is to use static, it is the same as class final.

Good link for that is

Setting a Default Property Value with a Closure or Function

Excerpt From: Apple Inc. “The Swift Programming Language.” iBooks


Code example:

Prints

start

setting default property value with a closure

So it is lazy evaluated.

 

https://stackoverflow.com/questions/24137212/initialize-class-method-for-classes-in-swift

以上是关于There is no type initializer in Swift----One answer is to use static, it is the same as class final.的主要内容,如果未能解决你的问题,请参考以下文章

There is No Alternative CSU - 2097 最小生成树

There is no known eureka server; cluster server list is empty

Struts2注解错误之There is no Action mapped for namespace /

mybatis There is no getter for property named 'xxxx

YES, There is No such thing as a free lunch

SassError: There is no module with the namespace “math“