Skip to content

Instantly share code, notes, and snippets.

@staycreativedesign
Created July 21, 2017 20:07
Show Gist options
  • Save staycreativedesign/337fadea25362d0be8e5d964a20e3189 to your computer and use it in GitHub Desktop.
Save staycreativedesign/337fadea25362d0be8e5d964a20e3189 to your computer and use it in GitHub Desktop.
func checkForDecksDirectory() {
let fm = FileManager.default
let dirPath = fm.urls(for: .documentDirectory, in: .userDomainMask)
let docsURL = dirPath[0]
let docPath = docsURL.appendingPathComponent("decks").absoluteString
let deckPath = docsURL.appendingPathComponent("decks")
var isDir : ObjCBool = false
if fm.fileExists(atPath: docPath, isDirectory:&isDir) {
if isDir.boolValue {
// file exists and is a directory
print("file exists is a dir")
} else {
// file exists and is not a directory
print("file exists is not a dir")
}
} else {
do {
try fm.createDirectory(at: deckPath, withIntermediateDirectories: true, attributes: nil)
}
catch {
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment