saving and retrieve core data from server - iphone

I'm planing to use core data to store my data. I want the user to add some data or update some data that have been added previously by him. I'm going to use a server to save the core data on it, I've read some question here and the answer was to use RESTKit. but I'm not sure if it's the right choice or not, my question is it simple to do what I said before about save the data and retrieve it from server by using a core data? and please if any one have a tutorial for me that will explain lot of things to me like my Idea :/
i did the design and I have now core data with all the entities like user entity and photo entity.
I hope I made my question clear >_< and Thank you for reading my question :$

I like AFNetworking. If you write your web-services to work with JSON, this is a great choice IMO. If you are using XML based web-services and don't want to / can't change to JSON, then TBXML is a great choice for parsing XML.

Related

Fetch data from JSON server and automatically store in sqlite

I want to fetch data from JSON and store it automatically to sqlite whatever updated on server automatically updates to database whenever program runs.
Can anyone help me out in it. And if my question is not sufficient to answer please ask anything required.
Thanks in advance.
I would look into the RestKit framework. It takes care of the low-level API calls, object mapping, SQLite persistence, etc. It's well documented and maintained.
You can start here http://www.raywenderlich.com/5492/working-with-json-in-ios-5
After reading this, you can user this Class, https://github.com/AFNetworking/AFNetworking. It's easy and usefull!
Download JSON data with AFNetworking and decode with JSONKit, then you can save to SQLite with this wrapper FMDB.
If your supporting iOS 5+ then JSON is added for you by default and can use it using the method given here and after getting the dictionary of objects , you can follow the normal procedure of adding them to sqlite or use core data as said by #Paras Joshi.

how to fetch data from webserver and store to our database through SQLite

i want to fetch data from web server and save it in my local database through sqllite.How is it possible.
You can fetch data from webserver using JSON and webservice and then parse the JSON Response string.
Then you may create insert statements from the data obtained and execute it to insert in your database using executeNonQuery method of SQLite.
Best option is to do all this on appDidFinishLaunching so that there would be initial delay but then whole app after that would not face any performance issues i.e. No delays
Hope this helps you.
Well,
it depends on what kind of data you want to fetch. If you want to fetch XML from the webserver, you will get a nice list of xml parsers on this site: http://www.raywenderlich.com/553/how-to-chose-the-best-xml-parser-for-your-iphone-project
Another nice option for fetching any kind of data from the webserver is curl. You can find static libraries on this page: http://code.google.com/p/ios-static-libraries/
Well, there's always the option to use the iOS native libraries, which are documented (with examples) in the iOS SDK.
I would not recommend using "raw" SQLite these days unless you have an exceptional reason to do so. Core Data is the way forward.
I'm not really sure what your question is; it's so broad. But, in general, you'd create an NSURLConnection, download the data, parse the data and store it in your database. Each stage is pretty well documented and there are lots of questions here on each stage.
If you use Core Data there are also some open source projects, such as RestKit, that might give you a good starting point.

Using core data with web services

I am a newbie in Xcode. I am developing an iPhone app where I need to send and receive data from a web service. And I need to store them temporarily in my app. I don't want to use SQLite. So I wondering if I should use core data for this purpose. I read some articles but I still don't have a clear picture of How to do it, because I have used core data only with SQLite. I want to do the following things :
How to receive table data from a web service?
Have to perform certain calculations on those fields.
How to send the data back in xml format to the server?
How do I convert the xml data into int, date or any other data type? And How do I store it in managed data objects?
You want to use an XML parser to turn the XML into other objects; I tend to recommend TouchXML for that.
You can use Core Data and an in memory store if you are not going to save the data as it will then create and manage all of the data objects for you and generally give you less code to write. However that depends on your app if it is worth it or not. Personally i use Core Data in every app that works with data.
As for sending data, you can use the same library that you used to consume the XML to produce XML. Most of them now days are bi-directional.
For a specific example of fetching XML from server and then storing on the device using core data take a look at Björn Sållarp's blog post on Core Data and UITableView. A drill-down application. Note this example makes use of NSXMLParser and not TouchXML.
I have also found [coredatalibrary xcode template][2] to be quite useful in getting started with a new Core Data project.
Also if you are adding custom logic to your managed objects take a look at rentzch's [mogenerator][3] which generates 2 classes _MyEntity and its subclass MyEntity.

Question about optimal way to organize data for a book-esque iphone app

I would like to begin work on an iPhone app that does little more than display a books content for reading. The book content is available online, and is fully open source, but I would like to make the content available locally. With apps that I have worked on previously, namely with iPhone OS 2.X, creating (or finding) an .sql database and then just making queries for data from within the app worked really well. With the advent of Core Data (which I am not that familiar with) the older sql method may not be ideal. So my question is: What is the best way for me to go from online web content to locally stored iPhone readable content? Regardless of which approach I take, I am going to need a db (right?), so should I get the brunt of it out of the way and start with importing the web content into a db with all of the correct tables and columns? I guess with this question, I am just looking for a point in the right direction. If there were any suggestions about the best method for me to get rolling on this, it would be greatly appreciated. Thanks!
Core Data is good if you have "objects" that you want to make persistent. In the case of having just a lot of data to read/write, plain old SQLite may be simpler.
Sorry that I can't give any more specific advice, but it comes down to how complicated your app's data model and object models are. I'd recommend looking at Core Data, but don't use it just because everybody tells you how cool it is.
If you go with Core Data, you won't define your own SQL database schema, so don't start down that path until you've made the decision.
I actually would go with the Core Data route. Core Data is just an API provided by Apple to manage persistent data no matter the data backend (wether it is a flat plist file, an XML file, or a full sqlite database file).
In the case of a book, you can break down the entities as follows.
Book Entity
Title which is a String Attribute
Author which is a String Attribute
chapters which is a has many relationship of Chapter Entities
Chapter Entity
Title which is a String Attribute
pages which is a has many relationship of Page Entities
Page Entity
PageText which is a String Attribute
Then you can access all the values as if they are objects using Core Data without having to worry about the SQL backend code, and writing all the code to translate the SQLite datatypes to Cocoa objects that your view controllers can display.

How to write Data Base application in iPhone

Hi I am create an iPhone app, which will use SQLite as database. This database is synchronized by websever by XML HTTP request. The problem is, I don't have pre-build architecture for creating database app.
Is there any tutorial which will guild me how to write Data Access Layer(DAL) or how to import SQLite file with iPhone in secured way.
I dont want to open database connection again and again, its like creating a single class which will handle all database related part.
Please suggest me.
Thanks
You just described something that Apple calls Core Data. See this link for some more details
http://cocoadevcentral.com/articles/000086.php
It does describe Core Data on the desktop but it is essentially the same.
Core Data is a pretty light wrapper for SQLite written by apple. Core data once you have your base code in place you will find it pretty easy to work with.
The other big win with Core Data is that it has a small memory foot print which is important to make sure your application performance optimal.
I would first start with some sample code, core data is going to take a few hours to get started and few days to weeks to learn but once you are past this you should find it very handy and powerful.
John.