4
votes

I write one method in swift 1 like this :

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

when I install Xcode 7.2 (swift 2) this method give me error like this :

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

now I want to know what is that problem?

1
Try return (self.object as! [AnyObject]).map { JSON($0) } - Ramkrishna Sharma
@RamkrishnaSharma are you sure right this? - black tiger

1 Answers

2
votes

Don't use forced cast, and call map on the array, as the function was moved in Swift 2

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