aldominium
aldominium

Reputation: 291

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

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:

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

This is the whole 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 swift knowledge doesnt go this far...

Upvotes: 2

Views: 659

Answers (1)

Daniel T.
Daniel T.

Reputation: 33979

map is now a member function on the CollectionType protocol.

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

Upvotes: 7

Related Questions