尝试了:
var headerImage:UIImage = UIImage(named: "")! |
编译通过了,但是运行时出错:
fatal error: unexpectedly found nil while unwrapping an Optional value
发现有个:
UIImage(imageLiteral: String>) |
要去搞清楚什么含义。
搜:
swift UIImage imageLiteral
参考:
Added UIImage.init(imageLiteral: String) extension UIImage : _ImageLiteralConvertible { required convenience init(imageLiteral name: String) } extension UIImage { func stretchableImageWithLeftCapWidth(_ leftCapWidth: Int, topCapHeight topCapHeight: Int) -> UIImage var leftCapWidth: Int { get } var topCapHeight: Int { get } } extension UIImage : _ImageLiteralConvertible { required convenience init(imageLiteral name: String) } |
iOS知识小集 第六期(2015.10.20) – 南峰子的技术博客
UIImage的带参数imageLiteral的,最新的官网的文档中也没有解释:
+ imageWithContentsOfFile: – UIImage Class Reference
How to declare an empty UIImage variable in swift – Quora
也是这么写的:“ var imgg:UIImage = UIImage(named: "")!”
ios – UIImage on swift can’t check for nil – Stack Overflow
var headerImage:UIImage? |