swift 自动将我的 NSURL 缩写为“...”以覆盖它不适合的字符?
swift auto-abbreviates my NSURL with " ... " over the characters it can't fit?
所以我建立了一个长字符串,其中包含我要写入文件的路径,例如:
/Users/<mylongusername>/Library/Developer/CoreSimulator/Devices/EF7BF515-BFC9-4900-BBF4-E70268EDCD59/data/Containers/Data/Application/CE6698CD-98D4-4DEA-8C01-CE70029D922B/Documents/looks/2052f438-5a75-11e6-914c-06bcb4e621d1.mp4
这是 226 个字符。
当我使用以下行创建 NSURL 时:
locationURL = NSURL(string: filePath)!
它被设置为更短的字符串:
/Users/<mylongusername>/Library/Developer/CoreSimulator/Devices/EF7BF515-BFC9-4900-BBF4-E70268EDCD59/data/Containers/Data ... 21d1.mp4
用空格和所有内容完成,URL 中不能存在,因此 URL 以后不能用于检索文件。为什么会这样,NSURL 不能处理最多 255 个字符吗?我是不是太接近极限了?使用不同的 URL 构造函数会有帮助吗,比如 fileURLWithPath?
对于上述问题,您可以使用 locationURL = NSURL(fileURLWithPath: filePath)
而不是 locationURL = NSURL(string: filePath)
let filePath = "/Users/<mylongusername>/Library/Developer/CoreSimulator/Devices/EF7BF515-BFC9-4900-BBF4-E70268EDCD59/data/Containers/Data/Application/CE6698CD-98D4-4DEA-8C01-CE70029D922B/Documents/looks/2052f438-5a75-11e6-914c-06bcb4e621d1.mp4"
let locationURL = NSURL(fileURLWithPath: filePath)
print("the url = \(locationURL)")
所以我建立了一个长字符串,其中包含我要写入文件的路径,例如:
/Users/<mylongusername>/Library/Developer/CoreSimulator/Devices/EF7BF515-BFC9-4900-BBF4-E70268EDCD59/data/Containers/Data/Application/CE6698CD-98D4-4DEA-8C01-CE70029D922B/Documents/looks/2052f438-5a75-11e6-914c-06bcb4e621d1.mp4
这是 226 个字符。
当我使用以下行创建 NSURL 时:
locationURL = NSURL(string: filePath)!
它被设置为更短的字符串:
/Users/<mylongusername>/Library/Developer/CoreSimulator/Devices/EF7BF515-BFC9-4900-BBF4-E70268EDCD59/data/Containers/Data ... 21d1.mp4
用空格和所有内容完成,URL 中不能存在,因此 URL 以后不能用于检索文件。为什么会这样,NSURL 不能处理最多 255 个字符吗?我是不是太接近极限了?使用不同的 URL 构造函数会有帮助吗,比如 fileURLWithPath?
对于上述问题,您可以使用 locationURL = NSURL(fileURLWithPath: filePath)
locationURL = NSURL(string: filePath)
let filePath = "/Users/<mylongusername>/Library/Developer/CoreSimulator/Devices/EF7BF515-BFC9-4900-BBF4-E70268EDCD59/data/Containers/Data/Application/CE6698CD-98D4-4DEA-8C01-CE70029D922B/Documents/looks/2052f438-5a75-11e6-914c-06bcb4e621d1.mp4"
let locationURL = NSURL(fileURLWithPath: filePath)
print("the url = \(locationURL)")