SwiftLint icon indicating copy to clipboard operation
SwiftLint copied to clipboard

Rule Request: observable_object_main_actor

Open 72A12F4E opened this issue 3 years ago • 0 comments

New Issue Checklist

New rule request

  1. 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/
  1. Provide several examples of what would and wouldn't trigger violations.

Good

@MainActor
class ViewModel: ObservableObject {
    //...
}
@MainActor
class SomeOtherThing {
    //...
}

Bad

class ViewModel: ObservableObject {
    //...
}
  1. Should the rule be configurable, if so what parameters should be configurable?

nothing at this time

  1. 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.

72A12F4E avatar Jun 11 '21 15:06 72A12F4E