Swift 2.0 Cannot invoke map using argumet type list ([AnyObject], (_) & # 8594; _)

I am trying to fix all my projects after a quick update 2.0. After some work, I narrowed it down to this one mistake:

Cannot invoke map using argumet type list ([AnyObject], (_) → _)

This is all the code:

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

The error appears here:

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

Any ideas? My quick knowledge doesn't go that far ...

+2
source share
1 answer

map is now a member function in the CollectionType protocol.

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

+7
source

Source: https://habr.com/ru/post/1623039/


All Articles