Created
September 21, 2014 23:45
-
-
Save mchirico/8698f3e05015d1374f59 to your computer and use it in GitHub Desktop.
Unsolved Swift Problem ... can't figure this out...
This file contains 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
/* | |
someObjects is [AnyObject!], but I want to | |
define it again as Array of Dictionary<String:String> | |
*/ | |
// Starts out like this | |
let someObjects: [AnyObject!] = [ | |
["a one":"1", "a two":"2","a three":"3"], | |
["b one":"1", "b two":"2","b three":"3"]] | |
// Now how do you get it back. | |
// The following are all failures | |
func findAllKV(array: [[String:AnyObject]], key: String, value: AnyObject) -> [[String:AnyObject]] { | |
var all : [[String:AnyObject]] = [] | |
for dict in array { | |
if let val: AnyObject = dict[key] { | |
if val === value { | |
all.append(dict) | |
} | |
} | |
} | |
return all | |
} | |
func makeDict<T: Hashable>(arr: [T]) { | |
let x = Dictionary<T, Int>() | |
} | |
for i in someObjects { | |
makeDict(i!) | |
} | |
if let k=someObjects as? [[AnyObject:AnyObject?]!] { | |
} | |
if let k=someObjects as? [Dictionary?]{ | |
print("yes") | |
} else { | |
println("nope") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment