Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You wrote a setter for your managedObjectContext, but it does nothing:</p> <pre><code>- (void) setManagedObjectContext:(NSManagedObjectContext *)managedObjectContext{} </code></pre> <p>When you do <code>self.managedObjectContext = nil</code>, all it does is call <code>[self setManagedObjectContext:nil]</code>. That does nothing. The instance variable managedObjectContext keeps the same value, and when you request it again with the getter, you still have the managedObjectContext that was associated with the deleted file. You need:</p> <pre><code>- (void) setManagedObjectContext:(NSManagedObjectContext *)_managedObjectContext { [managedObjectContext release]; managedObjectContext = _managedObjectContext; [managedObjectContext retain]; } </code></pre> <p>And that's also assuming your managedObjectContext property is declared with the nonatomic modifier. If it's declared atomic, you will also need code to lock. Write the setters for managedObjectModel and persistentStoreCoordinator in a similar way.</p> <p>@synthesize usually generates setters like that for you, but since you want to write your own getters, you have to write your own setters too. There might be a way to have @synthesize make only the setter for your property instead, but I can't remember.</p> <p>Answer to follow up question. Maybe you are doing something like this:</p> <pre><code>NSManagedObjectContext *moc = self.managedObjectContext; [self reset]; [self repopulateData:xmlFile]; NSError *error = nil; if (![moc save:&amp;error]) [self logError:error]; </code></pre> <p>If that's the case then you would be calling save on the old managed object context. Not sure what the outcome of that would be. Instead change the next-to-last line to</p> <pre><code>if (![self.managedObjectContext save:&amp;error]) </code></pre> <p>to make sure you are using the current managed object context.</p> <p>Or similarly you might be trying to read from the old managed object context. Check the address of any managed object context pointers you are using and make sure they are pointing to the same thing as the new managed object context you created in reset.</p> <p>If that's not the problem, I have no idea. You will have to try to gather more information as to why it's not working. For example, does the file exist at all? Does its size increase when you add the data? Is the data written to the file, but can't be read?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload