Save NSMutableArray with NSUserDefaults - iphone

i'm french so maybe i'll make some mistakes, sorry about that :D
I explain my problem, I have a XMLParser who generates NSString (title, category, url, ...), I would like the stream that is generated is to save the user can read the stream even if it is not connected to the internet.
The flow generated can be found here ==> http://www.recontv.fr/testXml.xml
I try different solutions and each time, I should go about it wrong but its not working. : (
Do you need my code? Did I explain my problem?
Thank you in advance for your help!
PS: I post on differents forum for a answer, if I take it somewhere else, i pick here too.

NSUserDefaults isn't really meant to be used for saving an array from XML to it. Your main solutions are to save the XML to a file and re-parse when the user needs to access the information offline, or you can save the NSArray itself to a file using either its writeToFile: methods, or NSKeyedArchiver/NSKeyedUnarchiver. In each case you must ensure that the objects in your array conform to the NSCoding protocol.

Related

how can I save the whole plist data coming from server (without formatting) to another plist

[NSPropertyListSerialization propertyListFromData:self.responseData
mutabilityOption:NSPropertyListMutableContainersAndLeaves
format:&format
errorDescription:&errorDesc];
When the server is online, it sends the responseData. Now I want to save this data(obtained through the responseData in the code) directly to another plist in my app, so that I can retrieve the data later(when the server is offline) in the same format(without changing) and use it/pass it in the same way as it is being passed when my server is online. I am doing this so that the user of the app does not come to know whether the server is online/offline and still is able to give updates/feedback to the responseData (as he/she would give when the server is online). I don't want to break the responseData and save it, rather directly save it the way it is coming from the server.
Please let me know if more explanation is required.And thanks for all the answers that you would be giving :)
If you don't want to change anything I believe you should just download the plist as a file and not as data.
To save the file on the phone you should use NSFileManager, you can read about it here:NSFileManager reference + File System Programming Guide
You must pay attention to the place you save the plist according to apple "new" rules of data storage, you can read about it here:
Were you should save your files
Good luck

How best to import a lot of text into an iphone app?

I have seemingly a lot of text that i need to get into my iphone app. It's not nearly as much as a book or anything but it would take quite some time to type it all out in xcode, and I'm sure thats not the best way. I read you can import an xml file or maybe a .txt, could someone please point me in the best direction, and maybe a tutorial or something to help me get started?
Thanks!
You can bundle any file you want with your application as a resource. Just include it as part of your project, and then you can load it in your app as an NSString* or NSData*, whichever your prefer/whichever is most appropriate to your data type.
You can also transform the data however your would like, and write some new file that contains the transformed information, and then grab the new file and package that one with the app so that the transformation step no longer needs to be run. For instance, maybe you want to parse your text data and prepopulate a Core Data model with it. You could write the code that does this, grab the .sqlite database file that is generated, and then package the database file in the deployed version of your app so that everyone starts out with an already-populated data model. If that happens to be your use-case here.
What you mean by get text into my iphone app? Do you want to show the text in your application? If yes, why don't you just use the this NSString method:
+ (id)stringWithContentsOfFile:(NSString *)path
encoding:(NSStringEncoding)enc
error:(NSError **)error
If your text needs to be formatted, I would recommend you to use webview to load formatted html files.

Saving profile in Iphone

In my app, I am writing some data, and I want to save it so that I can retrieve it later. How can I save it and where will it be saved?
Please suggest some ideas...
I think you want to store it in a database using Core Data. If you give more specifics I may be able to give a more specific answer.
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreData/cdProgrammingGuide.html
NSUserDefaults would be the obvious suggestion.
Other suggestions would be to write it to a .plist file in the documents directory or use core-data depending on how much you would want to save.

Serializing a plist

I have tried the various techniques described to serialize a plist I need in order to save the favorites of the user.
Some people also say it is better to save that data into the "user defaults" file.
Which is the better technique and how are they serialized. I have this code
[plistArray writeToFile:filepath atomically: YES];
which adds the object to the array, but cant seem to save the plist edits.
Regards
If you want to save preferences, then the appropriate method is to use the NSUserDefaults mechanism as it will save you a hell of a lot of time and hassle.
However, if you're using a PLIST as a means of persisting data that's stored in say, an NSDictionary, then I think it would be appropriate to use the writeToFile approach.
If you want to save preferences of any kind, just store them in the user defaults dictionary. That's the only correct way – and additionally you make sure, that iTunes will back it up, if the user syncs its phone.

Exif and iPhone files

Im using a library for extracting EXIF data from google code.
I assume with iPhone OS 3 that you can use UIImagepicker to do it.
I just want to be able to extract the f-Stop, Shutter Speed and ISO data from the image.
I want to discard the image and just use the information that I store up.
Would I end up extracting the tag data in the viewcontroller.m or h?
This part of coding seems to baffle me a little bit and I cant figure out what to put where.
Can anyone help me out? I still havent figured out XCode all that well.
Whatever executable code you have needs to go in a .m (implementation) file, not a .h (header file). The headers are just for declaring things like classes, protocols, and methods, not for any real processing work.
Are there any tutorials that you know of that explain using exif step by step?
im using the one found here -
http://iphone-land.blogspot.com/2008/06/geo-tagging-images-using-iphone-exif.html
However, for a newbie like me, its not all that thorough because im coming up with errors and i am not sure how to resolve them.
I guess im just shy in all this. need a good place to start
You will likely have trouble getting access to an images metadata if you get it via UIImagePickerController, due to the issues described in this question: UIImagePickerController and extracting EXIF data from existing photos