Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <pre><code>NSString* urlStr = @"https://developer.apple.com/library/ios/#/legacy/library/documentation/Xcode/Conceptual/ios_development_workflow/10-Configuring_Development_and_Distribution_Assets/identities_and_devices.html#//apple_ref/doc/uid/TP40007959-CH4-SW"; urlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; NSURL* url = [NSURL URLWithString:urlStr]; </code></pre> <p>After using encoding ,the "#" is replaced by "%23".</p> </blockquote> <p>Well, yeah. That's what you told it to do.</p> <p>If you don't want that, then don't do that.</p> <blockquote> <p>If you don't use encoding, the NSURL will be nil.</p> </blockquote> <p>That's because there are two #s, so your URL is invalid. It makes sense for even NSURL (which is VERY permissive about dodgy URLs) to reject it.</p> <p>Take out the first, and only the first, #:</p> <pre><code>urlStr = [urlStr stringByReplacingOccurrencesOfString:@"/#" withString:@""]; </code></pre> <p>(That approach is a bit fragile; you could make it more robust by <a href="http://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html#//apple_ref/occ/instm/NSString/rangeOfString%3a" rel="nofollow">finding the range of the first match</a> and then <a href="http://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html#//apple_ref/occ/instm/NSString/stringByReplacingOccurrencesOfString%3awithString%3aoptions%3arange%3a" rel="nofollow">only replacing within that range</a>.)</p> <p>Now your URL is valid, so NSURL will have no problem with it.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload