iOS App的各种路径获取

let bundlePath =Bundle.main.bundlePath

let homeDir =NSHomeDirectory()

let tmpDir =NSTemporaryDirectory()

print("NSDocumentDirectory")

if let docDir =FileManager.default.urls(for:FileManager.SearchPathDirectory.documentDirectory, in:FileManager.SearchPathDomainMask.userDomainMask).first{

print(docDir)

}

print(NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory,FileManager.SearchPathDomainMask.userDomainMask,true))

print("NSLibraryDirectory")

if let libDir =FileManager.default.urls(for: .libraryDirectory, in: .userDomainMask).first{

print(libDir)

}

print(NSSearchPathForDirectoriesInDomains(.libraryDirectory, .userDomainMask,true).first??"Not Found")

print("NSCachesDirectory")

print(NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true).first??"Not Found")

print("NSTemporaryDirectory")

print(NSTemporaryDirectory())

你可能感兴趣的:(iOS App的各种路径获取)