Model
extension MyEntity {
@nonobjc public class func fetchRequest() -> NSFetchRequest< MyEntity > {
return NSFetchRequest< MyEntity >(entityName: "MyEntity")
}
@NSManaged public var customFields: NSDictionary?
}
customFields keys and values are Strings.
Bindings
Columns are created in code since the user can add/remove columns.
column.bind(NSBindingName.value, to: treeController!, withKeyPath: "arrangedObjects.customFields.\(uniqueID))", options: [.createsSortDescriptor:false])
column.sortDescriptorPrototype = NSSortDescriptor(key: "customFields.\(uniqueID))", ascending: true, selector: #selector(NSString.compare(_:)))
Issue
Sorting will not work when clicking on column header. Values are simply String, but it seems they are not considered as such. Any idea of where the problem might be? Thanks!
UPDATE
- The
NSTreeController
is in Entity mode - This is a view-based outline view (is the cell-based still used nowadays??)
- For static columns (defined in IB), sorting works
- When I sort on dynamic columns, nothing happens (no error)
- I suppose that the values are not considered as string because it is a NSDictionary that does not use generics
UPDATE 2
On another project, I successfully managed to do so.
The only difference is that the dictionary is not , but where MyObject
has a value
property of type String
.
The sorting is enabled using the following code:
/* Bind column for sorting */
column.bind(NSBindingName.value, to: resultsArrayController!, withKeyPath: "arrangedObjects.dictionary.\(String(describing: paramDef.objectID)).value", options: nil)
or this works as well:
column.sortDescriptorPrototype = NSSortDescriptor(key: "dictionary.\(String(describing: paramDef.objectID)).value", ascending: true, selector: #selector(NSString.compare(_:)))
I do not know why it works in that case and not above.