Kaynağa Gözat

Fix for "Data" type (macOS, 3.0 preview 1).

Damian Kołakowski 10 yıl önce
ebeveyn
işleme
17259cc90b
1 değiştirilmiş dosya ile 5 ekleme ve 2 silme
  1. 5 2
      Sources/Swifter/HttpResponse.swift

+ 5 - 2
Sources/Swifter/HttpResponse.swift

@@ -39,8 +39,11 @@ public enum HttpResponseBody {
                         throw SerializationError.InvalidObject
                     }
                     let json = try JSONSerialization.data(withJSONObject: object, options: JSONSerialization.WritingOptions.prettyPrinted)
-                    return (json.count, {
-                        $0.write(json)
+                    let data = json.withUnsafeBytes({ (body: UnsafePointer<UInt8>) -> Array<UInt8> in
+                        return Array(UnsafeBufferPointer(start: body, count: json.count))
+                    })
+                    return (data.count, {
+                        $0.write(data)
                     })
                 #endif
             case .Text(let body):