I'm trying to understand how to use the function fileExistsAtPath:isDirectory:
with Swift but I get completely lost.
This is my code example:
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)
}
I can't understand how can I access the value for the b
MutablePointer. What If I want to know if it set to YES
or NO
?
The second parameter has the type
UnsafeMutablePointer<ObjCBool>
, which means that you have to pass the address of anObjCBool
variable. Example:Update for Swift 3 and Swift 4:
Tried to improve the other answer to make it easier to use.