Is there any API or good function to format strings like "www.example.com" or just "example.com" to valid urlstrings like "http://www.example.com"?
+ (NSString*)complete:(NSString *)urlString
{
NSArray * urlParts = [urlString componentsSeparatedByString:@"."];
if(urlParts.count==3)
return [NSString stringWithFormat:@"http://www.%@.%@",[urlParts objectAtIndex:1],[urlParts objectAtIndex:2]];
else if(urlParts.count==2)
return [NSString stringWithFormat:@"http://www.%@.%@",[urlParts objectAtIndex:0],[urlParts objectAtIndex:1]];
return nil;
}
this is what current solution looks like, but this doesn't look very good and solid to me.