SearchDirectories 与 URLsDirectory - iOS

SearchDirectories vs URLsDirectory - iOS

为什么当我使用 NSFileManager 的 URLsForDirectory api 时,路径与 NSSearchPathForDirectoriesinDomains 的路径不同?

let paths = NSFileManager.defaultManager().URLsForDirectory(.CachesDirectory, inDomains: .UserDomainMask)
let cachePath = paths[0] as! NSURL
print cachePath

这给了我一个输出

file:///Users/Labs1/Library/Developer/CoreSimulator/Devices/E2BB953D-7CAB-4FB7-BAFA-84C9D962A28E/data/Containers/Data/Application/BB57895F-9D13-46E1-AC48-B76E4FDA2DDF/Library/Caches/

使用 NSSearchPathForDirectoriesInDomains

print(NSSearchPathForDirectoriesInDomains(.CachesDirectory, .UserDomainMask, true)[0] as? String)

我得到一个输出

/Users/Labs1/Library/Developer/CoreSimulator/Devices/E2BB953D-7CAB-4FB7-BAFA-84C9D962A28E/data/Containers/Data/Application/BB57895F-9D13-46E1-AC48-B76E4FDA2DDF/Library/Caches

有没有办法删除 URLsForDirectory 中的 file:///

if let cachesDirectoryPath = NSFileManager().URLForDirectory(.CachesDirectory, inDomain: .UserDomainMask, appropriateForURL: nil, create: true, error: nil)?.path {
    println(cachesDirectoryPath)   // "/var/folders/s_/fxl041zd64l0y6_rjddfbpcc0000gn/T/com.apple.dt.Xcode.pg/containers/com.apple.dt.playground.stub.iOS_Simulator.UIColor-PlayGround-514A4119-E045-4B83-A740-B0C1BBCECBD7/Library/Caches"
}