Showing posts with label resourcePath. Show all posts
Showing posts with label resourcePath. Show all posts

Monday, April 29, 2013

NSBundle resourcePath example ios

resourcePath
Returns the full pathname of the receiving bundle’s subdirectory containing resources.
- (NSString *)resourcePath
Return Value of [NSBundle resourcePath]
The full pathname of the receiving bundle’s subdirectory containing resources.
Example of [NSBundle resourcePath]
NSString *path = [[NSBundle mainBundle] resourcePath];
NSFileManager *fm = [NSFileManager defaultManager];

NSError *error = [[NSError alloc] init];

NSArray *directoryAndFileNames = [fm contentsOfDirectoryAtPath:path error:&error];
Example of [NSBundle resourcePath]
- (void) copyImages
{
    NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    NSString *sourcePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"folderinbundle"];  //folder contain images in your bundle
    NSString *destPath = [documentsDirectory stringByAppendingPathComponent:@"images"];  //images is your folder under document directory

    NSError *error;
    [[NSFileManager defaultManager] copyItemAtPath:sourcePath toPath:destPath error:&error];  //copy every files from sourcePath to destPath
}