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.
Related
I want to store documents that I download from firestore. Each document has a unique id so I was thinking of a way I can store that document in json format or in database table (so I can access its fields) and if that id is not present in the memory than just simply download it from firestore and save it. I also want these documents to be deleted if they are not used/called for a long time. I found this cache manager but was unable to understand how to use it.
you can download the content by using any of the flutter downloadmanager and keep the path of the downloaded content in sqllite and load the data from local storage rather than url if the data is already saved.
Following pseudo-code may help you:
if(isDownloaded(id)){
//show from local;
} else {
// show from remote
}
you can manually check whether the resources are being used or not by keeping a timestam of it and update the timestamp only when it is shown. and you can run a service which looks for the unused resources and delete it from storage and the databse too.
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`
I'm trying to find the best way the save data obtained from JSON.
The website which hosts the data is: "JSON data".
Since I will be using the data in places where I won't have a connection to the internet, I want to save this data on the iPhone itself, with an ability to update when I do have an internet connection.
I'll want to display this data in a table view, and I'll need to be able to filter/search this data. This search will either be on the City, or on the store ID ("no:" in the data). Clicking the row will show a detail view of the store.
I was thinking of storing the data in an SQL table. I'm however unsure of the best way to update the data, and I don't know how to filter the data on two different columns(City/ID)?
Also, if you know a better approach I'd love to hear it!
Your data appears to be a table of addresses, with some sort of "detail" records associated with each address. This is a classic master/detail database. Normally you'd have one table with a record for each address, and assign some sort of unique ID to each address. Then have a second table that's keyed by unique ID to contain all of the detail records.
What I want :
I want to use Auto Completion of Text field in my App.As my data is coming from the web service, I want to perform the "Auto Completion" with the JSON Response.
What I Know :
I know that first I have to fetch data from the web service. Then I need to parse it and fill the Array with that parsed data and then I can use that array to perform Auto Completion.
Problem :
I don't know how to send the requests to get JSON data for each "prefix" that user types in text field (means I want JSON Data during Typing). I know how to perform "JSON Parsing" and "Auto completion of text fields" independently but no idea regarding "TextField Autocompletion with JSON Response". I tried a lot to find the answer regarding this but i failed. So Please Help me...
I am using the doautocompletetextfield to perform "Text field Auto completion".
Better Suggestion for this problem will be appreciated.
Any Solutions ?
You can use linear searching just like done in the api example or can use NSPredicate for fast searching in your autoCompleteArray.
According to your problem, you will get json data first, then you need to save relevant data from json into some array and then you can use this api to autocomplete the text in text field.
But i am confused about your this statement: "I don't know how to send the requests to get JSON data for each "prefix" that user types in text field."
1) Do you want to get json data from web service during typing?
2) Or you want to fetch data from json dictionary during typing?
If you want to go with option (1), i think it would be bad way to solve the problem.
And if you want to go with option (2) then you need to parse json and extract data of your interest and save it in an array. And then do autocomplete on the basis of the contents of that array.
hi friend
can any one tell me that i have web server there i have create the database for store some value for registration form the value was save in webserver this is working good
but now that data coming in json format and now i have fetch json value and save in to the local database which is same as the webserverdata base both the side ssame table and same colume name is there how can i do this
and how to writ the query for this sitution help me
Various JSON parsers exist for objective c. You'll have to pass the data to a library or to javascript in a webview to extract it. Here is a google library:
http://code.google.com/p/json-framework/
If you need help with saving the data, I say with no snideness whatsoever that you should read the manual:
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreData/Articles/cdUsingMOM.html
In