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...