0
点赞
收藏
分享

微信扫一扫

【Swift】遍历Bundle里的图片资源

夏沐沐 2022-03-11 阅读 41

遍历Bundle里的图片资源

func bundleTest() {
        let mainBundle = Bundle.main.bundlePath
        print(mainBundle)
        let path2 = ""
        let fileManager = FileManager.default
        let files = fileManager.subpaths(atPath: mainBundle)
        print(files ?? [""])
        let array: NSMutableArray = []
        if let fileArray = files {
            for imageName in fileArray {
                if imageName.hasSuffix(".png") || imageName.hasSuffix(".jpg") {
                    let path = mainBundle.appending(imageName)
                    array.add(path)
                }
            }
        }
        print(array)
    }
}
举报

相关推荐

0 条评论