use pattern matching

This commit is contained in:
Erik 2015-12-26 13:09:24 -05:00
parent aeb52de72f
commit 4e5fcff258

View File

@ -195,24 +195,19 @@ struct SocketPacket {
} }
private mutating func _fillInPlaceholders(data: AnyObject) -> AnyObject { private mutating func _fillInPlaceholders(data: AnyObject) -> AnyObject {
if let str = data as? String { switch data {
if let num = str["~~(\\d)"].groups() { case let string as String where string["~~(\\d)"].groups() != nil:
return binary[Int(num[1])!] return binary[Int(string["~~(\\d)"].groups()![1])!]
} else { case let dict as NSDictionary:
return str return dict.reduce(NSMutableDictionary(), combine: {cur, keyValue in
} cur[keyValue.0 as! NSCopying] = _fillInPlaceholders(keyValue.1)
} else if let dict = data as? NSDictionary { return cur
let newDict = NSMutableDictionary(dictionary: dict) })
case let arr as [AnyObject]:
for (key, value) in dict {
newDict[key as! NSCopying] = _fillInPlaceholders(value)
}
return newDict
} else if let arr = data as? [AnyObject] {
return arr.map({_fillInPlaceholders($0)}) return arr.map({_fillInPlaceholders($0)})
} else { default:
return data return data
} }
} }
} }