PDA

View Full Version : Xcode database programming




uba2012
Aug 20, 2012, 12:52 PM
Hey.
I am building an app for my self it's called salary calculator.
I input some data like day, month and hours, minutes worked.
and it calculates the daily earnings and stores it I a database.

I am just wondering how to use databases in objective c. I know how to use them in java which I leaned in school, but I don't understand how to do it in obj c.

I know there is the indirect way (c wrapper FMDB). and one were you access the database directly without FMDB(not core data ). So my question is which way is best if you have experience with it.

I have classes called inputs.m and .h which is a class of setter and getter methods. You know synthesizing. And classes called myinputs l.h and.m. Where I want the methods to write and read from the database to be. I want to follow goos object oriented programming practises just so I can learn from this app.

Thanks in advance for any reply



PhoneyDeveloper
Aug 20, 2012, 05:37 PM
I use FMDB. If you use direct sqlite calls you'll find that the difference in memory management between C and objective-C results in a lot of tedious code. This is wrapped up in the FMDB code.

jnoxx
Aug 21, 2012, 01:13 AM
I'd just use Core Data with an SQLite database, and have CoreData Managers via Singletons or instance methods for accessing the core data :)

uba2012
Aug 23, 2012, 02:03 PM
Do you know how I can make a insert statement with SQL/a method. I should take what it says in a text field and write to a database when you push a button. ?
I use FMDB database

PhoneyDeveloper
Aug 23, 2012, 05:41 PM
It's basically just normal SQL.

There is a file fmdb.m that comes with FMDB and that has sample code in it that shows how to INSERT into a table.

uba2012
Aug 23, 2012, 09:50 PM
Thanks I figured it out.
But I seems I can't insert integers into the database.
I use textfields to get data from and save into a integer like this :
Nsinteger day =[dayTextfield.text integervalue];

The program just crashes.

PhoneyDeveloper
Aug 24, 2012, 05:21 PM
For numbers use NSNumber.

uba2012
Aug 24, 2012, 07:40 PM
Ahh thanks:)