|
|
|
|
|
by dep_b
2821 days ago
|
|
True, I think Crashlytics still doesn't work very well for logging unusual but not crashing program situations. I would like to have an elegant solution for that. I always throw assertionErrors in case something weird happens handling an optional. However if you adopt different patterns with Swift you can exclude a lot of optionals, for example if you give every View a State enum with associated values you can avoid quite a lot of optionals: class PersonView: UIView {
enum State {
case empty
case loading(personId: String)
case loaded(person: Person)
}
var state: State = .empty {
didSet {
switch state {
/* handle all different states */
}
}
}
}
Every time you switch state you need to give the right associated value and every time you are in this state this value is guaranteed to be there where before you would have an optional personId and an optional person.And it's applicable almost everywhere. I barely use optionals anymore unless I really can't replace them with an emum. |
|
Have you tried
I use it to log errors on API calls in my projects. It comes in handy when I'm using third-party services and they decide to break something on their end.