NSURL from non-url NSString
NSURL from non-url NSString
- Subject: NSURL from non-url NSString
- From: Koen van der Drift <email@hidden>
- Date: Sun, 25 May 2014 11:05:31 -0400
Hi,
At one point in my code I need to recognize an URL to show in a different color. Pretty standard:
NSURL *url = [NSURL URLWithString: aString];
if (url) // if url is created change color
{
NSAttributedString *linkString = [[NSAttributedString alloc] initWithString: aString
attributes: @{NSForegroundColorAttributeName: [UIColor blueColor]}];
...etc
}
Works great, if aString starts with eg http:// it will be in blue; regular strings won't.
However, I noticed that strings that have the form P12345 also turn blue. Any idea why that string would turn into an NSURL? The url scheme is nil, and the path components just show P12345.
(I could test above for if (url.scheme) to avoid this, but knowing why this happens would actually help me with other parts in my app).
Thanks,
- Koen.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden