core data - how to use? - iphone

I want to build an app that uses core data, but all the tutorials I found in the net didn't show if I can store a data without using the code it self.
Is there anyway to do it?
For example, i want to make a row of name and put there couple of names.

I've just read the book "Pro Core Data for iOS" from APRESS it covers Core Data very well. I recommend this by heart.

You can try Core Data Editor. But it's not cheap.

You can use SQLite directly without Core Data; there you'd have your SQLs in your own hands. Your can use Core Data and debug SQLs issued by the framework, of course if using SQLite as the store.
Core Data works also with binary and XML format (the latter not available on iPhone): passing following argument to the application:
-com.apple.CoreData.SQLDebug 1
Other than that, you could probably use SQL to access Core Data SQLite store, since it is all SQL, but it is not recommended.

Unfortunately Core Data is all code. However, CoreData is an api that helps you create, save, load data from the database, it uses SQLLite in an easier fashion.
If you need very complex data storage then by all means use SQLLite directly. But, if it's just simple data storage of names, emails, booleans, etc, then i would recommend CoreData.
I'll give you a link that it helped me greatly when i wanted to integrate CoreData for my app.
CoreData Tutorial
Good Luck.

Related

Use txt files or sqlite with core data in project?

I am developing iPhone app for a web application currently running online. Current web application is big and complex and uses SQL to store vital information like member details, login credentials etx. Other stuffs like info about several sections, groups, sub groups and other information related to each are saved in txt. Current system uses its own standard to keep data in files and also made custom algorithm to read and write data in it. Each txt file is below 1 mb size. There are lot of data manipulations going on.
Custom algorithm created just read those files and put all data in cache as records (same as in core data managedobjectcontext) and whenever there is a change in data the whole file is overwritten.
So while implementing the same what I want to choose for iPhone app? In apple website they said that 'SQLite is perfect for low-level relational database work' https://developer.apple.com/technologies/ios/data-management.html But in my case it is high level.
So please help me to make a decision. Do I want to manage data in files or sqlite database using core data?
I would also like to know whether it is possible to import those classes and algorithms currently in webserver to iOS, so I don't want to rewrite the same algorithm for iOS? Current server codes are in C#
In the rare case that you need to do low-level relational database work use SQLite. In the 99% other cases use Core Data. Don't ever store relational stuff into txt files. It'll just be a pain.
Your use case sounds like a good match for Core Data.
Often misunderstood, Core Data is an object store that happens to use sqlite for persistence. You don't manipulate the sqlite underneath it, Core Data manage the sqlite for you. You do not write SQL. The closest match to it in .NET is EDM and the Entity Framework in ADO.NET.
Assuming the classes and algorithm you want to import in the webserver is in C#, sadly those needed to be ported to Obj-C.

Using SQLite on the iPhone: do I have to read the entire database and store it into an array?

Hi I am a newbie to iPhone programming. I have been looking at some tutorials online for using SQLite on the iPhone.
From what Iv'e seen, one has to read the entire database in the app delegate method and then store the contents in an array. This is then used to populate a UITableView.
I was wondering how this can be efficient? I mean, if you are going to store the contents of your entire database in memory why have a database?
Is this standard practice?
Instead of this, if I use Core Data, I can set the paging size and it will optimize how much data is stored in memory and only read whats being shown within the visible cells.
Is there anyway, In can have the same functionality using SQLite? so its easy on memory. I mean my database has only 300 entries now, but what if in the future it has 3 million?
Can some one please assist me in understanding this....
Are there any tutorials for SQLite that show how to do it in an optimized way?
Thanks
I would suggest using Core Data. It's extremely powerful, better supported than a SQLite table, and not as complicated as it looks, it just uses a lot of "managed object" jargon which can be daunting at first. Check out the CoreDataHelper class, and a few tutorials. I was able to get Core Data working in a few days (in my first ever app) using the links in my comment
If you're familiar with SQL, basically Core Data works like this: the Persistent Store IS a SQLite table, but you never access it directly; the managedObjectContext is where you do all the data work in your program (and don't forget to save it to the persistent store!), while an Entity is a table, attributes of that entity are your columns, and a managed object is a row.
Further Reading:
Core Data Tutorial - YouTube
Core Data Tutorial: Getting Started | Ray Wenderlich
iPhone Core Data: Your First Steps
Here is some tutorial that may help you:
iPhone Programming Tutorial.
I recommend you consider using core data instead of sqlite.

