Skip to content

Instantly share code, notes, and snippets.

@timd
Last active December 14, 2015 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timd/5141930 to your computer and use it in GitHub Desktop.
Save timd/5141930 to your computer and use it in GitHub Desktop.
Assume Xcode project file structure like:
Project/
- project.xcworkspace
- project.xcodeproj
- Project/
- assets/
- data/
- css/
- html/
- content.html
- en.lproj/
- main.m
- etc
- etc
To list the contents of the assets/ directory :
NSString *filesPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"assets"];
NSArray *filesList = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:filesPath error:nil];
NSLog(@"filesList = %@", filesList);
To list contents of assets/data directory:
NSString *filesPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"assets"];
NSArray *filesList = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:filesPath error:nil];
NSLog(@"filesList = %@", filesList);
To load content.html:
NSString *pathToBundle = [[NSBundle mainBundle] resourcePath];
NSURL *baseURL = [NSURL fileURLWithPath:pathToBundle];
NSString *pathToFile = [[NSBundle mainBundle] pathForResource:@"content" ofType:@"html"];
NSString *htmlFileToDisplay = [[NSString alloc] initWithContentsOfFile:pathToFile];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment