Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions Foundation/NSData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -850,21 +850,13 @@ open class NSData : NSObject, NSCopying, NSMutableCopying, NSSecureCoding {
extension NSData : _CFBridgable, _SwiftBridgable {
typealias SwiftType = Data
internal var _swiftObject: SwiftType { return Data(referencing: self) }

public func bridge() -> Data {
return _swiftObject
}
}

extension Data : _NSBridgable, _CFBridgable {
typealias CFType = CFData
typealias NSType = NSData
internal var _cfObject: CFType { return _nsObject._cfObject }
internal var _nsObject: NSType { return _bridgeToObjectiveC() }

public func bridge() -> NSData {
return _nsObject
}
}

extension CFData : _NSBridgable, _SwiftBridgable {
Expand Down
7 changes: 4 additions & 3 deletions Foundation/NSJSONSerialization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,10 @@ open class JSONSerialization : NSObject {
*/
open class func writeJSONObject(_ obj: Any, toStream stream: NSOutputStream, options opt: WritingOptions) throws -> Int {
let jsonData = try _data(withJSONObject: obj, options: opt, stream: true)
let jsonNSData = jsonData.bridge()
let bytePtr = jsonNSData.bytes.bindMemory(to: UInt8.self, capacity: jsonNSData.length)
return stream.write(bytePtr, maxLength: jsonNSData.length)
let count = jsonData.count
return jsonData.withUnsafeBytes { (bytePtr) -> Int in
return stream.write(bytePtr, maxLength: count)
}
}

/* Create a JSON object from JSON data stream. The stream should be opened and configured. All other behavior of this method is the same as the JSONObjectWithData:options:error: method.
Expand Down
2 changes: 1 addition & 1 deletion TestFoundation/TestNSData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ extension TestNSData {

func test_dataHash() {
let dataStruct = "Hello World".data(using: .utf8)!
let dataObj = dataStruct.bridge()
let dataObj = dataStruct._bridgeToObjectiveC()
XCTAssertEqual(dataObj.hashValue, dataStruct.hashValue, "Data and NSData should have the same hash value")
}

Expand Down
2 changes: 1 addition & 1 deletion TestFoundation/TestNSKeyedArchiver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class TestNSKeyedArchiver : XCTestCase {
XCTAssertTrue(encode(archiver))
archiver.finishEncoding()

let unarchiver = NSKeyedUnarchiver(forReadingWithData: data.bridge())
let unarchiver = NSKeyedUnarchiver(forReadingWithData: Data._unconditionallyBridgeFromObjectiveC(data))
XCTAssertTrue(decode(unarchiver))
}

Expand Down