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

Remove reference to functions as selections #32

Merged
merged 3 commits into from
Aug 21, 2015

Conversation

eliperkins
Copy link
Contributor

This was causing memory leaks as the closure referenced self, without declaring it's ownership of self.
From the Swift docs: "A strong reference cycle can also occur if you assign a closure to a property of a
class instance, and the body of that closure captures the instance...[this] strong reference cycle occurs
because closures, like classes, are reference types"

By adding the [unowned self] to each selection, we remove any retain cycles.

@eliperkins eliperkins force-pushed the ep/remove-memory-leaks-in-example branch from d7d0ad2 to 584cb2f Compare August 20, 2015 21:11
], footer: "This is a section footer."),
Section(header: "Accessories", rows: [
Row(text: "None"),
Row(text: "Disclosure Indicator", accessory: .DisclosureIndicator),
Row(text: "Detail Disclosure Button", accessory: .DetailDisclosureButton(detailDisclosureButtonSelected)),
Row(text: "Detail Disclosure Button", accessory: .DetailDisclosureButton({
[unowned self] in
Copy link
Contributor

Choose a reason for hiding this comment

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

We put this line on the same line as the opening brace in our app. I don’t really mind whichever way, but we should be consistent ✨

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed!

This was causing memory leaks as the closure referenced self, without declaring it's ownership of self.
From the Swift docs: "A strong reference cycle can also occur if you assign a closure to a property of a
class instance, and the body of that closure captures the instance...[this] strong reference cycle occurs
because closures, like classes, are reference types"

By adding the [unowned self] to each selection, we remove any retain cycles.
@eliperkins eliperkins force-pushed the ep/remove-memory-leaks-in-example branch from 584cb2f to c67a77f Compare August 20, 2015 21:15
@ayanonagon
Copy link
Contributor

Yay! Thanks for this, and the reference to the Swift docs.

Wanna update the README too so other people don’t run into the same issues that we did? :D

@ayanonagon
Copy link
Contributor

🍏

@eliperkins
Copy link
Contributor Author

@ayanonagon Is there something specific in the README that you think should get updated?

@ayanonagon
Copy link
Contributor

Section(header: "Money", rows: [
    Row(text: "Balance", detailText: "$12.00", accessory: .DisclosureIndicator, selection: {
        // Show statement
    }),
    Row(text: "Transfer to Bank…", cellClass: ButtonCell.self, selection: {
        // Show transfer to bank modal
    })
], footer: "Transfers usually arrive within 1-3 business days.")

I guess that doesn’t reference self but might be nice to show an example of it.

@eliperkins
Copy link
Contributor Author

@ayanonagon How's that? 812f8d3

@hyperspacemark
Copy link
Contributor

It's minor but would you mind putting that example of presenting a view controller in the transfer to bank row instead?

@eliperkins
Copy link
Contributor Author

@hyperspacemark done.

@ayanonagon
Copy link
Contributor

🍏

ayanonagon added a commit that referenced this pull request Aug 21, 2015
Remove reference to functions as selections
@ayanonagon ayanonagon merged commit 3eb875a into master Aug 21, 2015
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.

3 participants