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

Annotate designated and unavailable initializers #31

Open
SSheldon opened this issue Apr 24, 2016 · 1 comment
Open

Annotate designated and unavailable initializers #31

SSheldon opened this issue Apr 24, 2016 · 1 comment

Comments

@SSheldon
Copy link
Member

Currently, we don't annotate any initializers with NS_DESIGNATED_INITIALIZER or NS_UNAVAILABLE. This means that any of our objects can be constructed with plain init, breaking our invariants. This is especially bad in Swift, where if a nonnull property is uninitialized it can lead to undefined behavior.

For example, here's autocomplete recommending to me that I can construct a YLPClient without any tokens:
screen shot 2016-04-24 at 9 02 45 am

@SSheldon
Copy link
Member Author

Here's an example of undefined behavior we can invoke currently:

let biz = YLPBusiness()
if Optional.Some(biz.URL) == nil {
  print("uh oh")
}

This prints "uh oh", because we're making an Optional from the Some case, and yet the result is 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

No branches or pull requests

1 participant