Xcode database programming

Discussion in 'iOS Programming' started by uba2012, Aug 20, 2012.

  1. macrumors member

    Joined:
    Jul 5, 2012
    Location:
    Denmark
    #1
    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
     
  2. macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #2
    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.
     
  3. macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #3
    I'd just use Core Data with an SQLite database, and have CoreData Managers via Singletons or instance methods for accessing the core data :)
     
  4. thread starter macrumors member

    Joined:
    Jul 5, 2012
    Location:
    Denmark
    #4
    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
     
  5. macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #5
    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.
     
  6. thread starter macrumors member

    Joined:
    Jul 5, 2012
    Location:
    Denmark
    #6
    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.
     
  7. macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
  8. thread starter macrumors member

    Joined:
    Jul 5, 2012
    Location:
    Denmark

Share This Page