Skip to content

Instantly share code, notes, and snippets.

@jackreichert
jackreichert / getKeyVals
Last active March 19, 2020 07:12
This is a swift extension for NSURL so you can parse the query string and get back a dictionary of the variables.
extension NSURL {
func getKeyVals() -> Dictionary<String, String>? {
var results = [String:String]()
var keyValues = self.query?.componentsSeparatedByString("&")
if keyValues?.count > 0 {
for pair in keyValues! {
let kv = pair.componentsSeparatedByString("=")
if kv.count > 1 {
results.updateValue(kv[1], forKey: kv[0])
}
let mainQueueA = dispatch_get_global_queue(qos_class_main(), 0)
let mainQueueB = dispatch_get_main_queue()
// This works fine
dispatch_apply(3, mainQueueA) { i in
println("A: \(i)")
}
println("Yep")
// This never calls the block and hangs the main thread