yelp-ios
yelp-ios copied to clipboard
Annotate designated and unavailable initializers
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:

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.