Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 09-10-2010, 03:25 PM   #1 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 9
Code is on a distinguished road
Default Loading a little bit of data into my app.

Hi Guys,

I have a little bit of data that my app needs to function. Not much, so was wondering whats the easiest method of getting this data into my app?
(I'm new to Iphones and objective-c so an easy method would help)
At the moment its stored in a text file but i could change it into an XML file or whatever is needed.

Thanks for your advice.
-Code
Code is offline   Reply With Quote
Old 09-10-2010, 04:06 PM   #2 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by Code View Post
Hi Guys,

I have a little bit of data that my app needs to function. Not much, so was wondering whats the easiest method of getting this data into my app?
(I'm new to Iphones and objective-c so an easy method would help)
At the moment its stored in a text file but i could change it into an XML file or whatever is needed.

Thanks for your advice.
-Code
Do you want the data to be included in the app, or created on the fly?

Many of the container classes in Cocoa include methods to write their contents to a file, and other methods that will create a new instance of the object with the contents of a file. These methods use "plist" format, and you can control whether it uses a binary plist format or an specific XML format.

For data that's included in the app, you would read it from the app bundle. If you look at the docs for NSBundle there are methods that give you a path to the main bundle. You append a filename to the bundle's path and use that as a path to your file. Bear in mind that the contents of the app bundle are read-only.

You could also use NSUserDefaults, and set default values for those defaults. User defaults let you save data that can change. Again, take a look at the XCode docs on NSUserDefaults. Look at the method registerDefaults for creating default values for user defaults.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 09-10-2010, 04:28 PM   #3 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 9
Code is on a distinguished road
Default

I just want to read this data into the app. It will never be changed.

So the simplest way to achieve this is to do something with NSBundle?

I'll look into that now. Thanks for the tip.
Code is offline   Reply With Quote
Old 09-10-2010, 05:03 PM   #4 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 9
Code is on a distinguished road
Default

Quote:
Originally Posted by Code View Post
I just want to read this data into the app. It will never be changed.

So the simplest way to achieve this is to do something with NSBundle?

I'll look into that now. Thanks for the tip.
OK read the docs on NSBundle. it hasn't given me a clear idea on what to do.

I gather that my Resources get packaged in the Bundle. But what I am asking about is some specific guidance on how to get my data into my app. Using Text files, XML etc and then how to parse it from these files. Whats commonly done for this kinda of thing. Any code snippets or tutorials would be greatly appreciated.

Thanks,
-Code
Code is offline   Reply With Quote
Old 09-10-2010, 06:15 PM   #5 (permalink)
Super Moderator
 
Join Date: Oct 2009
Location: San Diego, CA
Posts: 1,586
JasonR is on a distinguished road
Default

In the Developer Documentation, you'll find a "Property List Programming Guide". That was easy enough for my first app, and when you read from a file, the data goes right into one of the built in ObjectiveC collections, like NSArray.
JasonR is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
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
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 330
10 members and 320 guests
bignoggins, carlandrews, flamingliquid, hzwegjxg, ilmman, jenniead38, linkmx, mraalex, stanny
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,116
Posts: 402,889
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 11:52 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0