Looks like -stringByDeletingLastPathComponent is not supposed to be used with url strings. The method would replaced double slashes with the single slash and -stringByAppendingPathComponent: seem to be doing the same.
I have created NSString category with these two methods to solve my immediate problem but now I'm curious if there is a better way to handle url addresses? Any suggestions?
I have created NSString category with these two methods to solve my immediate problem but now I'm curious if there is a better way to handle url addresses? Any suggestions?
Code:
- (NSString *)stringByDeletingLastPathOrURLComponent
{
NSString *tmpString = [self stringByDeletingLastPathComponent];
if (![tmpString hasPrefix:@"http://"] && [tmpString hasPrefix:@"http:/"])
tmpString = [tmpString stringByReplacingOccurrencesOfString:@"http:/" withString:@"http://"];
return (tmpString);
}
- (NSString *)stringByAppendingPathOrURLComponent:(NSString *)str
{
NSString *tmpString = [self stringByAppendingPathComponent:str];
if (![tmpString hasPrefix:@"http://"] && [tmpString hasPrefix:@"http:/"])
tmpString = [tmpString stringByReplacingOccurrencesOfString:@"http:/" withString:@"http://"];
return (tmpString);
}