相关疑难解决方法(0)

Xcode 8 beta 4:Calendar.Unit与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)
Run Code Online (Sandbox Code Playgroud)

在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)
Run Code Online (Sandbox Code Playgroud)

产生编译错误 cannot convert value of type Calendar.Component to NSCalendar.Unit

我做错了什么或这是一个错误?

swift3 xcode8 xcode8-beta4

26
推荐指数
2
解决办法
2万
查看次数

Xcode 8和Swift 3 NSCalendar

我在Swift中实现了我的watch项目,现在我因为Xcode 8而迁移到Swift 3.我让Xcode 8将源代码更改为Swift 3.但是,代码中有错误,我无法弄明白.

let unitFlags: Calendar = [.hour, .firstWeekday, .monthSymbols, .year, .minute, .firstWeekday]

var calendar = NSCalendar.current
calendar.timeZone = NSTimeZone(identifier: "UTC")!
let components = (calendar as NSCalendar).components(unitFlags, from: reservationDate)
Run Code Online (Sandbox Code Playgroud)

Xcode在这些行中给出了错误,我无法理解这个问题.

错误:上下文类型"日历"不能与数组文字一起使用

错误:参数标签'(标识符:)'与任何可用的重载都不匹配

错误:无法将"日历"类型的值转换为预期的参数类型"NSCalendar.Unit"

ios swift swift2 swift3

16
推荐指数
1
解决办法
1万
查看次数

标签 统计

swift3 ×2

ios ×1

swift ×1

swift2 ×1

xcode8 ×1

xcode8-beta4 ×1