initFileURLWithPath:
Initializes a newly created NSURL referencing the local file or directory at path.
- (id)initFileURLWithPath:(NSString *)path
Parameters of [NSURL initFileURLWithPath]
- path
- The path that the NSURL object will represent. path should be a valid system path. If pathbegins with a tilde, it must first be expanded with
stringByExpandingTildeInPath
. Ifpath
is a relative path, it is treated as being relative to the current working directory.Passingnil
for this parameter produces an exception.
Return Value
An NSURL object initialized with path.
Discussion of [NSURL initFileURLWithPath]
Invoking this method is equivalent to invoking
initWithScheme:host:path:
with schemeNSURLFileScheme
, a nil
host, and path.
This method examines path in the file system to determine if it is a directory. If path is a directory, then a trailing slash is appended. If the file does not exist, it is assumed that pathrepresents a directory and a trailing slash is appended. As an alternative, consider using
initFileURLWithPath :isDirectory:
which allows you to explicitly specify whether the returned NSURL represents a file or directory.
Example of [NSURL initFileURLWithPath]
NSString* targetFilePath = @"/Users/bob/Documents/About_Stacks.pdf";
NSURL* targetFileURL = [[NSURL alloc] initFileURLWithPath:targetFilePath];