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.的更多相关文章
- 使用Spire组件抛出异常The type initializer for 'spr857' threw an exception
使用Spire组件抛出异常The type initializer for 'spr857' threw an exception 我使用免费的Spire.Xls组件尝试去转换Excel文档到PDF文 ...
- C#中异常:“The type initializer to throw an exception(类型初始值设定项引发异常)”的简单分析与解决方法
对于C#中异常:“The type initializer to throw an exception(类型初始值设定项引发异常)”的简单分析,目前本人分析两种情况,如下: 情况一: 借鉴麒麟.NET ...
- System.Security.SecurityException The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception
[15/08/19 00:03:10] [DataManager-7292-ERROR] System.Reflection.TargetInvocationException: Exception ...
- System.TypeInitializationException: The type initializer for 'Mono.Unix.Native.Stdlib' threw an exception.
08-31 17:02:03: ### DEBUG ##########################System.TypeInitializationException: The type ini ...
- the type initializer for '' threw an exception
the type initializer for '' threw an exception 问题:程序启动时初始化主窗口类时,弹出该错误.调查:查看类的构造函数是否会有异常抛出.解决:去掉类的构造函 ...
- debian The type initializer for 'System.Drawing.KnownColors' threw an exception
Change the "System.Drawing" reference of "CoreCompat.System.Drawing"if you thro ...
- ASP.Net Core "The type initializer for 'Gdip' threw an exception"
ASP.NET Core项目部署在Linux下可能会出现GDI错误 The type initializer for 'Gdip' threw an exception 解决方案:创建 libdl 的 ...
- The type initializer for System.Data.SqlClient.SqlConnection threw an exception
The type initializer for System.Data.SqlClient.SqlConnection threw an exception net framwork啥原因 xp电脑
- System.TypeInitializationException: The type initializer for 'Oracle.DataAccess.Client.OracleConnection' threw an exception. ---> Oracle.DataAccess.Client.OracleException: 提供程序与此版本的 Oracle 客户机不兼容”
.net应用程序通过Oracle.DataAccess.dll访问64位的Oracle服务器,在连接时出现以下异常:“System.TypeInitializationException: The t ...
随机推荐
- Ansible14:Playbook条件语句
目录 简介 when关键字 1. when基本使用 2. 比较运算符 3. 逻辑运算符 条件判断与tests 判断变量 判断执行结果 判断路径 判断字符串 判断整除 其他tests 条件判断与bloc ...
- Lua table的remove函数
[1]remove函数简介 table.remove(table, pos): 返回table数组中位于pos位置的元素,其后的元素会被前移. pos参数可选, 默认为table长度, 即从最后一个元 ...
- TP5多字段排序
有业务需求如下: select * from table where id IN (3,6,9,1,2,5,8,7) order by field(id,3,6,9,1,2,5,8,7); 这里直入主 ...
- 【题解】选数字 [51nod1354]
[题解]选数字 [51nod1354] 传送门:选数字 \([51nod1354]\) [题目描述] 共 \(T\) 组测试点,每一组给定一个长度为 \(n\) 的序列和一个整数 \(K\),找出有多 ...
- 『摆渡车 斜率优化dp及总结』
摆渡车的题解我已经写过一遍了,在这里,这次主要从斜率优化的角度讲一下摆渡车,并总结一下斜率优化会出现的一些奇奇怪怪的错误. 摆渡车 Description 有 n 名同学要乘坐摆渡车从人大附中前往人民 ...
- GoF的23种设计模式之行为型模式的特点和分类(1)
行为型模式用于描述程序在运行时复杂的流程控制,即描述多个类或对象之间怎样相互协作共同完成单个对象都无法单独完成的任务,它涉及算法与对象间职责的分配. 行为型模式分为类行为模式和对象行为模式,前者采用继 ...
- Java并发编程: CountDownLatch、CyclicBarrier和 Semaphore
java 1.5提供了一些非常有用的辅助类来帮助并发编程,比如CountDownLatch,CyclicBarrier和Semaphore. 1.CountDownLatch –主线程阻塞等待,最后完 ...
- 一个 Java 正则表达式例子
今天在项目里看到用 Python 正则表达式的时候,用到 group,没有仔细看.正好学习 Java 正则表达式,对 group 多留意了一下. 上代码: import java.util.regex ...
- 简洁的 Python Schema
目录 Python Schema使用说明 1. Schema是什么? 2. 安装 1. 给Schema类传入类型(int.str.float等) 2. 给Schema类传入可调用的对象(函数.带__c ...
- ASP.NET MVC 允许跨域请求设置
场景:创建一个图片上传的站点,用于其他站点跨域上传附件和图片之类. 上传插件结合百度的 webuploader.js 经常会碰到,跨域的问题,如下, 处理方式呢,是在web.config 中配置允许跨 ...