mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
28 lines
638 B
Swift
28 lines
638 B
Swift
//
|
|
// Dictionary+Web.swift
|
|
// RSWeb
|
|
//
|
|
// Created by Brent Simmons on 1/13/18.
|
|
// Copyright © 2018 Ranchero Software. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
public extension Dictionary where Key == String, Value == String {
|
|
|
|
/// Translates a dictionary into a string like `foo=bar¶m2=some%20thing`.
|
|
var urlQueryString: String? {
|
|
|
|
var queryItems = [URLQueryItem]()
|
|
for (key, value) in self {
|
|
queryItems.append(URLQueryItem(name: key, value: value))
|
|
}
|
|
|
|
var components = URLComponents()
|
|
components.queryItems = queryItems
|
|
let s = components.percentEncodedQuery
|
|
|
|
return s == nil || s!.isEmpty ? nil : s
|
|
}
|
|
}
|