-
Notifications
You must be signed in to change notification settings - Fork 318
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Minimize NSObject inheritance #2294
Comments
I think there are some problems with following classes.
I couldn't find mapbox-navigation-ios/MapboxNavigation/CarPlaySearchController+ CPSearchTemplateDelegate.swift Line 8 in 134af22
|
If I understood the suggested change,
But what if there will be more than 1 observer needed? What if user wants to observe any other property? |
Ah, good point. That’s a legitimate reason to inherit from NSObject.
That was a typo; I meant CarPlaySearchController. But you’re right, CPSearchTemplateDelegate forces NSObjectProtocol conformance here too.
Do we want developers to be able to observe RouteProgress model changes directly, or should they observe |
Disabling KVO for mapbox-navigation-ios/MapboxNavigation/RouteVoiceController.swift Lines 122 to 126 in 134af22
mapbox-navigation-ios/MapboxNavigation/MapboxVoiceController.swift Lines 52 to 65 in 134af22
This change will conflict with #2268 PR. |
As a followup to #2230, we should minimize the number of classes that explicitly inherit from NSObject. NSObject inheritance hinders Codable adoption and potentially has other subtle side effects.
The following classes look like good candidates for becoming ordinary Swift classes, though we’ll need to make sure there isn’t any KVO lurking around. Not listed here are any classes that need to conform to NSObjectProtocol because of some Foundation protocol inheritance such as CLLocationManagerDelegate.
RouteProgress, RouteLegProgress, and RouteStepProgress
Multi-leg routing fix #2229 registered key-value observers on these classes. Clients can set indices directly and a third object, RouteController, needs to update in response to the change. Though Foundation’s Progress class also inherits from NSObject, it solves this problem by allowing an object to register blocks to handle specific changes. It’s basically a hard-coded subset of KVO, more structured than the delegate pattern. Removing NSObject usage here will unblock codability: Route progress classes should be codable #1940.
NavigationSettings
This class also uses KVO, but I think only it registers on its own key paths, for the purpose of sending out notifications. Given the manageable number of properties and outstanding reflection mysteries like is not key value coding-compliant for the key #2262, we should replace this mechanism with a series of
didSet
s that call a common method.MapboxNavigationService
NavigationOptions
NavigationEventsManager: Cleanup of Deprecated / Obsoleted Symbols #2297
EndOfRouteFeedback
FeedbackItem
CarPlaySearchManager
StyleManager
DataCache
/cc @mapbox/navigation-ios
The text was updated successfully, but these errors were encountered: