NSBundle.mainBundle().URLForResource("bach1",withExtension:"jpg")上面的代码返回null。为了检查文件是否存在,我使用了下面的代码:letfileManager=NSFileManager.defaultManager()iffileManager.fileExistsAtPath(savepath){println("exist")}以上代码返回目录中存在的文件。所以我不明白为什么第一个代码返回null 最佳答案 你的问题是NSBundle.mainBundle().
NSBundle.mainBundle().URLForResource("bach1",withExtension:"jpg")上面的代码返回null。为了检查文件是否存在,我使用了下面的代码:letfileManager=NSFileManager.defaultManager()iffileManager.fileExistsAtPath(savepath){println("exist")}以上代码返回目录中存在的文件。所以我不明白为什么第一个代码返回null 最佳答案 你的问题是NSBundle.mainBundle().
我正在使用iOS4.2SDK开发一个iOS应用程序,但我希望该应用程序可以在旧设备上运行,例如我的iPhone2G和iOS3.1.3。我不知道这段代码的替代方案是什么:NSURL*modelURL=[[NSBundlemainBundle]URLForResource:@"CoreDataApp"withExtension:@"momd"];它在我的设备上崩溃,因为URLForResource:withExtension:方法是iOS4+。请帮忙。谢谢。 最佳答案 您可以使用pathForResource:ofType:获取资源路径