Which database should you use to program an iPhone/iPad application?

I am new to iPhone development and want to know which database you use to program an iPhone/iPad?
I have heard its SQLite, are there any alternatives to this?
The application I am programming is like an online shop however you can't buy products, only view their details.
You should use CoreData for that. CoreData is a database abstraction layer which uses SQLite to store your data. Or you could use SQLite directly. But I would prefer CoreData.
Core Data Programming Guide
Core Data Overview
If you have any plan to use the database file outside iPhone e.g. in other computer, or data input program to populate data, then SQlite is the best choice. CoreData modify the fields name when you create the database inside XCode. But if the data is only accessed by your app in the iPhone, best choice is CoreData.
If you want to run complex sql query then sqlite is better. Read about NSPredicate, what type of query you can do there.
SQLite is the master choice here!
As an alternative, I would suggest you the simplicity of an XML file.
You can also use NSUserDefaults if u have less data to be stored in your database.
http://icodeblog.com/2008/10/03/iphone-programming-tutorial-savingretrieving-data-using-nsuserdefaults/
If the data to be stored is more then go for sqlite

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.

New to Core Data for iphone

I am new to the iphone platform and am creating an app that retrievals a rss feed and displays it in a UITableView. I have gotten this working perfectly (or rather, the way I wanted). What I was thinking was I would store the current feed items on the phone so that it would initally load the old items it has stored while it got the new feed, then parse the new feed and add the new items and refresh the TableView. I was going to use Core Data to store it the old feed items because it would be a good way of learning Core Data and it would be an appropriate use of Core Data. However, I am having a difficult time learning how to use Core Data and connecting it with the Table/Array.
I have already googled and looked on stackoverflow for tutorials but have yet to find anything that explains it in a way I really understand. Any explanation of the overall steps that it takes to add Core Data to an existing app would be greatly appreciated. Full-blown detail are not necessary (but would also be useful). I'm just not very experienced with SQL or storing of data in such a manner and am having trouble wrapping my head around how the whole concept of Core Data works and how it connects to everything.
Also, any better method of doing what I'm trying to accomplish would also be appreciated.
There exist Xcode templates for Core Data-based applications; these are a great start to getting Core Data off the ground. However, it sounds like you want to integrate Core Data into your existing app, so you'll need to...
Add three main Core Data objects: the managed object context (MOC), the managed object model (MOM), and the persistent store coordinator (PSC). These need to be accessible wherever you want Core Data available, so either in your app delegate or, more preferably, in the controller or data source for your table view.
Create a MOM in Xcode. This will be a file of type .xcdatamodel, and it's an object graph that defines all the Core Data entities you want in your app.
Use NSFetchedResultsController (as suggested by Louis Gerbarg) to get data out of Core Data and display it into your table view.
Add code in your existing RSS-fetching-and-parsing routines to store new Core Data objects back into the store, when appropriate.
A good way to start is just to create a new Core Data application and play around with it a bit; you can also look at Apple's fantastic resources on the subject, like the Core Data Programming Guide and the sample apps Recipes and Locations. (Developer registration may be required.)
One last thing to note is that for the most part, a lot of the Core Data code you need to add can be ripped straight out of one of the Xcode template apps and pasted into your program (this holds especially true for the accessors for the three Core Data objects you need). Be careful not to use code you don't understand, though.
If you are using CoreData to populate a UITableView you really want to use NSFetchedResultsController as opposed to trying to populate and sync array yourself. The documentation for NSFetchedResultsController includes links to several CoreData tutorials, including onces that populate table views.
NSFetchedResultsController is still a bit buggy and requires fragile workarounds. I would start with the simpler iPhone Core Data "location" tutorial before moving on to the Books tutorial.
Also, any better method of doing what I'm trying to accomplish would also be appreciate
yes, it sounds like Core Data might be overkill for your application. Assuming your feed items are stored in a collection object you can easily use OSX's built in serializaition.
Been noted in other Stack-Overflow posts, but I can highly recommend the Prag Prog book "Core Data: Apple's API for Persisting Data on Mac OS X" - most is also relevant to iPhone Core Data apps; there is a whole chapter on creating an iPhone app too.
http://pragprog.com/titles/mzcd/core-data