Foundation has two classes that facilitate working with
NSURL represents a
Uniform Resource Locator (URL). This class lets applications create,
manipulate, and pick apart URLs.
accesses data and resources specified by an instance of
NSURL. This class can access resources provided by
HTTP, FTP, and
represents a URL—the human-readable
host names and paths that various network clients use to locate
resources on the local filesystem or over the Internet.
NSURL provides a number of methods and
initializers that let you create instances in many different ways, as
shown in Example 6-2.
Core Foundation has a type,
CFURL, that is
“toll-free bridged” to
NSURL. As such, the two types can be used
NSURL are essentially equivalent:
NSURL objects can be used in Core Foundation calls
that ask for a
CFURL, and vice versa.
NSURL is just one of several Foundation classes
that have a bridged Core Foundation equivalent.
Example 6-2. Creating and initializing instances of NSURL
// From a string...NSURL *url = [NSURL URLWithString:@"http//www.macdevcenter.com"]; url = [[NSURL alloc] initWithString: :@"http//www.macdevcenter.com"];
// From a file path...url = [NSURL fileURLWithPath:@"/Users/mike/Pictures/pic.tiff"]; url = [[NSURL alloc] initFileURLWithPath: :@"/Users/mike/Pictures/pic.tiff"];
// Access a URL with scheme, host, and pathurl = [[NSURL alloc] initWithScheme:@" ...