将代码从 Swift 1.2 转换为 Swift 2.0 以进行错误处理

Convert code from Swift 1.2 to Swift 2.0 for Error Handling

Swift1.2代码:

var error:NSError? = nil

if (fileManager.removeItemAtPath(exportPath as String, error: &error))
{
    //Error - handle if requried
}

当我使用 try and catch 块时,我无法将此代码编译为 Swift 2.0。

Swift 2.0 代码

do {
    check = try fileManager.removeItemAtPath(exportPath as String)
    if(//some condition)
    {
        // whatever                    
    }
}
catch {
    check = nil
}

这是方法,您不再需要 error 参数!

do {
    try fileManager.removeItemAtPath(exportPath as String)
} catch {
    // Error - handle if required
}