You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Optional style properties treat nil as a function #6095
On iOS and macOS, properties on MGLStyleLayer classes for optional attributes have somewhat unpredictable nullability. For example, the style specification defines the background-color property as being optional with a default value of #000000. If I create an MGLBackgroundStyleLayer and immediately add it to an MGLStyle, the backgroundColor property is nil rather than the default value of +[UIColor blackColor]:
(lldb) po layer.backgroundColor
nil
That’s fine; perhaps I could consider the property to be nullable with an implicit default value. But if I set the property to be nil, it ends up as a function with no stops:
(lldb) po layer.backgroundColor = [UIColor redColor]
UIExtendedSRGBColorSpace 1 0 0 1
(lldb) po layer.backgroundColor = nil
nil
(lldb) po layer.backgroundColor
<MGLStyleAttributeFunction: 0x7fdc23c09e90, base = 0; stops = {
}>
To be sure, setting the property to a non-nil constant value does give the expected result:
(lldb) po layer.backgroundColor = [UIColor redColor]
UIExtendedSRGBColorSpace 1 0 0 1
(lldb) po layer.backgroundColor
UIExtendedSRGBColorSpace 1 0 0 1
The SDK should intercept a stop-less function and return nil instead.
Better yet, mbgl::style::Layer should have a formal concept of a default value so that we can implement the null_resettable semantics in the SDK. That is, an optional property should never return nil (instead returning the default value), but you can set the property to nil in order to revert it to the default value.
Better yet, mbgl::style::Layer should have a formal concept of a default value so that we can implement the null_resettable semantics in the SDK. That is, an optional property should never return nil (instead returning the default value), but you can set the property to nil in order to revert it to the default value.
With these semantics, how would you distinguish a default-valued property from a property whose value happens to be set to the same value as the default?
With these semantics, how would you distinguish a default-valued property from a property whose value happens to be set to the same value as the default?
That’s a good question. Is it important to be able to distinguish between these two cases at the SDK level? If so, then we should keep the properties nullable but fix the issue where the setting to nil creates a no-op function. If not, then null_resettable would allow us to eliminate the concept of an “implicit default”, which is even less common in Objective-C APIs than null_resettable.
I don't know how important it is at the SDK level, but I think it's a distinction we should preserve at the core level; I don't think we should change the behavior of existing mbgl::style::Layer accessors. Instead we could add methods to obtain property default values.
Split out #6117 to track accessors for property default values. Meanwhile, this ticket tracks the bug that you can’t get a property back to nil (undefined).
Per #7249 (comment), this was the stopless functions were likely an SDK-level issue. The code for converting an mbgl::style::PropertyValue into an MGLStyleValue has been rewritten twice since I reported this issue, and the observed symptoms are long gone.
Activity
[ios, macos] Optional properties are nullable
jfirebaugh commentedon Aug 22, 2016
With these semantics, how would you distinguish a default-valued property from a property whose value happens to be set to the same value as the default?
1ec5 commentedon Aug 22, 2016
That’s a good question. Is it important to be able to distinguish between these two cases at the SDK level? If so, then we should keep the properties
nullablebut fix the issue where the setting tonilcreates a no-op function. If not, thennull_resettablewould allow us to eliminate the concept of an “implicit default”, which is even less common in Objective-C APIs thannull_resettable.jfirebaugh commentedon Aug 22, 2016
I don't know how important it is at the SDK level, but I think it's a distinction we should preserve at the core level; I don't think we should change the behavior of existing
mbgl::style::Layeraccessors. Instead we could add methods to obtain property default values.1ec5 commentedon Aug 22, 2016
Split out #6117 to track accessors for property default values. Meanwhile, this ticket tracks the bug that you can’t get a property back to
nil(undefined).1ec5 commentedon Aug 23, 2016
null_resettablesemantics are being tracked in #6126.1ec5 commentedon Dec 1, 2016
Per #7249 (comment), this was the stopless functions were likely an SDK-level issue. The code for converting an
mbgl::style::PropertyValueinto an MGLStyleValue has been rewritten twice since I reported this issue, and the observed symptoms are long gone.