@weakify, @strongify

ARC supposedly does away with reference counting. However, blocks introduce a small wrinkle.

When you reference self in a block you make a strong reference to it which encourages leaks as you end up with objects (including View Controllers) hanging around beyond when they’re needed.

The solution is to define a weak reference before the block and use that. Inside the block you convert it to a strong reference. We don’t have a proper strong reference outside the block so it decrements as it should do. However, it’s a pain (see the first part of the linked-to post).

This is where the @weakify(self) technique makes things simple and easy. See the second part of this post!


Law of Demeter


In OO software, do not assume knowledge of anything else.

Longer explanation

The Law of Demeter (LoD) is the principle of least knowledge for developing software.

Roughly speaking other ways of expressing this are:

  • software should be loosely coupled
  • principle of encapsulation
  • principle of “information hiding”

For modern OO languages, when using dot notation simply use 1 dot. i.e. something like this would be forbidden:


as you’re assuming knowledge.

Much longer explanation here: http://en.wikipedia.org/wiki/Law_of_Demeter

Advanced App Tricks

One of those Apple articles that just doesn’t seem to fit in anywhere but rather useful.

  • Configuring your app to support iPhone5
  • Creating a Universal App
  • Supporting Multiple Versions of iOS
  • Launching in Landscape Mode
  • Installing App-Specific Data Files at First Launch
  • Protecting Data Using On-Disk Encryption
  • Tips for Developing a VoIP App
  • Communicating with Other Apps
  • Implementing Custom URL Schemes
  • Showing and Hiding the keyboard
  • Turning off Screen Locking