Skip to content

Instantly share code, notes, and snippets.

View tncowart's full-sized avatar

Thomas Cowart tncowart

View GitHub Profile
@tncowart
tncowart / network_interface.swift
Last active August 12, 2020 18:42
enumerate iphone interfaces in swift and objective-c
private struct InterfaceNames {
static let wifi = ["en0"]
static let wired = ["en2", "en3", "en4"]
static let cellular = ["pdp_ip0", "pdp_ip1", "pdp_ip2", "pdp_ip3"]
static let supported = wifi + wired + cellular
}
private func ipAddresses() -> [String] {
var addresses = [String]()
var ifaddr: UnsafeMutablePointer<ifaddrs>?
@tncowart
tncowart / URLFragment.swift
Last active September 5, 2019 00:43
Splitting URL fragment into components
extension URL {
private func splitQuery(_ query: String) -> [String: [String]] {
return query.components(separatedBy: "&").map { $0.components(separatedBy: "=") }.reduce(into: [String: [String]]()) { result, element in
guard !element.isEmpty,
let key = element[0].removingPercentEncoding,
let value = element.count >= 2 ? element[1].removingPercentEncoding : "" else { return }
var values = result[key, default: [String]()]
values.append(value)
result[key] = values