NSFileManager fileExistsAtPath:isDirectory和swift

NSFileManager fileExistsAtPath:isDirectory和swift,第1张

概述我试图理解如何使用函数fileExistsAtPath:isDirectory:with Swift但我完全失去了。 这是我的代码示例: var b:CMutablePointer<ObjCBool>?if (fileManager.fileExistsAtPath(fullPath, isDirectory:b! )){ // how can I use the "b" variab 我试图理解如何使用函数fileExistsAtPath:isDirectory:with Swift但我完全失去了。

这是我的代码示例:

var b:CMutablePointer<ObjCBool>?if (fileManager.fileExistsAtPath(fullPath,isDirectory:b! )){    // how can I use the "b" variable?!    fileManager.createDirectoryAtURL(dirURL,withIntermediateDirectorIEs: false,attributes: nil,error: nil)}

我不明白如何访问b MutablePointer的值。如果我想知道它是否设置为YES或NO?

第二个参数的类型是UnsafeMutablePointer< ObjCBool​​&gt ;,这意味着
你必须传递一个ObjCBool​​变量的地址。例:
var isDir : ObjCBool = falseif fileManager.fileExistsAtPath(fullPath,isDirectory:&isDir) {    if isDir {        // file exists and is a directory    } else {        // file exists and is not a directory    }} else {    // file does not exist}

更新Swift 3(Xcode 8.0):

let fileManager = fileManager.defaultvar isDir : ObjCBool = falseif fileManager.fileExists(atPath: fullPath,isDirectory:&isDir) {    if isDir.boolValue {        // file exists and is a directory    } else {        // file exists and is not a directory    }} else {    // file does not exist}
总结

以上是内存溢出为你收集整理的NSFileManager fileExistsAtPath:isDirectory和swift全部内容,希望文章能够帮你解决NSFileManager fileExistsAtPath:isDirectory和swift所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1058012.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存