Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make view property weak in ViewStateMachine to avoid retain cycle #58

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Ezor
Copy link

@Ezor Ezor commented Jul 18, 2017

Hi,

When using ViewStateMachine standalone like the following example, I experienced a retain cycle caused by the fact that ViewStateMachine hold a strong reference on the backed view.
Using a weak property fixed the problem.

class StateView: UIView {

    private var stateMachine: ViewStateMachine!
    private var loadingView: LoadingView!

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        setupStateMachine()
    }

    override init(frame: CGRect) {
        super.init(frame: CGRect.zero)
        setupStateMachine()
    }

    private func setupStateMachine() {
        stateMachine = ViewStateMachine(view: self) // retain cycle
        loadingView = LoadingView(frame: self.bounds)
        stateMachine["loading"] = loadingView
    }

    func startLoading(_ message: String) {
        loadingView.label.text = message
        stateMachine.transitionToState(.view("loading"), animated: false, completion: nil)
    }

    ....
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant