varios tweaks

This commit is contained in:
Erik 2016-08-20 17:58:52 -04:00
parent 29670af4d3
commit f982e756c2
No known key found for this signature in database
GPG Key ID: 4930B7C5FBC1A69D
3 changed files with 13 additions and 8 deletions

View File

@ -30,9 +30,9 @@ enum JSONError : Error {
}
extension Array {
/// Because Swift 3 removes a lot of implicit briding so we have to perform more casts
/// Because Swift 3 removes a lot of implicit briding so we have to perform more explicit bridging
func toAnyObjectArray() -> [AnyObject] {
return flatMap({$0 as? AnyObject})
return flatMap({ $0 as AnyObject })
}
}

View File

@ -134,7 +134,7 @@ struct SocketPacket {
// binary data
private func _fillInPlaceholders(_ object: AnyObject) -> AnyObject {
switch object {
case let dict as NSDictionary:
case let dict as [AnyHashable: AnyObject]:
if dict["_placeholder"] as? Bool ?? false {
return binary[dict["num"] as! Int] as AnyObject
} else {
@ -187,11 +187,14 @@ private extension SocketPacket {
return placeholder as AnyObject
case let arr as [AnyObject]:
return arr.map({shred($0, binary: &binary)}) as AnyObject
case let dict as NSDictionary:
return dict.reduce(NSMutableDictionary(), {cur, keyValue in
cur[keyValue.0 as! NSCopying] = shred(keyValue.1 as AnyObject, binary: &binary)
return cur
})
case let dict as [AnyHashable: AnyObject]:
return dict.reduce([AnyHashable: AnyObject](), {cur, keyValue in
var mutCur = cur
mutCur[keyValue.0] = shred(keyValue.1 as AnyObject, binary: &binary)
return mutCur
}) as AnyObject
default:
return data
}

View File

@ -47,6 +47,7 @@ struct SocketStringReader {
mutating func read(count: Int) -> String {
let readString = message[currentIndex..<message.characters.index(currentIndex, offsetBy: count)]
advance(by: count)
return readString
@ -54,6 +55,7 @@ struct SocketStringReader {
mutating func readUntilOccurence(of string: String) -> String {
let substring = message[currentIndex..<message.endIndex]
guard let foundRange = substring.range(of: string) else {
currentIndex = message.endIndex