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
Tested in Apple Swift version 4.2 (swiftlang-1000.11.37.1 clang-1000.11.45.1)
Confirmed by inspecting the source of the latest Swift master (14d4235b571d7a4e2ae51854f0d665f96959d182)
The NSSortDescriptor extension for working with KeyPath values is quite broken. The computed keyPath property relies on converting the String back into an AnyKeyPath by using a global table that is populated when converting the KeyPath into a String in the first place. The problem is, the String can't include the root type, so two different KeyPath values that have the same Obj-C keypath string will overwrite each other, and cause the NSSortDescriptor.keyPath property to return the wrong value.
Besides equality, this also affects the behavior of the AnyKeyPath.appending(path:) method.
Personally, I think we should just do away with the keyPath property entirely. Barring that, I believe the correct solution here is to use Obj-C associated objects to associate the original KeyPath value with the NSSortDescriptor and do away with the global table.
The text was updated successfully, but these errors were encountered:
Upon second look, this is not actually the only client of the global keypath table, it was simply the only client of the global _bridgeStringToKeyPath(_: String) function. Unfortunately, the global keypath table is still used in the implementation of automaticallyNotifiesObservers(for:), and it's not clear how to fix that. I will file a separate ticket for that.
Environment
Tested in Apple Swift version 4.2 (swiftlang-1000.11.37.1 clang-1000.11.45.1)
Confirmed by inspecting the source of the latest Swift master (14d4235b571d7a4e2ae51854f0d665f96959d182)
Additional Detail from JIRA
md5: 88ed436db4b4df7ee10944ba48007057
Issue Description:
The
NSSortDescriptor
extension for working withKeyPath
values is quite broken. The computedkeyPath
property relies on converting theString
back into anAnyKeyPath
by using a global table that is populated when converting theKeyPath
into aString
in the first place. The problem is, theString
can't include the root type, so two differentKeyPath
values that have the same Obj-C keypath string will overwrite each other, and cause theNSSortDescriptor.keyPath
property to return the wrong value.Example:
Besides equality, this also affects the behavior of the
AnyKeyPath.appending(path:)
method.Personally, I think we should just do away with the
keyPath
property entirely. Barring that, I believe the correct solution here is to use Obj-C associated objects to associate the originalKeyPath
value with theNSSortDescriptor
and do away with the global table.The text was updated successfully, but these errors were encountered: