• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSURL from non-url NSString
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: NSURL from non-url NSString
      • From: Jens Alfke <email@hidden>
    • Re: NSURL from non-url NSString
      • From: Mike Abdullah <email@hidden>
    • Re: NSURL from non-url NSString
      • From: Ken Thomases <email@hidden>
    • Re: NSURL from non-url NSString
      • From: Uli Kusterer <email@hidden>
  • Prev by Date: Re: Understanding ARC
  • Next by Date: Re: NSURL from non-url NSString
  • Previous by thread: Re: string literals and performance
  • Next by thread: Re: NSURL from non-url NSString
  • Index(es):
    • Date
    • Thread