2

I am creating UIManagedDocument and I don't know why I get the error saying:

Thread 1: EXC_BAD_ACCES code=1 address=0xdeadbeef

The only thing in my code is the creation of this UIManagedDocument. This function is called in viewDidLoad:

- (void)setupDatabaseDocument
{
    if(!self.databaseDocument){
        NSURL *url = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
        url = [url URLByAppendingPathComponent:@"Default Database"]; 
        NSLog(@"self.databaseDocument will be initWithFileURL:%@",url);
        NSLog(@"%@",[[[UIManagedDocument alloc] initWithFileURL:url] class]);
        self.databaseDocument = [[UIManagedDocument alloc] initWithFileURL:url];
    }
}

I tried to print through NSLog the class of [[UIManagedDocument alloc] initWithFileURL:url] to see if it is of object type UIManagedDocument but then the EXC_BAD_ACCESS appeared again in the NSLog line of code.

I don't know if the following details are relevant to the problem: I use Xcode 4.3.3 with iOS 5.1 Simulator. I tried running this with iOS 5.0 Simulator but the same error appeared. My Mac OS X version is 10.7.4.

Why do you think am i getting this error?

Martin Verdejo
  • 1,229
  • 2
  • 13
  • 24
  • can you tell us the result of the first log? because I think the url is somehow not right.. – Bob de Graaf Sep 20 '12 at 09:08
  • Yes. It prints properly. Then (lldb) appears after it. Here: self.databaseDocument will be initWithFileURL:file://localhost/Users/martinverdejo/Library/Application%20Support/iPhone%20Simulator/5.1/Applications/88459E99-638B-4363-BE47-E70E6328B6D7/Documents/Default%20Database – Martin Verdejo Sep 20 '12 at 09:13
  • not entirely sure since I'm not all that into the ManagedDocuments, but shouldn't the filepath have an extension? Like .doc or something else? – Bob de Graaf Sep 20 '12 at 09:15
  • could it have anything to do with my starting with an empty application instead of single-view application? I restarted with a single-view application, now its working. Why? – Martin Verdejo Sep 23 '12 at 09:27
  • I guess the error you got was something else then, not really about the managed document, probably in the setup you missed something with loading the view :) – Bob de Graaf Sep 26 '12 at 11:34
  • I never found out what the error was. I started a new project as single view application and copied the code, then it worked. What could have been the problem? I started the previous one as an empty application. Maybe I forgot something. – Martin Verdejo Oct 09 '12 at 02:05

0 Answers0