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 { 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] { func toAnyObjectArray() -> [AnyObject] {
return flatMap({$0 as? AnyObject}) return flatMap({ $0 as AnyObject })
} }
} }

View File

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

View File

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