SwiftLint
SwiftLint copied to clipboard
Rule Request: observable_object_main_actor
New Issue Checklist
- [x] Updated SwiftLint to the latest version
- [x] I searched for existing GitHub issues
New rule request
- Why should this rule be added? Share links to existing discussion about what the community thinks about this.
From many WWDC21 talks around SwiftUI & async/await, a common practice was ensuring that an ObservableObject
was run on the main actor by marking the class with @MainActor
- https://developer.apple.com/videos/play/wwdc2021/10019/
- Provide several examples of what would and wouldn't trigger violations.
Good
@MainActor
class ViewModel: ObservableObject {
//...
}
@MainActor
class SomeOtherThing {
//...
}
Bad
class ViewModel: ObservableObject {
//...
}
- Should the rule be configurable, if so what parameters should be configurable?
nothing at this time
- Should the rule be opt-in or enabled by default? Why? See README.md for guidelines on when to mark a rule as opt-in.
I think this rule should be opt in. async/await & actors are not yet fully supported on all iOS versions so lots of code would need to adapt for this rule to be useful.