yelp-ios icon indicating copy to clipboard operation
yelp-ios copied to clipboard

Annotate designated and unavailable initializers

Open SSheldon opened this issue 9 years ago • 1 comments

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 avatar Apr 24 '16 16:04 SSheldon

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.

SSheldon avatar May 13 '16 17:05 SSheldon