0

Here's the error message:

warning: 'ReaderAppDelegate' may not respond to '-checkForDatabase' (Messages without a matching method signature will be assumed to return 'id' and accept '...' as arguments.

I put a breakpoint at the 'checkForDatabase' method in the code below, and it never got there... the app died. I'm assuming he warning above has something to do with the abort. How do I fix this? Do I have to declare 'checkForDatabase' in my .h file?

//---------------    application finished launching    ----------------|
- (void)applicationDidFinishLaunching:(UIApplication *)application  {
    //  create the d/b or get the connection value
    [self checkForDatabase];    

}

//--------------    check for database or create it    ----------------|
- (void)checkForDatabase  {

    NSFileManager *filemanager = [NSFileManager defaultManager];
    NSString *databasePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] 
            stringByAppendingString:@"/ppcipher.s3db"];

    if(![filemanager fileExistsAtPath:databasePath]) {  //Database doesn't exist yet, so we create it...
        NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/ppcipher.s3db"];
        // remainder of code goes here...
    }
}
SpokaneDude
  • 4,856
  • 13
  • 64
  • 120

3 Answers3

1

As you mention, you need to declare the function within your interface or the dynamic (i.e.: runtime) binding won't know that the method exists.

John Parker
  • 54,048
  • 11
  • 129
  • 129
  • I added it to my .h file (- (void)checkForDatabase; ), but now the app dies... I can't see where the crash is; isn't the XCode debugger supposed to tell you these things? (it does in Monotouch!) – SpokaneDude Mar 07 '11 at 21:23
  • @Spokane-Dude If you put the breakpoint at the `[self checkForDatabase];` line you should be able to step into the method. That said, if you've added the `- (void)checkForDatabase;` to the correct part of your interface (outside of the variable definition block, before the `@end` directive), it sounds like the problem lies elsewhere. – John Parker Mar 07 '11 at 21:29
  • I commented out the [self checkForDatabase]; and it still dies... here is the console output: (the last two lines repeated themselves) ttys001 Program loaded. target remote-mobile /tmp/.XcodeGDBRemote-949-102 Switching to remote-macosx protocol mem 0x1000 0x3fffffff cache mem 0x40000000 0xffffffff none mem 0x00000000 0x0fff none (gdb) run Running… Error launching remote program: failed to get the task for process 245. The program being debugged is not being run. – SpokaneDude Mar 07 '11 at 21:48
  • @Spokane-Dude Think you need to have a read of http://stackoverflow.com/questions/4720597/profile-bug-error-launching-remote-program-failed-to-get-the-task-for-process-x :-) – John Parker Mar 07 '11 at 21:54
  • I am using the Development profile; this was working before I added the code to check for the database. Even when I comment all of the database code out, it still won't run... – SpokaneDude Mar 07 '11 at 22:03
  • @Spokane-Dude Bizarre. In that case I'm out of ideas. (Presume you've tried deleting the app off the device, doing a clean and rebuild in Xcode, rebooting your Mac, etc.?) – John Parker Mar 07 '11 at 22:04
  • I found it... I had renamed some of the files, and didn't rename the files in IB... thanks so much for your time... I really appreciate it. – SpokaneDude Mar 07 '11 at 22:21
  • @Spokane-Dude No worries - glad you managed to get it sorted. :-) – John Parker Mar 07 '11 at 22:24
0

It'd be a good idea to declare the -checkForDatabase method in your class's interface, but I don't think that's the cause of your crash. Look at the console for a message that will probably indicate the cause of the crash.

Caleb
  • 124,013
  • 19
  • 183
  • 272
  • I think you might be surprised. :-) – John Parker Mar 07 '11 at 21:18
  • Thanks for the pointer... didn't know it existed... anyway, here is the contents Running… Error launching remote program: failed to get the task for process 177. Error launching remote program: failed to get the task for process 177. The program being debugged is not being run. The program being debugged is not being run. – SpokaneDude Mar 07 '11 at 21:31
  • @middaparka: You can send any message to any object in Objective-C. Now, if the receiver doesn't implement that message, the default behavior is to throw an exception, and if you don't catch the exception the app will terminate. But simply failing to declare a method that you call is not going to cause a crash (so long as you do define it). – Caleb Mar 07 '11 at 23:44
  • @Spokane-Dude: Your app clearly has other issues. I'd start by verifying that the app delegate is properly connected. Put a breakpoint in main() to see if you even get there. Check that the main nib file is correctly specified. Did you make any changes to the build settings? What happens if you copy your source code into a new project? – Caleb Mar 07 '11 at 23:52
0

You either need to declare checkForDatabase in your header file or in a private category in the implementation file. You could also define the method implementation above the implementation of applicationDidFinishLaunching.

Stephen Poletto
  • 3,645
  • 24
  • 24