user1858725 user1858725 - 1 month ago 13
iOS Question

how to check if file exist use swift, rewrite from objective c

how to rewrite this objective-c language to swift?

NSString *filePath = @"/Applications/MySample.app";
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath])
{
// avoid open add friend
}


regards.

Answer

Equivalent Swift 3 Code:

let filePath = "/Applications/MySample.app"
if (FileManager.default.fileExists(atPath: path)) {
    // avoid open add friend
}

Swift 2

let filePath = "/Applications/MySample.app"
if (NSFileManager.defaultManager().fileExistsAtPath(filePath))
{
    // avoid open add friend
}