# NSURL class reference

mguesdon@sbuilders.com
rfm@gnu.org
greg.casamento@gmail.com
1999 Free Software Foundation, Inc.
Software documentation for the NSURL class
Foundation/NSURL.h
NSCoding
NSCopying
NSURLHandleClient
This class permits manipulation of URLs and the resources to which they refer. They can be used to represent absolute URLs or relative URLs which are based upon an absolute URL. The relevant RFCs describing how a URL is formatted, and what is legal in a URL are - 1808, 1738, and 2396.
Handling of the underlying resources is carried out by NSURLHandle objects, but NSURL provides a simplified API wrapping these objects.
URLByResolvingAliasFileAtURL:
url
options:
options
error:
error
Description forthcoming.
URLWithString:
aUrlString
Create and return a URL with the supplied string, which should be a string (containing percent escape codes where necessary) conforming to the description (in RFC2396) of an absolute URL.
Calls -initWithString:
URLWithString:
aUrlString
relativeToURL:
aBaseUrl
Create and return a URL with the supplied string, which should be a string (containing percent escape codes where necessary) conforming to the description (in RFC2396) of a relative URL.
Calls -initWithString:relativeToURL:
fileURLWithPath:
aPath
Create and return a file URL with the supplied path.
The value of aPath must be a valid filesystem path.
Calls -initFileURLWithPath: which escapes characters in the path where necessary.
fileURLWithPath:
aPath
isDirectory:
isDir
Description forthcoming.
fileURLWithPathComponents:
components
Creates a file URL using a path built from components.
URLByAppendingPathComponent:
pathComponent
Returns a URL formed by adding a path component to the path of the receiver.
See [NSString -stringByAppendingPathComponent:].
URLByAppendingPathComponent:
pathComponent
isDirectory:
isDirectory
Returns a URL formed by adding a path component to the path of the receiver, along with a trailing slash if the component is designated a directory.
See [NSString -stringByAppendingPathComponent:].
URLByAppendingPathExtension:
pathExtension
Returns a URL formed by adding a path extension to the path of the receiver.
See [NSString -stringByAppendingPathExtension:].
URLByDeletingLastPathComponent
Returns a URL formed by removing a path component from the path of the receiver.
See [NSString -stringByDeletingLastPathComponent].
URLByDeletingPathExtension
Returns a URL formed by removing an extension from the path of the receiver.
See [NSString -stringByDeletingPathExtension].
URLByResolvingSymlinksInPath
Returns self unless the receiver is a file URL, in which case it returns a URL formed by calling [NSString -stringByResolvingSymlinksInPath].
URLByStandardizingPath
Returns self unless the receiver is a file URL, in which case it returns a URL formed by calling [NSString -stringByStandardizingPath].
URLHandleUsingCache:
shouldUseCache
Returns an NSURLHandle instance which may be used to write data to the resource represented by the receiver URL, or read data from it.
The shouldUseCache flag indicates whether a cached handle may be returned or a new one should be created.
absoluteString
Returns the full string describing the receiver resolved against its base.
absoluteURL
If the receiver is an absolute URL, returns self. Otherwise returns an absolute URL referring to the same resource as the receiver.
baseURL
If the receiver is a relative URL, returns its base URL.
Otherwise, returns `nil`.
checkResourceIsReachableAndReturnError:
error
Attempts to load from the specified URL and provides an error response if the data is unrachable.
Returns `YES` on success, `NO` on failure.
filePathURL
Description forthcoming.
fileReferenceURL
Description forthcoming.
fragment
Returns the fragment portion of the receiver or `nil` if there is no fragment supplied in the URL.
The fragment is everything in the original URL string after a '#'
File URLs do not have fragments.
getResourceValue:
value
forKey:
key
error:
error
Description forthcoming.
host
Returns the host portion of the receiver or `nil` if there is no host supplied in the URL.
Percent escape sequences in the user string are translated and the string treated as UTF8.
Returns IPv6 addresses without the enclosing square brackets required (by RFC2732) in URL strings.
initFileURLWithPath:
aPath
Initialise as a file URL with the specified path (which must be a valid path on the local filesystem).
Raises NSInvalidArgumentException if aPath is `nil`.
Converts relative paths to absolute ones.
Appends a trailing slash to the path when necessary if it specifies a directory.
Calls -initWithScheme:host:path:
initFileURLWithPath:
aPath
isDirectory:
isDir
Initialise as a file URL with the specified path (which must be a valid path on the local filesystem).
Raises NSInvalidArgumentException if aPath is `nil`.
Converts relative paths to absolute ones.
Appends a trailing slash to the path when necessary if it specifies a directory.
Calls -initWithScheme:host:path:
initWithScheme:
aScheme
host:
aHost
path:
aPath
Initialise by building a URL string from the supplied parameters and calling -initWithString:relativeToURL:
This method adds percent escapes to aPath if it contains characters which need escaping.
Accepts RFC2732 style IPv6 host addresses either with or without the enclosing square brackets (MacOS-X at least up to version 10.5 does not handle these correctly, but GNUstep does).
Permits the 'aHost' part to contain 'username:password@host:port' or 'host:port' in addition to a simple host name or address.
initWithString:
aUrlString
Initialise as an absolute URL.
Calls -initWithString:relativeToURL:
initWithString:
aUrlString
relativeToURL:
aBaseUrl
Initialised using aUrlString and aBaseUrl. The value of aBaseUrl may be `nil`, but aUrlString must be non-nil.
Accepts RFC2732 style IPv6 host addresses.
Parses a string wihthout a scheme as a simple path.
Parses an empty string as an empty path.
If the string cannot be parsed the method returns `nil`.
isFileReferenceURL
Description forthcoming.
isFileURL
Description forthcoming.
lastPathComponent
Returns the last (rightmost) path component of the receiver.
loadResourceDataNotifyingClient:
client
usingCache:
shouldUseCache
Loads resource data for the specified client.

