i have an iPhone application in which i added images
directory (Group) in to Resources
(group). i want to access that images which is in imag
First of all Check if there is a file with name name in the main Bundle.
It gives null when there is no file with such a name.
for soultion....
Go to : Target -> "Build Phases" -> "copy bundle Resources" Then add that particular file here.
clean the project and RUN. It works.
and also see...
NSBundle pathForResource inDirectory gives nil
NSString *path = [[NSBundle mainBundle] resourcePath];
NSFileManager *fm = [NSFileManager defaultManager];
NSError *error = [[NSError alloc] init];
NSArray *directoryAndFileNames = [fm contentsOfDirectoryAtPath:path error:&error];
print all value of this directoryAndFileNames and check your filename is exist in that or not....
Adding image by following method solved my problem.
Add Files to "project name"
.Copy items into destination group's folder
and Create Folder References for any added folders
and Add to targets
.Add
.Then with bellow code i can retrieve my image.
For Objective-C version
[[NSBundle mainBundle] pathForResource:@"imageName" ofType:@"png"];
For Swift 4.0 version
Bundle.main.path(forResource: "imageName", ofType: "png")