On Jan 8, 2015, at 11:09 PM, Steve Mills <sjmi...@mac.com> wrote:
> 
> Thanks Graham and Kyle. So since I now need to take control of securing the 
> url chosen in the path control, I can no longer just bind its value to user 
> defaults in the xib, right? I've added an action method that gets called when 
> the path changes, where I create a secure bookmark and store that in user 
> defaults instead.
> 
> Then in awakeFromNib (for when the app launches and the window is created), I 
> get the bookmark out of user defaults, resolve it securely to the url, and 
> set the path control's url to that. Sound good so far?

This sounds basically good. I’d suggest looking into overriding 
-[NSWindowController windowDidLoad] rather than using -awakeFromNib. 
Conceptually, the stored path is controller-level state, and thus should be 
pushed from the controller the view rather than retrieved directly by the view 
layer. Since you’re using bindings, you would be well-advised to already be 
using a subclass of NSWindowController to manage your window, since that 
superclass breaks retain cycles that Cocoa Bindings can cause.

> 
> Now I think I'm left with being granted access to that url. It's easy enough 
> to do that in awakeFromNib right before I use the url to set the path 
> control's url. But I'll need to keep access to it for the entire run of the 
> app or until the user chooses a different folder. At what point would you 
> suggest I call stopAccessingSecurityScopedResource on it? I'd need to do it 
> before the user chooses a new folder, but before the NSPathControl sets its 
> url, otherwise I'll lose any references to the url I've been granted access 
> to use.

There is no need to call -startAccessingSecurityScopedResource until you need 
to actually read from the file. As long as you have successfully created an 
NSURL from the bookmark data, you have access rights to the resource pointed to 
by that bookmark.

As per the documentation, your calls to -start/stopAccessing should be as 
tightly scoped as possible, so it would be inadvisable to call -startAccessing 
in -awakeFromNib. If NSPathControl needs to read the resource to determine, 
say, what icon to provide in a path segment, it will call 
-startAccesingSecurityScopedResource on its own.

--Kyle Sluder
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to