【发布时间】:2020-04-01 23:53:10
【问题描述】:
func gettinSongName(){
let folderUrl = URL(fileURLWithPath: Bundle.main.resourcePath!)
do {
let songPath = try FileManager.default.contentsOfDirectory(at: folderUrl, includingPropertiesForKeys: nil, options: .skipsHiddenFiles)
for song in songPath{
let mySong = song.absoluteString
if mySong.contains("mp3") {
print(mySong)
}
}
} catch {
}
}
我写这段代码时没有得到任何结果
但是当我输入.contains("a") 时我会得到结果
func gettinSongName(){
let folderUrl = URL(fileURLWithPath: Bundle.main.resourcePath!)
do {
let songPath = try FileManager.default.contentsOfDirectory(at: folderUrl, includingPropertiesForKeys: nil, options: .skipsHiddenFiles)
for song in songPath{
let mySong = song.absoluteString
if mySong.contains("a") {
print(mySong)
}
}
} catch {
}
}
结果:
file:///Users/xzips/Library/Developer/CoreSimulator/Devices/637C5530-3899-4D61-8AFB-8B0EC6A52D09/data/Containers/Bundle/Application/5EFA5FA9-2928-409E-B80C-A0A7F0A8E423/Bebek% 20Ninnileri.app/_CodeSignature/ file:///Users/xzips/Library/Developer/CoreSimulator/Devices/637C5530-3899-4D61-8AFB-8B0EC6A52D09/data/Containers/Bundle/Application/5EFA5FA9-2928-409E-B80C-A0A7F0A8E423/Bebek%20Nannileri.app /歌曲/ file:///Users/xzips/Library/Developer/CoreSimulator/Devices/637C5530-3899-4D61-8AFB-8B0EC6A52D09/data/Containers/Bundle/Application/5EFA5FA9-2928-409E-B80C-A0A7F0A8E423/Bebek%20Nannileri.app /Base.lproj/ file:///Users/xzips/Library/Developer/CoreSimulator/Devices/637C5530-3899-4D61-8AFB-8B0EC6A52D09/data/Containers/Bundle/Application/5EFA5FA9-2928-409E-B80C-A0A7F0A8E423/Bebek%20Nannileri.app /资产.汽车 file:///Users/xzips/Library/Developer/CoreSimulator/Devices/637C5530-3899-4D61-8AFB-8B0EC6A52D09/data/Containers/Bundle/Application/5EFA5FA9-2928-409E-B80C-A0A7F0A8E423/Bebek%20Nannileri.app /Info.plist file:///Users/xzips/Library/Developer/CoreSimulator/Devices/637C5530-3899-4D61-8AFB-8B0EC6A52D09/data/Containers/Bundle/Application/5EFA5FA9-2928-409E-B80C-A0A7F0A8E423/Bebek%20Nannileri.app /Bebek%20尼尼莱里 file:///Users/xzips/Library/Developer/CoreSimulator/Devices/637C5530-3899-4D61-8AFB-8B0EC6A52D09/data/Containers/Bundle/Application/5EFA5FA9-2928-409E-B80C-A0A7F0A8E423/Bebek%20Nannileri.app /PkgInfo
【问题讨论】:
-
结果中没有
mp3。尝试打印出所有文件,看看是否有mp3。 -
仔细检查
folderUrl是否有效以及songPath是否有任何内容。 -
type contains('"m") 你会看到你是否得到了一些东西,但里面没有mp3
标签: swift contains resultset swift5.1