Bundles and file access

I am adding a number of folders to my project (using the option Add existing file). This causes the contents of the folder to appear in Xcode as a blue folder.

The following works:

NSString *imageName = [NSString stringWithFormat:@"/File-03/images/image-%02d.jpg", imageIndex];

return [UIImage imageNamed:imageName];

However, I want to switch to using imageWithContentsOfFileso that the images are not cached.

The code below returns nilfor the image:

return [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"/File-03/images/image-%02d.jpg", imageIndex]];

I also tried to access imageWithContentsOfFileusing the beam, no go.

What am I missing here?

+3
source share
3 answers

Ok, I figured out one way in the code to get what I need:

  NSString *dir = [NSString stringWithFormat:@"File-03/images", imageIndex];
  NSString *file = [NSString stringWithFormat:@"image-%02d", imageIndex]; 
  NSString *path = [[NSBundle mainBundle] pathForResource:file ofType:@"jpg" inDirectory:dir];

  return = [UIImage imageWithContentsOfFile:path];

The focus in inDirectory was calling bundle.

+4
source

iPhone this.

shorty .

, , Xcode, , . - Finder CTRL- .

+6

imageWithContentsOfFile , , / , FS!

, pathForResource:ofType:inDirectory:, , .

, .

+1
source

Source: https://habr.com/ru/post/1709218/


All Articles