fatal error: unexpectedly found nil while unwrapping an Optional value
来源:互联网 发布:微博来自mac客户端 编辑:程序博客网 时间:2024/05/01 16:53
在写swift3.0代码是偶遇此问题。最后终于找到解决方案。
问题如下:
NSClassFromString("CustomClass")时。字符串转成类时,工程中明明存在"CustomClass"。缺报如下错误:
fatal error: unexpectedly found nil while unwrapping an Optional value
解决方法:
点击NSClassFromString 使用方法类 可以看出此函数在 Foundation框架下 NSObjCRuntime.h中。
从 NSObjCRuntime.h中可以看出为OC类,因此swift中引用oc方法需要在CustomClass类 上方添加
@objc(CustomClass)。就能解决此问题。
@objc用法
在 Swift 代码中,使用@objc
修饰后的类型,可以直接供 Objective-C 调用。可以使用@objc
修饰的类型包括:1>未嵌套的类.2>协议3>非泛型枚举(仅限于原始值为整形的类型)。4>类和协议中的属性和方法。5>构造器和析构器。6>下标。
0 0
- fatal error: unexpectedly found nil while unwrapping an Optional value
- Swift Error 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
- Swift 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“ 怎么解决
- 【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
- Permission denied (publickey). fatal: The remote end hung up unexpectedly while pushing back to git
- jpivot : javax.servlet.jsp.JspException: An error occurred while evaluating custom action attribute "test" with value "${query01
- an internal error occurred while showing an internal error...
- Fatal error: Class 'PEAR_Error' not found in
- Fatal error: Class ‘ZipArchive’ not found
- 杭电1213How Many Tables
- ios 数组里面的对象都执行一个方法
- GetLastError简介及返回值列表
- 设计模式-工厂方法模式
- HDU Problem 5326 Work 【并查集】
- fatal error: unexpectedly found nil while unwrapping an Optional value
- 各种行程问题
- Apache POI(3):给Excel文件添加打开密码
- JAVA基础问答(一)
- 【C语言】模拟实现strncpy、strncat、strncmp函数
- getAttribute()与getParameter的区别
- DBUnit 对比数据的4种方式
- fill_parent/match_parent/wrap_content区别
- 菜鸟运维