opitoanal type unwarped 总结

来源:互联网 发布:mac常用的软件 编辑:程序博客网 时间:2024/05/20 08:26

1. 如果报如题错误,说明你在使用一个optional的值,需要加上一个! 已表示unwraped。

2 .但是如果在一个for循环中使用了optional的值,也会同样报错,当然我想的是数组为空时不要循环了,可是必须不为空,真是郁闷。

于是,只有这么处理了


import UIKit@objc(LevelResponse)class LevelResponse: NSObject {    var results:[Level]?}


 //笔记        if levelResponse != nil {            for var item in (levelResponse?.results)!{                print("results:\(item.numberOfDrops)")            }        }

3. 当不知道是否能转换为响应对象时,前面申明的对象一定要使用?,否则默认为!

 let item:UIView? = behavior.collisionBehavior.items.firstas? UIView;


0 0
原创粉丝点击