How to convert XML data into a NSMutableArray - iphone

I'm receiving data in XML from a server through a NSData object and I would like to convert this data to a NSMutableArray object.
How do I convert the data from the NSData object (knowing that there should be different objects transferred into the NSMutableArray - UIImages ,CLLocation2D objects, strings,...)

Give you a URL, check it by yourself, it is easy to solve.

Related

Converting all NSData in a large NSDictionary to Hex-NSString in Swift

I have multiple large dynamically created NSDictionaries which contain (among other) multiple NSData objects.
I need to "pretty-print" this dictionary. Using -description I get a quite good result except for the NSData stuff which is not completely printed as it is cropped by the method.
Is there a way (except for iterating over the whole dictionary with a nested for-loop) to convert all the NSData objects to a Hex-String representation?

Problem with savin data!

I have a UitableView and its a checklist. I want to be able to save data when the user leaves the view. Then when the view is opened back up i want there to be the saved data. When i say saved data i mean that the table view is able to add and delete cells also i want to be able to save the checkmarks. Could somebody please provide me with a way or an idea on how to do this?
i know i can save data with:
NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
and then save the data to defaults, but i need know how on saving the table view's cells that are add and or deleted! also i would like to know how to save the checkmarks!
Thank you,
Kurt
Sounds like core data would be good here
http://developer.apple.com/library/ios/#documentation/DataManagement/Devpedia-CoreData/coreDataOverview.html
I would suggest using either Core Data, or NSCoding. NSCoding allows you to encode an object as NSData, and reload a replica of that object from NSData.
For instance, saving and loading an array of strings through NSCoding would be something like this:
NSArray * array = [NSArray arrayWithObjects:#"This", #"Is", #"A", #"Test"];
NSData * encoded = [NSKeyedArchiver archivedDataWithRootObject:array];
// save the encoded data to a file...
// load the encoded data from a file...
NSArray * decodedArray = [NSKeyedUnarchiver unarchiveObjectWithData:encoded];
Of course, you will need to implement some NSCoding stuff yourself if you plan on using classes more complicated than NSDictionary, NSArray, NSString, etc.
Documentation for NSKeyedArchiver can be found here. You can also find documentation for the NSCoding protocol here.

merging two data objects

I have to merge two data objects and later separate them.Can anybody suggest me the way to go about it.It's urgent!!!!!!
please respond fast....
Thanks
Have a look at NSMutableData. Specifically, look at the appendData: and appendBytes:Length methods.
You can 'merge' two NSData objects by appending them to an empty NSMutableData object. You can then probably retrieve the data using getBytes:range: and reconstruct your NSData object with dataWithBytes:Length:.
Have a look at this article for working with mutable binary data (includes sample code).

Separate NSData into smaller NSMutableData objects

I am unsure of how to separate a NSData object into smaller parts so that I can send it over bluetooth. I believe it is a method similar to this:
- (void)getBytes:(void *)buffer range:(NSRange)range
I do not know what to pass in for the buffer. Do I just pass in a NSMutableData object to hold the bytes that I pull out of the original NSData?
Thanks
You can use the -subdataWithRange: method.

Need to convert NSData to NSArray

I am pulling down a plist from a URL using an NSURLConnection, which returns an
NSData object. I would like to convert this to an NSArray. Can anyone help me?
I am refactoring a method that currently does a synchronous request to the URL,
using arrayWithContentsOfURL: to get the NSArray.
Thanks!!
Use +[NSPropertyListSerialization dataWithPropertyList:format:options:error:] to convert the data, then check if the result -isKindOfClass:[NSArray class].
Use NSKeyedArchiver for archiving object to data.
NSKeyedUnarchiver for unarchiving object from data:
NSArray *object = [NSKeyedUnarchiver unarchiveObjectWithFile:self.receivedData];