NSPathControl problem...

I have set up a window, that I’m using as a custom sheet, to locate 3 files at one time (as opposed to the “death-by-dialog” method).

Once the files are selected, they are validated to make sure they are the correct files ← that is working fine.

If one (or more) file(s) are not correct, I want to re-display the window (as a sheet) with the NSPathControl(s) for incorrectly selected file(s) reset to the default path ← this is NOT working.

pathToFiles: “NSPathCell://localhost/Users/bradbumgarner/Desktop/NFL%20Stats”

tell current application's NSURL to set theURL to initFileURLWithPath_(pathToStats)

result:
2012-11-10 11:12:14.231 NFL Spreads Generator 3.0[16887:1307] +[NSURL initFileURLWithPath:]: unrecognized selector sent to class 0x7fff7bd0e0b8
2012-11-10 11:12:14.242 NFL Spreads Generator 3.0[16887:1307] *** -[NFL_Spreads_Generator_3_0AppDelegate statsLocated:]: +[NSURL initFileURLWithPath:]: unrecognized selector sent to class 0x7fff7bd0e0b8 (error -10000)

I got the pathToFiles string by logging the NSPathControl before any files were selected. I understand that pathToFiles is a string but I can’t figure out how to convert it back to a NSURL object. I have read through the documentation using AppKiDo and have tried using initFileURLWithPath:isDirectory:, initWithString: and a couple of others but I always get the same result.

Thanks in Advance,
Brad Bumgarner

Model: Macbook (mid 2010)
Browser: Safari 7536.25
Operating System: Mac OS X (10.7)

Hi,

you are using an (instance) init method, which requires a preceding alloc message.
Use the class method fileURLWithPath() instead

tell current application's |NSURL| to set theURL to fileURLWithPath_(pathToStats)

Note: on my machine I have to pipe NSURL

Thanks Stefan,

Although I understand the difference between class and instance putting them into practice is still, apparently, filled with potholes. :lol:

The init class methods are convenience initializers which return an autoreleased instance of the class

NSURL *theURL1 = [[[NSURL alloc] initFileURLWithPath:@"/Users"] autorelease];
NSURL *theURL2 = [NSURL fileURLWithPath:@"/Users"];

are synonyms

Brad,

It’s really not that hard – if the method name starts with init, then you always need to precede it with an alloc.

If it doesn’t then you don’t. Most of the convenience method names start with the name of the thing you’re trying to create, like fileURLWithPath: (creates a file URL), or arrayWithObjects: (creates an array), or stringWithFormat: (creates a string).

Ric