Swift Error fatal error: unexpectedly found nil while unwrapping an Optional value
来源:互联网 发布:windows正版下载地址 编辑:程序博客网 时间:2024/05/21 19:38
致命的错误: 对一个为空的optional值进行解包.
强制解包(forced unwrapping): 在optional后面加叹号. 比如 "value!"
错误代码:
let testString ="lalala"
let a = testString.toInt();
println("\(a!)")
不能对为空的optional进行解包,否则会报运行时错误.所以在对optional进行解包之前进行判断是否为空.
正确写法:
let testString ="lalala"
let a = testString.toInt();
if (a !=nil) {
println("\(a!)")
}
0 0
- 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
- 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“ 怎么解决
- an internal error occurred while showing an internal error...
- An error occurred while collecting items to be installed session........No repository found containi
- 【Mood-17】 github中在本地进行上传的时候出现ERROR: Repository not found. fatal: The remote end hung up unexpectedly
- Error: Apache shutdown unexpectedly.
- Fatal error: Class 'PEAR_Error' not found in
- Fatal error: Class ‘ZipArchive’ not found
- PHP Fatal error: Class 'DOMDocument' not found
- vmware安装fatal error&msi found
- Fatal server error: no screens found
- Notes on Probability Essentials - 1 - Axioms of Probability
- Android adt-bundle下载链接
- windows远程桌面连接到ubuntu14.04
- Servlet和web服务器关系
- jmx
- Swift Error fatal error: unexpectedly found nil while unwrapping an Optional value
- 2012年5月SAT香港真题解析
- vector自定义排序
- Leetcode 230 Kth Smallest Element in a BST
- quickSort
- 跨平台移动开发实战(二)------IOS开发环境搭建
- AJAX返回出现懒加载问题
- 如何在阿里云中注册域名
- ffmpeg中将每帧视频图像保存为图片的方法