If shouldUseCache is `YES` then an attempt will be made to locate a cached NSURLHandle to provide the resource data, otherwise a new handle will be created and cached.

If the handle does not have the data available, it will be asked to load the data in the background by calling its loadInBackground method.

The specified client (if non-nil) will be set up to receive notifications of the progress of the background load process.

The processes current run loop must be run in order for the background load operation to operate!

parameterString
Returns the parameter portion of the receiver or `nil` if there is no parameter supplied in the URL.
The parameters are everything in the original URL string after a ';' but before the query.
File URLs do not have parameters.
password
Returns the password portion of the receiver or `nil` if there is no password supplied in the URL.
Percent escape sequences in the user string are translated and the string treated as UTF8 in GNUstep but this appears to be broken in MacOS-X.
NB. because of its security implications it is recommended that you do not use URLs with users and passwords unless necessary.
path
Returns the path portion of the receiver.
Replaces percent escapes with unescaped values, interpreting non-ascii character sequences as UTF8.
NB. This does not conform strictly to the RFCs, in that it includes a leading slash ('/') character (whereas the path part of a URL strictly should not) and the interpretation of non-ascii character is (strictly speaking) undefined.
Also, this breaks strict conformance in that a URL of file scheme is treated as having a path (contrary to RFCs)
pathComponents
Returns thepath components of the receiver.
See [NSString -pathComponents] .
pathExtension
Returns the file extension (text after the rightmost dot in the path) of the receiver.
see [NSString -pathExtension] .
port
Returns the port portion of the receiver or `nil` if there is no port supplied in the URL.
Percent escape sequences in the user string are translated in GNUstep but this appears to be broken in MacOS-X.
propertyForKey:
propertyKey
Asks a URL handle to return the property for the specified key and returns the result.
query
Returns the query portion of the receiver or `nil` if there is no query supplied in the URL.
The query is everything in the original URL string after a '?' but before the fragment.
File URLs do not have queries.
relativePath
Returns the path of the receiver, without taking any base URL into account. If the receiver is an absolute URL, -relativePath is the same as -path .
Returns `nil` if there is no path specified for the URL.
relativeString
Returns the relative portion of the URL string. If the receiver is not a relative URL, this returns the same as absoluteString.
resourceDataUsingCache:
shouldUseCache
Loads the resource data for the represented URL and returns the result. The shouldUseCache flag determines whether data previously retrieved by an existing NSURLHandle can be used to provide the data, or if it should be refetched.
resourceSpecifier
Returns the resource specifier of the URL... the part which lies after the scheme.
scheme
Returns the scheme of the receiver.
setProperty:
property
forKey:
propertyKey
Calls [NSURLHandle -writeProperty:forKey:] to set the named property.
setResourceData:
data
Calls [NSURLHandle -writeData:] to write the specified data object to the resource identified by the receiver URL.
Returns the result.
standardizedURL
Returns a URL with '/./' and '/../' sequences resolved etc.
user
Returns the user portion of the receiver or `nil` if there is no user supplied in the URL.
Percent escape sequences in the user string are translated and the whole is treated as UTF8 data.
NB. because of its security implications it is recommended that you do not use URLs with users and passwords unless necessary.
Software documentation for the NSURLComponents class
Foundation/NSURL.h
NSCopying
Description forthcoming.
componentsWithString:
urlString
Description forthcoming.
componentsWithURL:
url
resolvingAgainstBaseURL:
resolve
Description forthcoming.
URL
Description forthcoming.
URLRelativeToURL:
baseURL
Description forthcoming.
fragment
Description forthcoming.
host
Description forthcoming.
init
Description forthcoming.
initWithString:
URLString
Description forthcoming.
initWithURL:
url
resolvingAgainstBaseURL:
resolve
Description forthcoming.
password
Description forthcoming.
path
Description forthcoming.
percentEncodedFragment
Description forthcoming.
percentEncodedHost
Description forthcoming.
percentEncodedPassword
Description forthcoming.
percentEncodedPath
Description forthcoming.
percentEncodedQuery
Description forthcoming.
percentEncodedQueryItems
Description forthcoming.
percentEncodedUser
Description forthcoming.
port
Description forthcoming.
query
Description forthcoming.
queryItems
Description forthcoming.
rangeOfFragment
Description forthcoming.
rangeOfHost
Description forthcoming.
rangeOfPassword
Description forthcoming.
rangeOfPath
Description forthcoming.
rangeOfPort
Description forthcoming.
rangeOfQuery
Description forthcoming.
rangeOfScheme
Description forthcoming.
rangeOfUser
Description forthcoming.
scheme
Description forthcoming.
setFragment:
fragment
Description forthcoming.
setHost:
host
Description forthcoming.
setPassword:
password
Description forthcoming.
setPath:
path
Description forthcoming.
setPercentEncodedFragment:
fragment
Description forthcoming.
setPercentEncodedHost:
host
Description forthcoming.
setPercentEncodedPassword:
password
Description forthcoming.
setPercentEncodedPath:
path
Description forthcoming.
setPercentEncodedQuery:
query
Description forthcoming.
setPercentEncodedQueryItems:
queryItems
Description forthcoming.
setPercentEncodedUser:
user
Description forthcoming.
setPort:
port
Description forthcoming.
setQuery:
query
Description forthcoming.
setQueryItems:
queryItems
Description forthcoming.
setScheme:
scheme
Description forthcoming.
setString:
urlString
Description forthcoming.
setURL:
url
Description forthcoming.
setUser:
user
Description forthcoming.
string
Description forthcoming.
user
Description forthcoming.
Software documentation for the NSURLQueryItem class
Foundation/NSURL.h
NSCopying
NSCoding
Description forthcoming.
queryItemWithName:
name
value:
value
Description forthcoming.
initWithName:
name
value:
value
Description forthcoming.
name
Description forthcoming.
value
Description forthcoming.
Software documentation for the NSObject(NSURLClient) category
Foundation/NSURL.h
An informal protocol to which clients may conform if they wish to be notified of the progress in loading a URL for them. NSURL conforms to this protocol but all methods are implemented as no-ops. See also the <NSURLHandleClient> protocol.
URL:
sender
resourceDataDidBecomeAvailable:
newBytes
Some data has become available. Note that this does not mean that all data has become available, only that a chunk of data has arrived.
URL:
sender
resourceDidFailLoadingWithReason:
reason
Loading of resource data has failed, for given human-readable reason.
URLResourceDidCancelLoading:
sender
Loading of resource data was cancelled by programmatic request (not an error).
URLResourceDidFinishLoading:
sender
Loading of resource data is complete.