evgenyneu / Cosmos

A star rating control for iOS/tvOS written in Swift
MIT License
2.19k stars 368 forks source link

didTouchCosmos closure can capture self #6

Closed agordeev closed 8 years ago

agordeev commented 9 years ago

I'd be safer to change this

cosmosView.didTouchCosmos = { rating in }

to this

cosmosView.didTouchCosmos = { [unowned self] rating in }

in case if we'd use this code within view controller. Otherwise didTouchCosmos closure captures a reference to self and retain cycle is created.

evgenyneu commented 9 years ago

Hi, yes, I agree, which part of code are you referring to?

agordeev commented 9 years ago

README

evgenyneu commented 9 years ago

I would not put the capture list to this example in the readme, which currently is:

// Receive user input
cosmosView.didTouchCosmos = { rating in }

In my opinion, putting capture list will make the example a little bit complicated and move the focus away from its main purpose. Remember, we are not teaching people Swift language here, but rather explaining how to use the library. Note that in some situation people will not need to use capture list at all, or they will need to use [weak self] instead of [unowned self]. Explaining all those nuances in this readme is a bit out of the scope of this document and could be distractive. Thank you for your feedback.