iOS: collect and parse local project files

Do you have a bunch of HTML files that are local to your iOS project? Would you like to run through them and parse out keywords for your own search method? While I won’t go into the indexing and searching (separate topic), digging through your own stuff dynamically is actually pretty easy when you put a few pieces together. I give you a method which finds all the HTML pages in your application.

- (void)indexAllHTML
    NSArray *pages = [[NSBundle mainBundle] pathsForResourcesOfType:@".html" inDirectory:nil];
    for(int i=0; i<[pages count]; i++){
        NSString *path = [pages objectAtIndex:i];
        NSString *pageData = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
        NSArray *foo = [path componentsSeparatedByString:@"/"];
        NSString *shortPath = [foo lastObject];
        //Perform your indexing magic here
Related Posts Plugin for WordPress, Blogger...

Leave a Reply

Your email address will not be published. Required fields are marked *

+ 5 = seven

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>