从头创建 URL
NSURL.build(scheme: "tel", path: "+7 (910) 670 14 00") // #> NSURL "tel:+7%20(910)%20670%2014%2000"
使用 BaseURL
let baseURL = NSURL(string: "https://google.com")!
baseURL.build(query: ["q": "Safe URL"]) // #> NSURL "https://google.com?q=Safe%20URL"
构建路径。无不安全的字符串插值
let baseURL = NSURL(string: "https://example.com/api/v1/")!
let userId = 1
baseURL.build(["users", userId]) // #> NSURL "https://example.com/api/v1/users/1"
SafeURL 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile:
pod "SafeURL"
Yury Korolev, [email protected]
SafeURL 可在 MIT 许可证下获取。有关更多信息,请参阅 LICENSE 文件。