V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
snipes
V2EX  ›  Swift

请教一个 Swift 语法问题( Alamofire.request)?

  •  
  •   snipes · Feb 23, 2016 · 3667 views
    This topic created in 3726 days ago, the information mentioned may be changed or developed.

    Alamofire.request(.GET, postEndpoint)
    .responseJSON { response in
    // handle JSON
    }
    .responseString{ response in
    print(response.result.value)
    print(response.result.error)
    }

    想问一下,这里的.responseXXXX 是什么语法,另外为什么一个方法有多个尾闭包啊?没搜到答案,如果有资料的话发个链接我自己看更好,感谢。

    1 replies    2016-02-23 23:08:07 +08:00
    finab
        1
    finab  
       Feb 23, 2016 via iPhone   ❤️ 1
    前面的 requset 方法 会返回一个 Request 对象, responseXXX 是 Requset 对象的方法,接受一个闭包做参数。 responseString 会返回字符串, responseJSon 会返回 json 。这是这个库的一个很灵活的写法,你可以返回任何你想返回的数据结构。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3664 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 10:41 · PVG 18:41 · LAX 03:41 · JFK 06:41
    ♥ Do have faith in what you're doing.