0

I have this code where I am attempting to create a database; I'm getting a warning (which is causing the crash) about "instance variable 'db' accessed in a class method". Being a newbie, I don't know how to fix it (crash occurs on line 57). Help is appreciated. :D

the .m file

This is the .h file: the .h file

SpokaneDude
  • 4,856
  • 13
  • 64
  • 120

1 Answers1

3

checkIfDatabaseExist is a class method (you marked it with +). This method belongs to class itself no to instances of this class. db is instance variable so class method doesn't have access to it. Make checkIfDatabaseExist instance method

- (void)checkIfDatabaseExists { ... }
hoha
  • 4,418
  • 17
  • 15
  • On this code (where I call 'checkIfDatabaseExists', I'm getting a warning: SQLiteDB may not respond to +sharedSQLiteDB. How do I fix that? `myDB = [SQLiteDB sharedSQLiteDB]; // instantiate SQLiteDB [SQLiteDB checkIfDatabaseExists]; // see if the database exists` – SpokaneDude Mar 09 '11 at 23:43
  • It's because there is no `sharedSQLiteDB` in your class interface. Just declare this method in interface part of `SQLiteDB` like `+ (SQLiteDB *)sharedSQLiteDB;` and this warning will go away. – hoha Mar 09 '11 at 23:54
  • Thanks HoHo... did that, but still getting a SIGABRT (see http://imgur.com/sCz1Q). – SpokaneDude Mar 10 '11 at 00:21
  • Since you've made `checkIfDatabaseExists` an instance method you have to send `checkIfDatabaseExists` message to instances - for example to object returned to you by `[SQLiteDB sharedSQLiteDB]` – hoha Mar 10 '11 at 00:26
  • I really recommend you to read 'The Objective-C Programming Language' (you can find it in 'Developer Documentation' section of Help menu). Reading this will repay very soon – hoha Mar 10 '11 at 00:28
  • Thanks, HoHa... I have bought several books, none of which help very much... I'm a C# programmer, usually using Monotouch, but for this app, I can't. Struggling with Obj-C. Today I purchased "Cocoa in a Nutshell", which I think will help. Thanks for your time and advice, I appreciate it. – SpokaneDude Mar 10 '11 at 01:36
  • If you don't know C language I highly recommend to read "The C Programming Language" by Brian Kernighan and Dennis Ritchie. It's in Top-10 in this thread about most influential books - http://stackoverflow.com/questions/1711/what-is-the-single-most-influential-book-every-programmer-should-read. C is really important language to know and not only because it's a subset of Objective-C Good luck! – hoha Mar 10 '11 at 09:32
  • Hoha... I know C, C++, C# and a few other languages... I'm just having a hard time getting my hands around Objective-C... if I knew Smalltalk (I think that's where some of the Obj-C design came from), I could probably figure it out... but right now, I'm struggling with it... the light will eventually turn on, just hope it's before I die! :D – SpokaneDude Mar 10 '11 at 14:05