Search code examples
iphonecrashnsstringdirectorynsurl

Incompatible Objective C types


I am trying to store the location of my Application's Document Directory in a NSString.

NSString *documentDirectory = [self applicationDocumentsDirectory];

The code compiles without error, but I get the warning that I am trying to initialize a NSString with a NSURL. When I run the app, the app crashes. I tried casting, but it gave me an error. The book I got it off(Head First iPhone Development) says the code should work. The code is in my appDelegate.m file. Any Help will be greatly appreciated.

Regards


Solution

  • It is returning an NSURL as Dave DeLong said. However the easiest way to get round this and convert it to an NSString without changing the method, is setting the string to the NSURL's absoluteString.

    NSString *documentDirectory = [[self applicationDocumentsDirectory] absoluteString];