Tuesday, April 30, 2013

NSURL fileURLWithPath isDirectory example ios


fileURLWithPath :isDirectory:

Initializes and returns a newly created NSURL object as a file URL with a specified path.
+ (id)fileURLWithPath:(NSString *)path isDirectory:(BOOL)isDir
Parameters
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. If pathis a relative path, it is treated as being relative to the current working directory.[NSURL fileURLWithPath]
Passing nil for this parameter produces an exception.
isDir
A Boolean value that specifies whether path is treated as a directory path when resolving against relative path components. Pass YES if the path indicates a directory, NO otherwise.
Return Value of [NSURL fileURLWithPath]
An NSURL object initialized with path.
Example of [NSURL fileURLWithPath]
[slWebView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"iHelp" ofType:@"htm"]isDirectory:NO]]];
Example of [NSURL fileURLWithPath]
NSURL *theURL = [NSURL fileURLWithPath:@"/Users/elisevanlooij/nonexistingfile.php" 
         isDirectory:NO];
NSError *err;
if ([theURL checkResourceIsReachableAndReturnError:&err] == NO)
    [[NSAlert alertWithError:err] runModal];