sl0000
V2EX  ›  iOS

iOS Objective-C 关于 NSURL 实例化的疑惑

  •  
  •   sl0000 · Dec 30, 2016 · 2480 views
    This topic created in 3599 days ago, the information mentioned may be changed or developed.

    [NSURL URLWithString:@""] == nil // false

    [NSURL URLWithString:@" "] == nil // true

    为什么是这样的结果

    4 replies  •  2016-12-30 23:50:36 +08:00
    mornlight
    mornlight
    Dec 30, 2016❤️1
    1
    The URL string with which to initialize the NSURL object. Must be a URL that conforms to RFC 2396. This method parses URLString according to RFCs 1738 and 1808.

    空字符串是合法的 URL ,空格不是。
    sl0000
    sl0000
    OP
    Dec 30, 2016
    2
    又 get 一个新知识, 不过在 Swift 里面 URL 以空字符串实例化就是 nil
    xjbeta
    xjbeta
    Dec 30, 2016
    3
    NSURL(string: "") //(no URL)
    NSURL(string: " ") //nil
    swift3 playground 内
    直接用的 OC 的 NSURL 应该一个道理
    xjbeta
    xjbeta
    Dec 30, 2016
    4
    @sl0000 swift3 的 URL 就都是 nil 用 NSURL 就和上面的一样了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1580 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 61ms · UTC 08:38 · PVG 16:38 · LAX 00:38 · JFK 03:38
    ♥ Do have faith in what you're doing.