📦URL
frameworks ⟩ Foundation ⟩ URL
var parts = URLComponents()
parts.scheme = "https"
parts.host = "example.com"
parts.path = "/v1/player"
parts.queryItems = [
URLQueryItem(name: "name", value: "艾佛森")
]
// ⭐️ URLQueryItem 會自動做 URL encoding,所以有空格或中文都沒關係。
// ╭───────── query item ─────────╮
// https://example.com/v1/player?name=%E8%89%BE%E4%BD%9B%E6%A3%AE
if let url = parts.url { ... }
Last updated
Was this helpful?