无法在NSBundle中获取图像路径?

时间:2018-06-27 09:20:02

标签: objective-c xcode xcode-ui-testing nsbundle

我试图在UITesting时获取图像的路径。我已经尝试了多种方法,如下所示,但没有一种起作用?

图像文件的名称为:TestImage.fff

NSBundle* testBundle = [NSBundle bundleForClass: [self class]];
NSString* testImage = [testBundle pathForResource:@"TestImage.fff" ofType:@"fff"];
NSString* testImage2 = [testBundle pathForImageResource:@"TestImage"];
NSURL* testImage3 = [testBundle URLForResource:@"TestImage" withExtension:@"fff"];

有人可以告诉我我要去哪里错吗?

1 个答案:

答案 0 :(得分:1)

在XCode中,在目标列表中选择测试目标。然后选择Build Phases标签,并在Copy Bundle Resources阶段内,添加所需的资源。

Example of project