That's the incredible thing: sender.pathItems.firstIndex(of: sender.clickedPathItem!) always returns nil, even if the clicked path item has the same address as the corresponding item in the path items array. Even sender.pathItems.firstIndex(where: { $0.description == sender.clickedPathItem!.description }) returns nil. And when executing that print statement more than once one after the other, each item always has a different address.
Not sure. I don't have time to test this thoroughly but try overriding the pathControlItems setter to see if you or the system are resetting the array unexpectedly. How are you creating each NSPathControlItem?
In any case as long as each NSPathControlItem URL is unique you can just hold whatever data you want to associate with each path item like so:
@property NSDictionary<NSURL*,Whatever*>*representedObjectsForPathURLs;
Then add a method on your path control subclass:
-(Whatever*)representedObjectForPathControlItem:(NSPathControlItem*)item
{
return [self.representedObjectsForPathURLs objectForKey:item.URL];
}
This assumes NSPathControlItem doesn't mangle your url strings after they are set.