Nil is incompatible with return type ...
来源:互联网 发布:网络基础知识教程视频 编辑:程序博客网 时间:2024/06/05 23:35
swift中不能直接将 nil 做为 返回值或者参数
返回值或者参数的类型必须是对应的
当想让 nil 做为参数的时候 需要用到 optional types 可选类型
在不使用optional的情况下
声明函数:
func dosome(name:String) {
print(name)
}
调用函数:
self.dosome(nil) 此时会有 Nil is incompatible with return type ... 的错误提示
但是 参数类型的头面添加?号 就能使用nil了 但是下面的方法仍然是不对的
func dosome(name:String?) {
print(name)
}
self.dosome(nil)
最终写法 使用可选类型的时候 需要拆包 之所以要拆包使用,是因为Optional类型其实是一个枚举
func dosome(name:String?) {
if let aname = name {
print(aname)
}else {
print("没有值")
}
}
self.dosome(nil)
0 0
- Nil is incompatible with return type ...
- 错误信息:The return type is incompatible with ActionSupport.getLocale()
- The return type is incompatible with JspSourceDependent.getDependants():JasperException问题分析与解决方法
- Nil is not compatible with expected argument type '[String : AnyObject]'
- Specified field type [interface javax.persistence.EntityManager] is incompatible with resource type [javax.persistence.EntityMan
- 错误argument of type "char *" is incompatible with parameter of type "LPCWSTR"的解决方法
- 错误argument of type "char *" is incompatible with parameter of type "LPCWSTR"的解决方法
- 错误argument of type "char *" is incompatible with parameter of type "LPCWSTR"的解决方法
- Property type 'id<xxxxTabBarDelegate>' is incompatible with type 'id<UITabBarDelegate>' inherited fr
- 错误argument of type "char *" is incompatible with parameter of type "LPCWSTR"的解决方法
- 错误argument of type "char *" is incompatible with parameter of type "LPCWSTR"的解决方法
- 错误:argument of type "char *" is incompatible with parameter of type "LPCWSTR"
- this is incompatible with DISTINCT
- return type UIViewController? add ? so that can return nil
- is incompatible with i386:x86-64 output
- plugin scala is incompatible with current installation
- this is incompatible with sql_mode=only_full_group_by
- this is incompatible with sql_mode=only_full_group_by
- iOS 3D Touch开发 很良心的版本原创!
- Sqlite3开发
- Android 短信验证码自动填写
- Strongswan5.3.3与win7 l2tpoverIPsecVPN对接的配置与打印
- cmd 相关命令
- Nil is incompatible with return type ...
- TextSwitcher实现文本自动垂直滚动
- JS判断输入字符串长度(汉字算两个字符,字母数字算一个)
- 杭电ACM2033
- 解决android studio 无法更新插件的问题(某些)
- php入门基础
- OpenCV截取图像的任意形状区域,规则的图形(圆、椭圆、矩形),不规则鼠标自己选择
- window安装vagrant+virtualbox
- IFRAME的内容增高或缩减时设置其IFRAME的高度的处理方案