Swift   发布时间:2022-03-31  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了swift3 – Xcode 8 beta 4:Calendar.Unit vs Calendar.Component大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

这个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)
这个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)

你得到的错误消息有点误导,我猜编译器正在努力使用类型推断。

大佬总结

以上是大佬教程为你收集整理的swift3 – Xcode 8 beta 4:Calendar.Unit vs Calendar.Component全部内容,希望文章能够帮你解决swift3 – Xcode 8 beta 4:Calendar.Unit vs Calendar.Component所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。