Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

xingworld

macrumors newbie
Original poster
Jan 24, 2011
13
0
I store an article in resource as file, I want to load it to a NSString.
How should I do?
Thank you.
 

j-a-x

macrumors 68000
Apr 15, 2005
1,562
284
Houston, Texas
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...
 
Last edited by a moderator:

xingworld

macrumors newbie
Original poster
Jan 24, 2011
13
0
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...

Thank you very for you reply.
In code which gives from you I see the way to continue.
 
Last edited by a moderator:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.