Skip to content

Commit

Permalink
Merge pull request swiftlang#580 from phausler/remove_Data_bridge
Browse files Browse the repository at this point in the history
NSData and struct Data should not have a function called bridge
  • Loading branch information
itaiferber authored Aug 22, 2016
2 parents f8c3fe6 + f8d6046 commit a478aaa
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 13 deletions.
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

0 comments on commit a478aaa

Please sign in to comment.