Skip to main content

Welcome to ZX81.org.uk

Tag: Objectivec

When to use -retainCount?

Preamble: In pre-Swift and pre-ARC days of development on Apple’s platforms, it was necessary to “manually” retain and release objects as you used and discarded them. One common, but incorrect, pattern that kept reappearing was the idea that you could use the retainCount method to ascertain whether an object was still being used.

## When to use -retainCount? Never!

There’s pretty much never a good reason to use -retainCount. Here’s a short and mildly abusive explanation why.

NSFetchedResultsController and iCloud

This took me a while to figure out so I thought it was worth blogging about. The short version: I’m using Core Data with iCloud syncing and it works… mostly. When starting up for the first time — when there is already data in iCloud — none of the data appears in a table view, but restarting the app correctly displays it.

I know what you’re thinking: you’re not merging the updates into the right managed object context. Nope. Sorry. Thinking that was the problem is probably why it took me quite so long to track the real problem down!

Programming Is Hard

It’s hard to explain to someone who is not already a programmer the kinds of things that you have to do when building an application. The thing you’re trying to explain is often very abstract and the answer frequently would involve lots of code.

That’s why I thought this particular problem might make an interesting discussion. In talking about this very simple problem we can talk about the things that developers deal with every day and, hopefully, the process can be followed by most people who have used an iPhone (or, actually, any computer). You won’t be a programmer at the end but you might have a greater appreciation for what happens behind the scenes.