我正在尝试复制我在对象C中执行的for in循环,但得到一个"'AnyObject‘没有名为'GeneratorType’的成员错误:
for (NSString *file in [dict objectForKey:@"Files"]){
NSString *content = [[source stringByAppendingPathComponent:@"Contents"] stringByA
}这是我的Swift
for file in dict.objectForKey("Files") {
let content:String = source.stringByAppendingPathComponent("Contents").stringByAppendingPathComponent(file)
}我已经尝试为字典定义了一个持有者变量。有没有人能看看我做错了什么?
发布于 2014-07-25 06:04:19
这不是字典中的循环。它循环通过存储在其中一个字典键中的数组。例如,如果您有一个字符串数组作为字典的键之一,那么这就是您想要做的。
if let arr = dict["Files"] as? [String] {
for file in arr {
}
}如果你确实想遍历字典,这在Swift中是可能的,并且可以像这样完成:
for (key, value) in dict {
println("key is - \(key) and value is - \(value)")
}发布于 2018-10-06 01:03:55
One Liner for loop
dict.forEach { print("key is - \($0) and value is - \($1)") }https://stackoverflow.com/questions/24944625
复制相似问题