如何在项目中获取plist文件列表 [英] How to get the plist file lists in project

查看:83
本文介绍了如何在项目中获取plist文件列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些数据文件

AAA.plist
BBB.plist
CCC.plist

我想获取这些plist文件的列表. 如果我事先知道文件名, 我可以得到这样的文件.

I would like to get the list of these plist file. If I know the file name in advance, I can get the file like this.

 let path : String = Bundle.main.path(forResource: "AAA", ofType: "plist")!
 var qplist = NSArray(contentsOfFile: path)

但是,如果我不事先知道文件名,我想获取plist文件列表.

However I want to get the plist file list in case of not knowing the file name in advance.

推荐答案

您可以使用

You can use urls(forResourcesWithExtension:subdirectory:) for that.

if let urls = Bundle.main.urls(forResourcesWithExtension: "plist", subdirectory: nil) {

     print(urls)
}
//Set subdirectory with specific name instead of nil if files inside some directory.

您还可以使用 paths(forResourcesOfType:inDirectory:) 来获取数组路径.

You can also use paths(forResourcesOfType:inDirectory:) to get array of paths.

这篇关于如何在项目中获取plist文件列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