其他分享
首页 > 其他分享> > 【Swift】遍历Bundle里的图片资源

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

作者:互联网

遍历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)
    }
}

标签:遍历,Bundle,imageName,let,mainBundle,print,array,Swift
来源: https://blog.csdn.net/weixin_45279502/article/details/123234567