Put the call to modelContext.fetch() inside a try { ... } catch { ... } block, and print out the error that it catches.
If you're trying to do something but you aren't bothering to catch any errors to see why it's failing, you're going to hit issues like this.
Your current code is always assuming that everything is 100% tickety-boo all the time. If transactions was nil, the call to transaction.count would crash the app anyway.
Topic:
App & System Services
SubTopic:
iCloud
Tags: