Retain Cycles in Swift

Retain cycles is a very interesting topic.

What picked my brain about retain cycles in Swift though is the actual absence of the warning you get when capturing self strongly inside of a block unlike when writing purely in Objective-C. Let me demonstrate what I am talking about. Let’s assume we are building a simple calculator app that only supports 4 mathematical operations: add, subtract, multiply, and divide. Let’s also assume that in place of a regular method, we will write a block that will perform the calculation for specified operation and set the text of the UILabel to the resulting value.

First of all, let’s declare an enum to keep track of all supported operations:

Continue reading “Retain Cycles in Swift”

Retain Cycles in Swift