iPhone Data Structure and accessor code advice - iphone

I need a code based solution for storing the following data without using CoreData. Preferably I would be able to access each row based on it's index, and each data field using a key/pair perhaps?
The PHP equivalent of what I'm looking for would be something like;
echo $arr[0]['Image'];
Apple.png

The simplest way is to use an NSMutableArray of NSMutableDictionary objects.
NSMutableArray has a -writeToURL: method you can use to save it to disk.

You can use either plist, sqlite or Any other data storage take look at this link. and if you are using like Sqlite than select query will get the Apple.png.

Related

Trouble working with nested JSON objects on Objective-C

On my iPhone app, I'm getting this response from the server:
I need to save this data to disk, so it can be accessed while offline, and am doing it with NSKeyedArchiver.
I need to save each id_preguntawith its correspondent values, including the array respuestas, which has some objects, too.
How can I break this server response into more manageable data, so I can save it? My current approach is using NSMutableDictionary, but I just can't understand the logic behind this (I'm way too tired).
Thanks in advance.
If you were to serialize this into NSMutableDictionary you could just write the contents of the dictionary to a file. If you need to parse the data into objects (for whatever reason) or you want the general scalability and performance of a database you may want to look at this link to -> Core Data.
However; you did not specify in what form you want the data.
Frank
See these in NSDictionary class reference...
- (BOOL)writeToFile:(NSString *)path atomically:(BOOL)flag
and
+ (id)dictionaryWithContentsOfFile:(NSString *)path`

Edit core data entry

I have an application which is currently using and storing data in Core Data. My data moel looks like this:
My client has requested the ability to amend the Number (in Customer entity), or any of the attributes in 'Rooms' (except CustomerName).
I not sure where to start with this. I have done some googling and searching of questions, but cant seem to find a solution that fits my need.
Any help or sample code would be greatly appreciated.
Thanks
Sam
You can modify the number using the key value coding or by accessing its method directly
Customer* customer=[NSEntityDescription insertNewObjectForEntityForName:#"Customer" inManagedObjectContext:self.managedObjectContext];
customer.Number=[NSNumber numberWithInt:10];
if(![managedObjectContext save:&err])
NSLog(#"data cannot be saved");
You can access the Rooms entity in a similar way,which will be returned as NSSet* object.
Get the required object in that and modify the value in a similar fashion.

Json Object to Sqlite Database in ios

I want to push the fetched data of json file to database. Can anyone suggests some solution?
1) First of all you might guess what really you do want to do with that data, because:
you could use things like FMDB https://github.com/ccgus/fmdb.git and store that JSON as string and get it reparsed every time you need it;
also you can use Mogenerator tool https://github.com/rentzsch/mogenerator.git and smth like MagicalRecord library [https://github.com/magicalpanda/MagicalRecord.git] to easily fetch data in n out;
and finally, there's CoreData if you like Apple's choise.

Fetching data from webservice and caching on iphone

I want to access a webservice to fetch alot of data (e.g. product lists/details/search results) and display this.
Are there any best practices for this type of operations?
Performance-wise, is there any better way than retrieving, parsing and displaying text data on each request and maybe load images in the background? Are there any wise caching policies which may be applied?
If I were doing something like this from the ground-up, here's what I'd do:
Have the web site post all the data in XML. Except for maybe the pictures - just have an XML field specify a URL for each picture. So, for example, say I was doing a product list.
Use NSXMLParser to both fetch and parse the XML data.
Use a separate NSData dataWithContentsOfURL: call to fetch the contents of each image, with the URL from the XML data
Write the XML data, (and the NSData image) to a database table with CoreData. Add a indexed timestamp field to the table.
You can now use the timestamp field to keep the newest "x" records in the database - and can purge the older ones if/when you need to.
Use the contents of the database table to populate a UITableView - or however else you want to present.
Make some sort of "next", "prev" or "update" fields in the UITableView to get more data from the web, if you need to display more data than is what is cached - or you want to update the data in the cache.

Core Data - GROUP BY

I am trying to group results returned by Core Data. I read that you need to use "SortDescriptors" with a selector but I cant seem to get it to work?
I am trying to return group'ed "unique" name values?
http://developer.apple.com/library/ios/#documentation/cocoa/Conceptual/SortDescriptors/Concepts/Creating.html
Actually, I think you want #distinctUnionOfObjects. See the Xcode Documentation: Key-Value Coding Programming Guide: Collection Operators.
try using #distinctUnionOfArrays.contactNumber to get the objects