From 8ecd7dd789f9c97e4772d1ded6b082a1be0dedaa Mon Sep 17 00:00:00 2001 From: Johannes Lund Date: Wed, 21 Sep 2016 01:31:38 +0200 Subject: [PATCH] Avoid casting to Swift types --- Benchmarks/NSFoundationDarwin/Sources/main.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Benchmarks/NSFoundationDarwin/Sources/main.swift b/Benchmarks/NSFoundationDarwin/Sources/main.swift index f5aea7b..a180d4f 100644 --- a/Benchmarks/NSFoundationDarwin/Sources/main.swift +++ b/Benchmarks/NSFoundationDarwin/Sources/main.swift @@ -9,7 +9,7 @@ extension User.Friend { public init(json: Any) throws { guard - let json = json as? [String: Any], + let json = json as? NSDictionary, let id = json["id"] as? Int, let name = json["name"] as? String else { throw JSONError.typeMismatch } @@ -23,7 +23,7 @@ extension User { public init(json: Any) throws { guard - let json = json as? [String: Any], + let json = json as? NSDictionary, let id = json["_id"] as? String, let index = json["index"] as? Int, let guid = json["guid"] as? String, @@ -45,7 +45,7 @@ extension User { let latitude = json["latitude"] as? Double, let longitude = json["longitude"] as? Double, let tags = json["tags"] as? [String], - let friendsObjects = json["friends"] as? [Any], + let friendsObjects = json["friends"] as? NSArray, //let tags = json["tags"].array?.flatMap({ $0.string }) ?? [] //let friends = try json["friends"].array?.map(Friend.init) ?? [] let greeting = json["greeting"] as? String, @@ -98,7 +98,7 @@ let modelResults = try bench { bytes in let data = Data(bytes: bytes) let json: Any = try JSONSerialization.jsonObject(with: data) - guard let array = json as? [Any] else { fatalError() } + guard let array = json as? NSArray else { fatalError() } _ = try array.map(User.init) }