ios - 如何检查文件是否存在使用 swift,从 objective c 重写

标签 ios swift

如何将这种 objective-c 语言重写为 swift?

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

问候。

最佳答案

等效的 Swift 3 代码:

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

swift 2

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

关于ios - 如何检查文件是否存在使用 swift,从 objective c 重写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27597686/

相关文章:

ios - 克隆节点和性能、几何结构和性能; iOS场景套件

swift - Firestore : How to set security on object types with users as field names

ios - 在 Swift 中生成一个随机词

string - 在 Swift 中转换 Unicode

ios - 编码的自动布局对于 UITableView 无法正常工作

ios - 以编程方式快速添加全尺寸 View

ios - Swift 中的类型检查和验证

swift - 将字符串转换为字典?

ios - Objective-c,.h 中的方法声明和.m 中的私有(private)属性混淆

ios - CollectionView 在动画过程中切断单元格