Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3931660
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:22:23+00:00 2026-05-19T23:22:23+00:00

I am starting to learn Objective-C and to help me doing so, I am

  • 0

I am starting to learn Objective-C and to help me doing so, I am using “Head First iPhone Development”. Now I am learning about SQLite databases and to get these to work I am told that the SQLite file needs to be in the Documents folder of the application and therefore I have to move the file.

I am using the example from the book but I can’t seem to get it to work. Everytime I compile it my app crashes. I have the following warning: “Incompatible Objective-C types initializing ‘struct NSURL *’, expected ‘struct NSString *’

Does anyone have a tip how to fix this?

EDIT:

The problem seems to be in these two lines with applicationDocumentsDirectory returning an NSURL but I tell it to return an NSString. I could tell it to return an NSURL but that gives me a problem on the next line where I use stringByAppendingPathComponent. Is there a way to fix this?

    NSString *documentsDirectory = [self applicationDocumentsDirectory];
    NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:@"iBountyHunter.sqlite"];

This is what the Debugger Console outputs when the app crashes:

2011-02-04 07:33:42.126 iBountyHunter[591:207] -[NSURL stringByAppendingPathComponent:]: unrecognized selector sent to instance 0x6043f80
2011-02-04 07:33:42.128 iBountyHunter[591:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSURL stringByAppendingPathComponent:]: unrecognized selector sent to instance 0x6043f80'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x00f87be9 __exceptionPreprocess + 185
    1   libobjc.A.dylib                     0x010dc5c2 objc_exception_throw + 47
    2   CoreFoundation                      0x00f896fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
    3   CoreFoundation                      0x00ef9366 ___forwarding___ + 966
    4   CoreFoundation                      0x00ef8f22 _CF_forwarding_prep_0 + 50
    5   iBountyHunter                       0x00001d8e -[iBountyHunterAppDelegate createEditableCopyOfDatabaseIfNeeded] + 107
    6   iBountyHunter                       0x00001f24 -[iBountyHunterAppDelegate application:didFinishLaunchingWithOptions:] + 37
    7   UIKit                               0x002ba1fa -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1163
    8   UIKit                               0x002bc55e -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 439
    9   UIKit                               0x002c6db2 -[UIApplication handleEvent:withNewEvent:] + 1533
    10  UIKit                               0x002bf202 -[UIApplication sendEvent:] + 71
    11  UIKit                               0x002c4732 _UIApplicationHandleEvent + 7576
    12  GraphicsServices                    0x018bda36 PurpleEventCallback + 1550
    13  CoreFoundation                      0x00f69064 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
    14  CoreFoundation                      0x00ec96f7 __CFRunLoopDoSource1 + 215
    15  CoreFoundation                      0x00ec6983 __CFRunLoopRun + 979
    16  CoreFoundation                      0x00ec6240 CFRunLoopRunSpecific + 208
    17  CoreFoundation                      0x00ec6161 CFRunLoopRunInMode + 97
    18  UIKit                               0x002bbfa8 -[UIApplication _run] + 636
    19  UIKit                               0x002c842e UIApplicationMain + 1160
    20  iBountyHunter                       0x00001cf8 main + 102
    21  iBountyHunter                       0x00001c89 start + 53
)
terminate called after throwing an instance of 'NSException'
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T23:22:23+00:00Added an answer on May 19, 2026 at 11:22 pm

    This will do the trick.

    // Check the existence of database 
            NSFileManager *mngr = [[NSFileManager alloc] init];
    
            // If the database doesn't exist in our Document folder we copy it to Documents (this will be executed only the first time we launch the app).
            if (![mngr fileExistsAtPath:[NSString stringWithFormat:@"%@/Documents/db.sqlite", NSHomeDirectory()]]){
                NSString *filePath = [[NSBundle mainBundle] pathForResource:@"db.sqlite" ofType:nil];
                [mngr copyItemAtPath:filePath toPath:[NSString stringWithFormat:@"%@/Documents/db.sqlite", NSHomeDirectory()] error:NULL];
            }
            [mngr release];
    

    here’s another version of the applicationDocumentsDirectory method:

    + (NSString*)applicationDocumentsDirectory {
    
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
        return documentsDirectory;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently started learning objective-C and cocoa. I'm slowly starting to learn about memory
I'm starting to learn about using Memcached with PHP and I was wondering; is
i'm just starting to learn about database design. For my first project I made
I'm just starting to learn about Quartz Composer and the first thing I would
I am starting to program in Objective-C. I am using a book to learn
I'm just starting to learn Objective-C using GNUstep on Windows and I'm wondering what
I'm just starting to teach myself objective-c and attempting to learn the cocoa touch
Just starting to learn ASP.NET (C#) and I am using Visual Studio 2008. I
I'm just starting to learn Objective-C, one thing I'm trying to learn is good
I'm just starting to learn about jQuery. I'm more of a html+css web designer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.