1

I just noticed a strange issue with my app using Core Data (which didn't happen before).

Here is a section of code:

NSArray *allTransactions = [CDMTransaction transactionsFrom:_dateFrom to:_dateTo bankAccounts:_displayedBankAccounts categories:categories recipients:recipients tags:tags unclosedOnly:unclosedTransactionsOnly];
for (CDMTransaction *transaction in allTransactions) {
    if (transaction.inverseTransaction != nil) {
        ...
    }
}

What causes the issue is the call to transaction.inverseTransaction.

CDMTransaction is a subclass of NSManagedObject, which contains several properties and relationships (like inverseTransaction).

Everything worked fine until now, but I get an crash when this property is called: CoreData: error: warning snapshot_get_value_as_object called on NULL, and it sends me to the inverseTransaction property implementation.

But when I try to log the allTransactions array contents, before entering the "for" loop, it just work fine!

Here is the updated code:

NSArray *allTransactions = [CDMTransaction transactionsFrom:_dateFrom to:_dateTo bankAccounts:_displayedBankAccounts categories:categories recipients:recipients tags:tags unclosedOnly:unclosedTransactionsOnly];
NSLog(allTransactions: %@, allTransactions);
for (CDMTransaction *transaction in allTransactions) {
    if (transaction.inverseTransaction != nil) {
        ...
    }
}

And what I get in the log console:

2015-01-11 11:54:51.613 Cash[14383:1403274] allTransactions: (
    "<CDMTransaction: 0x7b94d4a0> (entity: CDMTransaction; id: 0x7b935f30 <x-coredata://12493FBF-2D83-469C-9610-D7C29E21F12B/CDMTransaction/p1> ; data: <fault>)"
)

Without any issue after...

It doesn't seem to be an issue with the inverseTransaction property because it does the same with all other properties (NSString, XNSNumber, ...) and relationships...

What is wrong?

Edit 1: when it crashes I get the property implementation line highlighted in green with a EXC_BAD_INSTRUCTION error (and not an EXC_BAD_ACCESS)

Edit 2: The app doesn't crash anymore when I add request.returnsObjectsAsFaults = NO; to my NSFetchRequest... So it seems to be OK now, but why do I have to write that? It didn't need it before...

Thomas Albert
  • 275
  • 1
  • 10
  • Are you able to follow the steps of http://stackoverflow.com/questions/7845066/exc-bad-access-with-nsfetchedresultscontroller? This in order to get other details about the problem – Lorenzo B Jan 11 '15 at 14:38
  • Where/How can I "Set NSZombieEnabled, MallocStackLogging, and guard malloc in the debugger"? I never used it before.. Thanks for your answer – Thomas Albert Jan 12 '15 at 10:03
  • Here you can find how to enable zombies, etc. http://stackoverflow.com/questions/2190227/how-do-i-set-up-nszombieenabled-in-xcode-4 – Lorenzo B Jan 12 '15 at 13:19
  • Thank you, I will check that. But have you seen my last edit on my post? I managed to get it work, but using a property on NSFetchRequest that I didn't need to set before... Any idea? :) – Thomas Albert Jan 12 '15 at 16:36
  • Yes. But with more details on the error it should be better to understand the problem. – Lorenzo B Jan 13 '15 at 09:07

0 Answers0