jjzjj

forResource

全部标签

ios - Bundle.main.path(forResource :ofType:inDirectory:) returns nil

尽量不要笑或哭——我在20年后才重新开始编码......我花了4个多小时查看引用资料并尝试使用代码片段来获取Bundle.main.path打开我的文本文件,这样我就可以读取我的应用程序的数据(我的下一步是适本地解析它)。ifletfilepath=Bundle.main.path(forResource:"newTest",ofType:"txt"){do{letcontents=tryString(contentsOfFile:filepath)print(contents)}catch{print("Contentscouldnotbeloaded.")}}else{print(