ios - Swift 2.0 无法使用类型为 ([AnyObject],(_) -> _) 的参数列表调用 'map'

标签 ios swift swift2

在 swift 2.0 更新后,我一直在尝试修复我所有的项目。经过一些工作后,我将其缩小到一个错误:

无法使用 ([AnyObject],(_) -> _) 类型的参数列表调用“map”

这是完整的代码:

extension JSON {

//Optional [JSON]
public var array: [JSON]? {
    get {
        if self.type == .Array {
            return map(self.object as! [AnyObject]){ JSON($0) }
        } else {
            return nil
        }
    }
}

//Non-optional [JSON]
public var arrayValue: [JSON] {
    get {
        return self.array ?? []
    }
}

//Optional [AnyObject]
public var arrayObject: [AnyObject]? {
    get {
        switch self.type {
        case .Array:
            return self.object as? [AnyObject]
        default:
            return nil
        }
    }
    set {
        if newValue != nil {
            self.object = NSMutableArray(array: newValue!, copyItems: true)
        } else {
            self.object = NSNull()
        }
    }
}
}

错误出现在这里:

return map(self.object as! [AnyObject]){ JSON($0) }

有什么想法吗?我的知识还不够...

最佳答案

map 现在是 CollectionType 协议(protocol)的成员函数。

尝试 return (self.object as! [AnyObject]).map { JSON($0) }

关于ios - Swift 2.0 无法使用类型为 ([AnyObject],(_) -> _) 的参数列表调用 'map',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32673694/

相关文章:

ios - 具有自动布局的 UITableView 在横向模式下不会填满屏幕。为什么?

ios - 在 iOS 的 swift 中以编程方式设置图像的拉伸(stretch)参数

ios - 查询 Firebase 中的现有节点返回 null

ios - 如何解决 SceneKit double not supported 错误?

ios - 针对 TableView 上没有数据创建警报或标签文本。 swift

ios - (快速)当 AudioStreamPacketDescription 为 nil 时调试 CrashIfClientProvidedBogusAudioBufferList 的方法?

ios - 带搜索栏跳转的导航 Controller

swift - CloudKit共享记录: how to make it editable by the user who received the link

ios - Nearby 几秒钟后在后台进入休眠模式

xcode - 无法转换类型的值,swift 2.0,错误处理