Skip to content

Calling methods in initializers #78

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

Open
vihanb opened this issue Sep 21, 2018 · 0 comments
Open

Calling methods in initializers #78

vihanb opened this issue Sep 21, 2018 · 0 comments

Comments

@vihanb
Copy link
Member

vihanb commented Sep 21, 2018

Initializers should not be able to call methods on self until after the fields have been initialized:

class A {
    let a: Int
    let b: Int

    init() {
        f(); // OK
        self.a = 1
        self.foo() // Error
        self.b = 2
        self.foo() // OK
    }

    func foo() { ... }
}
@vihanb vihanb changed the title Calling self functions in initializers Calling methods in initializers Sep 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant