The first time I used Core Data I thought it was amazing. However, I got it all very wrong. I had "helper" functions in the App Delegate, I didn't use any relationships in the data model, etc... All very wrong.
Then I learned more about it and did it all myself again, this time it was excellent! I understood how the relationships worked, I was using NSFetchedResultsController. Merging changes from background contexts, syncing changes up to a server, everything.
Then I found Magical Record... this is awesome! (I thought).
It makes everything to do with Core Data so easy! (I thought).
It puts hundreds of different functions in to one line of code. Creating fetches becomes so easy, saving is easy, NSFetchedResultsController creation is now one line of code.
I went to town. Completely integrated it into my app.
Then I migrated my app from Xcode 4 to Xcode 5.
Ran the app... everything is fine! Woop!
Wait... the UI isn't responding, I can't press any buttons, no exceptions thrown either, what's going on?!
I paused the app and the first line in the stack trace looked a bit odd.
Looks like something to do with Core Data is blocking the main thread. Time to put my debug hat on...
Right, CoreData, where could the error be?
Wait... I have no idea. Something in Magical Record is doing something that looks like it's causing a deadlock between threads.
Do I know where it is? Nope, I didn't write it.
Do I know where to start looking? Nope, this code is alien to me.
Do I wish I could pull Magical record out of the project? Absolutely.
Is this blog really just a rant?
OK, let me get to my point.
I doubt that Magical Record is fully to blame for this. I'm guessing that somewhere I used it in the wrong way that caused this error. I guess...
But that's just it. I can only guess at what is wrong.
Because I've relied so much on someone else's code there isn't really anything I can do to work out how to fix it. I don't know the inner workings of my app when the inner workings is what I'm building.
I've since started a couple of other projects using CoreData and networking and neither of them use AFNetworking or Magical Record. Not because I think they are bad or don't work, but because I know that I can do everything I need just as easily and just as well. In fact, in both cases, my own code worked better for what it needed to do than either of these frameworks could do for me.
Of course, I'm not suggesting that everyone should stop using Magical Record and AFNetworking. Just make sure you know how and why they work before diving in head first. There will come a time when you need to know why something is acting in a particular way and you'll need to know the fundamentals.
I'm stuck with two options at the moment.
1. Try and work out what is happening that is causing this deadlock. I have no idea if it's my code or Magical Record code.
2. Try and remove Magical Record completely from my app. This is no mean feat. There are uses of it all over the place.
::Sigh:: back to work 🙁