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

Break retain cycle with Action.unsafeCocoaAction #2910

Merged
merged 3 commits into from
May 19, 2016

Conversation

mdiep
Copy link
Contributor

@mdiep mdiep commented May 18, 2016

Fixes #2233.

public var unsafeCocoaAction: CocoaAction {
return associatedObject(self, key: &unsafeCocoaActionKey, initial: { host in
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private var unsafeCocoaActionKey should be removed as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -176,12 +177,15 @@ class ActionSpec: QuickSpec {
let result = action.apply(0).first()
expect(result?.value) == 1
expect(values).toEventually(equal([ true, false, true ]))

_ = cocoaAction
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, what is this assignation here for ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's to keep cocoaAction from deallocating before the end of the test—because when it deallocates, the producer will complete.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, thanks!

@ikesyo
Copy link
Member

ikesyo commented May 19, 2016

👍

@ikesyo ikesyo merged commit b5232e3 into master May 19, 2016
@ikesyo ikesyo deleted the unsafe-cocoa-action-retain-cycle branch May 19, 2016 13:08
@kaybutter
Copy link
Contributor

kaybutter commented Jun 12, 2016

This kind of change should not be hidden behind a simple "fixed retain cycle" in the release notes.

While this code works fine in RAC 4.1, it compiles and fails silently in RAC 4.2:

someButton.addTarget(someAction.unsafeCocoaAction, action: CocoaAction.selector)

I feel like this change kind of defeats the purpose of having unsafeCocoaAction in the first place. Is there a better pattern to be used in this instance?

@mdiep
Copy link
Contributor Author

mdiep commented Jun 14, 2016

Sorry for the inconvenience! Let's move this discussion to #2983.

I'll try to comment there soon, but it may to happen this week because of WWDC.

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

4 participants