Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jan 27, 2011, 08:25 AM   #1
xingworld
macrumors newbie
 
Join Date: Jan 2011
How to load the content from the file in resource to NSString?

I store an article in resource as file, I want to load it to a NSString.
How should I do?
Thank you.
xingworld is offline   0 Reply With Quote
Old Jan 27, 2011, 09:11 AM   #2
j-a-x
macrumors 65816
 
j-a-x's Avatar
 
Join Date: Apr 2005
Location: 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 dejo; Jan 27, 2011 at 10:00 AM. Reason: Please use [code] tags.
j-a-x is offline   0 Reply With Quote
Old Jan 27, 2011, 09:24 AM   #3
xingworld
Thread Starter
macrumors newbie
 
Join Date: Jan 2011
Quote:
Originally Posted by j-a-x View Post
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 dejo; Jan 27, 2011 at 10:01 AM. Reason: Quoted post edited.
xingworld is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
An Error occurred trying to load this content Maceddy iPhone 0 May 16, 2014 08:39 PM
Finder Not Searching Folders for File Names or File Content HoberMallow Mac mini 1 Sep 30, 2013 11:47 AM
App Store won't load content. darngooddesign iOS 6 8 Jan 15, 2013 10:58 AM
S-L-O-W To Load Local Content soupy Apple TV and Home Theater 2 Oct 4, 2012 09:37 PM
Can't detect NSString content because of Formatting gwelmarten Mac Programming 9 Jun 9, 2012 06:25 AM

Forum Jump

All times are GMT -5. The time now is 09:45 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC