swift3 – Xcode 8 beta 4:Calendar.Unit vs Calendar.Componen
发布时间:2020-12-14 05:51:22 所属栏目:百科 来源:网络整理
导读:这个Swift 3代码工作直到XCode 8 beta 3: let calendar = Calendar.currentlet anchorComponents = calendar.components([Calendar.Unit.day,Calendar.Unit.month,Calendar.Unit.year,Calendar.Unit.hour],from: self) 在Xcode 8 beta 4 Calendar.Unit似乎
这个Swift 3代码工作直到XCode 8 beta 3:
let calendar = Calendar.current let anchorComponents = calendar.components([Calendar.Unit.day,Calendar.Unit.month,Calendar.Unit.year,Calendar.Unit.hour],from: self) 在Xcode 8 beta 4 Calendar.Unit似乎重命名为Calendar.Component。 现在这个代码 let calendar = Calendar.current let anchorComponents = calendar.components([Calendar.Component.day,Calendar.Component.month,Calendar.Component.year,Calendar.Component.hour],from: self) 产生编译器错误,不能将类型为Calendar.Component的值转换为NSCalendar.Unit 我做错什么或是这个bug?
在Xcode 8 beta 4附带的Swift版本中,组件已重命名为dateComponents。
注意:为了使调用更简单,可以省略Calendar.Component前缀。 let anchorComponents = calendar.dateComponents([.day,.month,.year,.hour],from: self) 你得到的错误消息有点误导,我猜编译器正在努力使用类型推断。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- .net core 控制台程序使用依赖注入(Autofac)
- 异常: IOException parsing XML document from ServletCon
- 正则表达式相关记录
- OOA/OOD/OOP
- swift – requestAccessForMediaType不要求权限
- c# – 我可以使用Newtonsoft.Json进行严格的反序列化吗?
- NSIS ---使用nsDialogs创建自定义页面,并获取输入到控件中
- ruby-on-rails – 带有mongoid,devise,database_cleaner的r
- unity团队如何解决项目资源依赖缺失问题和资源命名规范化
- 在Oracle 12.2多租户架构中只flush 某个pdb的buffer cache