Swift fatal error: unexpectedly found nil while unwrapping an Optional value?
来源:互联网 发布:mac安装ie浏览器 编辑:程序博客网 时间:2024/05/22 09:26
错误原因:可能是控件和代码中的定义没有关联起来。
解决方法一:点击控件,在Show the connections inspector中的Referencing Outlets中拖动圆点到界面中的控件,选择正确的控件,就建立起关联了。保持对象不被释放,去掉weak关键字.
解决方法二:使用guard关键字进行判断。
1、判断不为空
if sender.titleLabel.text != nil {
print("Contains a value!")
} else {
print("Doesn’t contain a value.")
}
2、可选绑定
if let text = sender.titleLabel.text {
print("Contains a value! It is \(number)!")
} else {
print("Doesn’t contain a number")
}
3、guard语句
guard let text = sender.titleLabel.text else {
return
}
- fatal error: unexpectedly found nil while unwrapping an Optional value
- Swift Error fatal error: unexpectedly found nil while unwrapping an Optional value
- Swift fatal error: unexpectedly found nil while unwrapping an Optional value?
- IOS fatal error: unexpectedly found nil while unwrapping an Optional value的一个原因
- ios开发出现fatal error: unexpectedly found nil while unwrapping an Optional value
- unexpectedly found nil while unwrapping an Optional value的解释 && Swift中Optional
- swift3.0 unexpectedly found nil while unwrapping an Optional value的解释 && Swift中Optional
- Swift Optional Chaining and nil Coalesce
- github中在本地进行上传的时候出现ERROR: Repository not found. fatal: The remote end hung up unexpectedly
- “An error message cannot be displayed because an optional resource assembly containing it cannot be found“ 怎么解决
- 【Mood-17】 github中在本地进行上传的时候出现ERROR: Repository not found. fatal: The remote end hung up unexpectedly
- An error occurred while collecting items to be installed session........No repository found containi
- libc++abi.dylib: terminate_handler unexpectedly threw an exception//NSScanner: nil string argument
- 出现NSScanner: nil string argument libc++abi.dylib: terminate_handler unexpectedly threw an exception
- Swift学习之七:Optional value(可选值)
- Swift学习之七:Optional value(可选值)
- Swift学习之七:Optional value(可选值)
- Swift学习之七:Optional value(可选值)
- char_dev.c 添加中文注释
- C# 如何将数据序列化到本地 数组 对象 等等
- SimpleHTTPServer的多并发版
- 项目整合spring-security4.2.2.RELEASE启动报错启动报错Caused by: java.util.zip.ZipException: zip file is empty
- remove 删除一个集合
- Swift fatal error: unexpectedly found nil while unwrapping an Optional value?
- 正则表达式
- 关于Linux bash 中的变量
- linux平台编译java项目
- Android6.0中oat文件的加载过程
- map.c 添加注释
- HTML5 之图片上传预处理
- java 数组去掉重复数据和排序
- 数电第二章总结——逻辑代数基础