Last active
January 30, 2018 13:14
-
-
Save acalism/d775542574a740552067b7ee66e14a4f to your computer and use it in GitHub Desktop.
对于不带双斜杠的url,URL和URLComponents的处理结果不能让人满意
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1. URL 转为 URLComponents 时,什么时候会变成 nil | |
// 2. URLComponents 转为 URL 时,什么时候会变成 nil | |
// 3. URL 协议后不带双斜杠时,为什么 host 会变成 path(如下例) | |
let str = "http:im.qq.com" // "mailto:[email protected]" | |
if let url = URL(string: str), let uc = URLComponents(url: url, resolvingAgainstBaseURL: true) { | |
print(url) | |
print(uc, uc.url!) | |
print(uc.scheme!, uc.path) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment