I\'m trying to check if a given URL is valid and i\'m doing it like this:
- (BOOL)urlIsValid:(NSString *)address {
NSURL *testURL = [NSURL URLWithString:
In my experience, the NSURL creation routines usually throw an exception instead of returning nil. However, the real question in this case is what constitutes a malformed URL? Are you checking whether a resource exists, or checking whether the structure of the string conforms to the relevant RFCs?
With regards to the first issue I mentioned, when creating URLs that I don't manually enter myself I usually do this:
@try
{
NSURL * url = [NSURL URLWithString: theString];
// use the URL
}
@catch (NSException * e)
{
NSLog( @"URL creation error? %@ - %@", [e name], [e reason] );
@throw; // throw the exception again, to hopefully get your attention
}