Swift 2.0无法使用类型为[[AnyObject],(_)-> _)的argumet列表调用'map' [英] Swift 2.0 Cannot invoke 'map' with argumet list of type ([AnyObject],(_) -> _)

查看:120
本文介绍了Swift 2.0无法使用类型为[[AnyObject],(_)-> _)的argumet列表调用'map'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

快速2.0更新后,我一直在尝试修复所有项目.经过一些工作后,我将其范围缩小到单个错误:

I've been trying to fix all my projects after the swift 2.0 update. After some work I narrowed it down to this single error:

无法使用类型为[[AnyObject],(_)-> _)的argumet列表调用'map'

Cannot invoke 'map' with argumet list of type ([AnyObject],(_) -> _)

这是完整的代码:

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) }

有什么想法吗?我的敏捷知识还没有走得那么远...

Any ideas? My swift knowledge doesnt go this far...

推荐答案

map现在是CollectionType协议的成员函数.

map is now a member function on the CollectionType protocol.

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

这篇关于Swift 2.0无法使用类型为[[AnyObject],(_)-> _)的argumet列表调用'map'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