表达式类型 'Set<NSObject>' 在没有更多上下文的情况下不明确

Expression Type 'Set<NSObject>' is ambiguous without more Context

我最近切换到 Swift 3 并且我得到了以下行的错误,我没有进入 swift 2. layerClient 调用引用了 layerkit api ,但错误似乎更多地与打字有关,而不是 api。错误本身是 "Expression Type 'Set' is ambiguous without more ".

layerClient.autodownloadMIMETypes = Set<NSObject>(arrayLiteral: "image/png")

我假设您正在使用 this framework

创建 Set 时不需要 <NSObject>。它可以通过传递给 init 方法的参数确定它包含的类型。此外,autodownloadMIMETypes 输入 swift 将是 Set<String>,与 Set<NSObject> 不匹配。这应该有效。

layerClient.autodownloadMIMETypes = Set(arrayLiteral: "image/png")

此外,由于 Set 符合 ExpressibleByArrayLiteral 协议,您应该能够像创建数组一样创建它。

layerClient.autodownloadMIMETypes = ["image/png"]