This is a longstanding bug, but it looks like we don't have a JIRA bug for it. Inside Apple it's <rdar://problem/15233922> "Cannot assign to a property through AnyObject", and it's very similar to SR-5475 (which is about optional properties of protocols). I don't think we have a good workaround other than defining a little static inline function in Objective-C that will do the call for you without trying to check anything.
An alternate approach in this specific case would be to file a bug against Apple that the sender here is not an instance of NSOpenPanel or at least NSSavePanel.
Any suggestions for … getting a reference to the Panel?
By way of workarounds, it seems like the PanelController class is intended to control a panel. In that case I’d store a reference to that panel in an instance property. That way my delegate could access it directly, rather than go through the sender parameter.
Ok, that does work and is probably the best workaround:
if sender as AnyObject === myOpenPanel as AnyObject {
myOpenPanel?.directoryURL = URL(fileURLWithPath: "/")
}
Now I find that setting the directoryURL does not seem to work within the Sandbox! Ugh. I guess there is then no way to limit the OpenPanel to a single directory.
I guess there is then no way to limit the OpenPanel to a single
directory.
Alas, I don’t know the answer to that one off the top of my head. You could ask over on DevForums to see if anyone’s done that before. If that doesn’t work out, you should open a DTS tech support incident and speak to our App Sandbox expert.