swift - watchOS 3 getSupportedTimeTravelDirections

标签 swift swift3 xcode8 apple-watch-complication clockkit

我正在尝试将我的 watchOS 2 应用更新到 watchOS 3。不幸的是,我不明白我在 ComplicationController 方面做错了什么。我总是收到以下错误(使用 Xcode 8 b6):

Type 'ComplicationController' does not conform to protocol 'CLKComplicationDataSource' Candidate has non-matching type '(CLKComplication, (CLKComplicationTimeTravelDirections) -> Void) -> ()'

代码:

class ComplicationController: NSObject, CLKComplicationDataSource {

    func getSupportedTimeTravelDirections(for complication: CLKComplication, withHandler handler: (CLKComplicationTimeTravelDirections) -> Void) {
        handler([.forward])
    }
...
}

我也试过:

handler(.forward)

这两种方法在 watchOS 3 上都会给我一个错误,但在 watchOS 2/Swift 2 上工作得很好。 有人知道 Swift 3 中关于此功能的变化吗?

最佳答案

来自 Xcode 8 beta 6 发行说明:

Closure parameters are non-escaping by default, rather than explicitly being annotated with @noescape. Use @escaping to indicate that a closure parameter may escape.

如果您在 Xcode 8 beta 6 中创建了一个新的 ComplicationController.swift 项目,生成的源代码现在如下所示:

func getSupportedTimeTravelDirections(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimeTravelDirections) -> Void) {
    handler([.forward, .backward])
}

此更改适用于具有处理程序参数的每个数据源方法。

关于swift - watchOS 3 getSupportedTimeTravelDirections,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39080834/

相关文章:

swift - Xcode 8.3 不支持 Swift 2.3

ios - 错误 : Multiple inheritance from classes 'UICollectionViewController' and 'UICollectionViewLayout'

ios - 如何在 CoreData iOS 中的实体中的同一索引处添加两个项目

ios - 在 UITextView 或 UILabel 中快速显示 html 数据

swift - 自身,协议(protocol)扩展和非最终类

Swift FileManager - 没有这样的文件

ios - Uber Carthage swift LoginManager(loginType : . AuthorizationCode) 给予 accessToken=nil

arrays - Swift Realm [[String]] 对象

ios - 在部分代码中抑制 "is partial: introduced in iOS"

iOS PushKit 注册在 iOS10 上不起作用