Search code examples
swift3xcode8xcode8-beta4

Cannot convert (NSError)-> Void in Swift 3


Hey guys so I recently updated my Xcode version to Xcode 8 and I have started getting these errors in the new betas that I haven't gotten before.

        CSSearchableIndex.default().indexSearchableItems([searchableItem]) { // Error.

        (error : NSError?) -> Void in

        if error != nil {

            print(error?.localizedDescription)
        }
    }

Here's the error : enter image description here


Solution

  • Rather than NSError, use Error. Or, let the compiler infer this for you.

    CSSearchableIndex.default().indexSearchableItems([searchableItem]) { error in
        if error != nil {
            print(error!.localizedDescription)
        }
    }