这是我的代码示例:
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> ;,这意味着你必须传递一个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所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)