Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
how to display the images from the NSMutableArray srinivas.be88 iPhone/iPad Programming 5 Sep 2, 2010 02:10 AM
how to get the "S" for the 3gs in sig brisweeney Site and Forum Feedback 7 Oct 9, 2009 12:46 PM
how to uninstall the limewire from the mac y2knp OS X 5 May 12, 2008 11:18 PM
how to remove the audio from video file? naiviv Digital Video 6 Jun 16, 2007 09:56 AM
how to get the glue from the stickers off a new ipod video donbadman iPod 1 Sep 7, 2006 02:30 PM


All times are GMT -5. The time now is 03:56 AM.

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

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