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

When capturing self as weak, remove ? #26

Closed
angelolloqui opened this issue Oct 19, 2017 · 1 comment
Closed

When capturing self as weak, remove ? #26

angelolloqui opened this issue Oct 19, 2017 · 1 comment
Labels

Comments

@angelolloqui
Copy link
Owner

In Swift, it is common in lambdas to capture self in weak mode and use self? inside the lambda body.

In Kotlin, due to GC, this is unnecesary and the ? must be removed.

Example:

func changePhoto(picture: Data) {
    userService.updateUser(picture: picture).always { [weak self] in
        self?.hasPhoto = true
    }
}

Translates to:

fun changePhoto(picture: Data) {
    userService.updateUser(picture = picture).always {  
        this?.hasPhoto = true
    }
}

But must be

fun changePhoto(picture: Data) {
    userService.updateUser(picture = picture).always {  
        this.hasPhoto = true
    }
}
@angelolloqui
Copy link
Owner Author

Fixed with b2fa60f

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

No branches or pull requests

1 participant