How to load the content from the file in resource to NSString?

Discussion in 'iOS Programming' started by xingworld, Jan 27, 2011.

  1. macrumors newbie

    Joined:
    Jan 24, 2011
    #1
    I store an article in resource as file, I want to load it to a NSString.
    How should I do?
    Thank you.
     
  2. j-a-x, Jan 27, 2011
    Last edited by a moderator: Jan 27, 2011

    macrumors 65816

    j-a-x

    Joined:
    Apr 15, 2005
    Location:
    Houston, Texas
    #2
    This is from a Mac App I wrote but it should be similar.

    This is for a resource in the preferences folder on my mac, so you'd have to change the path to be your resource instead, but this should give you a start. Also the file I am loading is a Plist and all of the key object combinations are loaded into a dictionary.

    Code:
    NSString *path;
    path = @"~/Library/Preferences/file.plist";
    NSString *absolutePath = [path stringByExpandingTildeInPath];
    NSDictionary *contentDictionary = [[NSDictionary alloc] initWithContentsOfFile:absolutePath];
    
    In your case, the path would be to a local resource and I guess you wouldn't have to expand the tilde for an iOS app, and you'd have to convert the dictionary to a string (which is easy). In your case maybe the plist could contain a key for the title of the article, and a key for the body of the article, etc.

    Sorry this isn't exactly the same but I thought it might help...
     
  3. xingworld, Jan 27, 2011
    Last edited by a moderator: Jan 27, 2011

    thread starter macrumors newbie

    Joined:
    Jan 24, 2011
    #3
    Thank you very for you reply.
    In code which gives from you I see the way to continue.
     

Share This Page