r/simpleios • • Oct 29 '11
[Question] "instance method '-openDB' not found"
I'm quite new into iOS and Objective C development and this I guess is more of an Objective C question. I'm building a class, Movie, which will eventually be a model class for my app.
I have my Model.h file which looks like
#import <Foundation/Foundation.h>
@interface Movie : NSObject
{
NSString *title;
NSString *year;
}
@property (strong, nonatomic) NSString *title;
@property (strong, nonatomic) NSString *year;
- (NSArray *)getMovies;
- (NSString *)filePath;
@endAnd Movie.m file which looks like
#import "Movie.h"
#import "sqlite3.h"
@implementation Movie
@synthesize title, year;
- (NSArray *)getMovies
{
[self openDB];
}
- (NSString *)filePath
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
return [documentsDir stringByAppendingPathComponent:@"database.sql"];
}
- (void)openDB
{
sqlite3 *db;
if (sqlite3_open([[self filePath] UTF8String], &db) != SQLITE_OK)
{
sqlite3_close(db);
NSAssert(0, @"Database failed to open.");
}
}
@endI'm getting a warning of: Instance method '-openDB' not found. If I add
- (void)openDB;into Movie.h then the warning disappears, as expected.
However, and this is where I'm not quite getting my head around it, if I have a UIViewController class and put the same code from the implementation file into the ViewController implementation class but don't declare - (void)openDB in the interface section of that class, I don't get this warning.
I'm guessing something is going on in the background that I'm not aware of that doesn't happen in a normal Objective C class. Can anyone suggest what is going on?
Thank you!
Edit: after consulting freenode, it turns out because I've declared the openDB function below where it's being called, that's why the warning is being shown.
View all comments
Show parent comment
1
u/[deleted] Oct 30 '11
Thanks for this tip!