The NSURL class is a subclass of the NSObject class and it provides methods for creating and manipulating URL addresses. URL stands for “Universal Resource Locator”. Here are few things you should know about the NSURL class:
- It is the only class spelt with all upper case.
- an NSURL object is not a string object such as @"http:/www.theapplady.net"
- There are many methods in the Foundation Framework that take an NSURL object as an argument.
Common NSURL Methods
The NSURL class contain several methods for manipulating NSURL objects. In this section I show how to use three of them.
The URLWithString: Method
This method creates and returns an NSUL object. The argument passed to the method must be an NSString which is a valid website address.
The fileURLWithPath: Method
This method is used for creating and returning an NSURL object as a file URL. The required argument passed to the method is a valid path to a file.
Code | Output | ||
---|---|---|---|
|
![]() |
The requestWithURL: Method
This method creates and returns an URL request object, which you can display in a UIWebView control, as demonstrated below.
Code | Output | ||
---|---|---|---|
|
![]() |