Skip to content

Commit 0f06824

Browse files
committed
Remove _CFBridgeable
Windows is seeing deserialization errors when dealing with _CFBridgeable; the protocol was slated for removal anyway, and it can be removed now.
1 parent dc881a8 commit 0f06824

17 files changed

+34
-54
lines changed

Diff for: Sources/Foundation/Bridging.swift

+1-5
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,7 @@ extension _StructTypeBridgeable {
5151
}
5252
}
5353

54-
// slated for removal, these are the swift-corelibs-only variant of the _ObjectiveCBridgeable
55-
internal protocol _CFBridgeable {
56-
associatedtype CFType
57-
var _cfObject: CFType { get }
58-
}
54+
// slated for removal, these are the swift-corelibs-only variant of the _ObjectiveCBridgeable\
5955

6056
internal protocol _SwiftBridgeable {
6157
associatedtype SwiftType

Diff for: Sources/Foundation/Bundle.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ open class Bundle: NSObject {
278278
}
279279

280280
open class func urls(forResourcesWithExtension ext: String?, subdirectory subpath: String?, in bundleURL: NSURL) -> [NSURL]? {
281-
return CFBundleCopyResourceURLsOfTypeInDirectory(bundleURL._cfObject, ext?._cfObject, subpath?._cfObject)?._unsafeTypedBridge()
281+
return CFBundleCopyResourceURLsOfTypeInDirectory(bundleURL._cfObject, ext?._cfObject, subpath?._cfObject)._nsObject as? [NSURL]
282282
}
283283

284284
// -----------------------------------------------------------------------------------
@@ -306,11 +306,11 @@ open class Bundle: NSObject {
306306
}
307307

308308
open func urls(forResourcesWithExtension ext: String?, subdirectory subpath: String?) -> [NSURL]? {
309-
return CFBundleCopyResourceURLsOfType(_bundle, ext?._cfObject, subpath?._cfObject)?._unsafeTypedBridge()
309+
return CFBundleCopyResourceURLsOfType(_bundle, ext?._cfObject, subpath?._cfObject)?._nsObject as? [NSURL]
310310
}
311311

312312
open func urls(forResourcesWithExtension ext: String?, subdirectory subpath: String?, localization localizationName: String?) -> [NSURL]? {
313-
return CFBundleCopyResourceURLsOfTypeForLocalization(_bundle, ext?._cfObject, subpath?._cfObject, localizationName?._cfObject)?._unsafeTypedBridge()
313+
return CFBundleCopyResourceURLsOfTypeForLocalization(_bundle, ext?._cfObject, subpath?._cfObject, localizationName?._cfObject)?._nsObject as? [NSURL]
314314
}
315315

316316
// -----------------------------------------------------------------------------------

Diff for: Sources/Foundation/DateIntervalFormatter.swift

+7-8
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,9 @@ open class DateIntervalFormatter: Formatter {
102102
public required init?(coder: NSCoder) {
103103
guard coder.allowsKeyedCoding else { fatalError("Requires a keyed coding-capable archiver.") }
104104

105-
func cfObject<T: NSObject & _CFBridgeable>(of aClass: T.Type, from coder: NSCoder, forKey key: String) -> T.CFType? {
105+
func object<T: NSObject>(of aClass: T.Type, from coder: NSCoder, forKey key: String) -> T? {
106106
if coder.containsValue(forKey: key) {
107-
let object = coder.decodeObject(forKey: key) as? T
108-
return object?._cfObject
107+
return coder.decodeObject(forKey: key) as? T
109108
} else {
110109
return nil
111110
}
@@ -115,13 +114,13 @@ open class DateIntervalFormatter: Formatter {
115114
_CFDateIntervalFormatterInitializeFromCoderValues(core,
116115
coder.decodeInt64(forKey: "NS.dateStyle"),
117116
coder.decodeInt64(forKey: "NS.timeStyle"),
118-
cfObject(of: NSString.self, from: coder, forKey: "NS.dateTemplate"),
119-
cfObject(of: NSString.self, from: coder, forKey: "NS.dateTemplateFromStyle"),
117+
object(of: NSString.self, from: coder, forKey: "NS.dateTemplate")?._cfObject,
118+
object(of: NSString.self, from: coder, forKey: "NS.dateTemplateFromStyle")?._cfObject,
120119
coder.decodeBool(forKey: "NS.modified"),
121120
coder.decodeBool(forKey: "NS.useTemplate"),
122-
cfObject(of: NSLocale.self, from: coder, forKey: "NS.locale"),
123-
cfObject(of: NSCalendar.self, from: coder, forKey: "NS.calendar"),
124-
cfObject(of: NSTimeZone.self, from: coder, forKey: "NS.timeZone"))
121+
object(of: NSLocale.self, from: coder, forKey: "NS.locale")?._cfObject,
122+
object(of: NSCalendar.self, from: coder, forKey: "NS.calendar")?._cfObject,
123+
object(of: NSTimeZone.self, from: coder, forKey: "NS.timeZone")?._cfObject)
125124
self._core = core
126125

127126
super.init(coder: coder)

Diff for: Sources/Foundation/NSArray.swift

+2-16
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ open class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NSCo
714714
}
715715
}
716716

717-
extension NSArray : _CFBridgeable, _SwiftBridgeable {
717+
extension NSArray : _SwiftBridgeable {
718718
internal var _cfObject: CFArray { return unsafeBitCast(self, to: CFArray.self) }
719719
internal var _swiftObject: [AnyObject] { return Array._unconditionallyBridgeFromObjectiveC(self) }
720720
}
@@ -728,21 +728,7 @@ extension CFArray : _NSBridgeable, _SwiftBridgeable {
728728
internal var _swiftObject: Array<Any> { return _nsObject._swiftObject }
729729
}
730730

731-
extension CFArray {
732-
/// Bridge something returned from CF to an Array<T>. Useful when we already know that a CFArray contains objects that are toll-free bridged with Swift objects, e.g. CFArray<CFURLRef>.
733-
/// - Note: This bridging operation is unfortunately still O(n), but it only traverses the NSArray once, creating the Swift array and casting at the same time.
734-
func _unsafeTypedBridge<T : _CFBridgeable>() -> Array<T> {
735-
var result = Array<T>()
736-
let count = CFArrayGetCount(self)
737-
result.reserveCapacity(count)
738-
for i in 0..<count {
739-
result.append(unsafeBitCast(CFArrayGetValueAtIndex(self, i), to: T.self))
740-
}
741-
return result
742-
}
743-
}
744-
745-
extension Array : _NSBridgeable, _CFBridgeable {
731+
extension Array : _NSBridgeable {
746732
internal var _nsObject: NSArray { return _bridgeToObjectiveC() }
747733
internal var _cfObject: CFArray { return _nsObject._cfObject }
748734
}

Diff for: Sources/Foundation/NSAttributedString.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ private extension NSAttributedString {
375375
}
376376
}
377377

378-
extension NSAttributedString: _CFBridgeable {
378+
extension NSAttributedString {
379379
internal var _cfObject: CFAttributedString { return unsafeBitCast(self, to: CFAttributedString.self) }
380380
}
381381

Diff for: Sources/Foundation/NSCalendar.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -1986,11 +1986,11 @@ extension DateComponents : _NSBridgeable {
19861986
var _nsObject: NSType { return _bridgeToObjectiveC() }
19871987
}
19881988

1989-
extension NSCalendar: _SwiftBridgeable, _CFBridgeable {
1989+
extension NSCalendar: _SwiftBridgeable {
19901990
typealias SwiftType = Calendar
19911991
var _swiftObject: SwiftType { return Calendar(reference: self) }
19921992
}
1993-
extension Calendar: _NSBridgeable, _CFBridgeable {
1993+
extension Calendar: _NSBridgeable {
19941994
typealias NSType = NSCalendar
19951995
typealias CFType = CFCalendar
19961996
var _nsObject: NSCalendar { return _bridgeToObjectiveC() }

Diff for: Sources/Foundation/NSCharacterSet.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ open class NSMutableCharacterSet : NSCharacterSet {
482482
}
483483
}
484484

485-
extension CharacterSet : _CFBridgeable, _NSBridgeable {
485+
extension CharacterSet : _NSBridgeable {
486486
typealias CFType = CFCharacterSet
487487
typealias NSType = NSCharacterSet
488488
internal var _cfObject: CFType {

Diff for: Sources/Foundation/NSData.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -909,12 +909,12 @@ open class NSData : NSObject, NSCopying, NSMutableCopying, NSSecureCoding {
909909
}
910910

911911
// MARK: -
912-
extension NSData : _CFBridgeable, _SwiftBridgeable {
912+
extension NSData : _SwiftBridgeable {
913913
typealias SwiftType = Data
914914
internal var _swiftObject: SwiftType { return Data(referencing: self) }
915915
}
916916

917-
extension Data : _NSBridgeable, _CFBridgeable {
917+
extension Data : _NSBridgeable {
918918
typealias CFType = CFData
919919
typealias NSType = NSData
920920
internal var _cfObject: CFType { return _nsObject._cfObject }

Diff for: Sources/Foundation/NSDate.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ extension NSDate {
231231
}
232232
}
233233

234-
extension NSDate: _CFBridgeable, _SwiftBridgeable {
234+
extension NSDate: _SwiftBridgeable {
235235
typealias SwiftType = Date
236236
var _swiftObject: Date {
237237
return Date(timeIntervalSinceReferenceDate: timeIntervalSinceReferenceDate)
@@ -246,7 +246,7 @@ extension CFDate : _NSBridgeable, _SwiftBridgeable {
246246
internal var _swiftObject: Date { return _nsObject._swiftObject }
247247
}
248248

249-
extension Date : _NSBridgeable, _CFBridgeable {
249+
extension Date : _NSBridgeable {
250250
typealias NSType = NSDate
251251
typealias CFType = CFDate
252252

Diff for: Sources/Foundation/NSDictionary.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ open class NSDictionary : NSObject, NSCopying, NSMutableCopying, NSSecureCoding,
578578
}
579579
}
580580

581-
extension NSDictionary : _CFBridgeable, _SwiftBridgeable {
581+
extension NSDictionary : _SwiftBridgeable {
582582
internal var _cfObject: CFDictionary { return unsafeBitCast(self, to: CFDictionary.self) }
583583
internal var _swiftObject: Dictionary<AnyHashable, Any> { return Dictionary._unconditionallyBridgeFromObjectiveC(self) }
584584
}
@@ -592,7 +592,7 @@ extension CFDictionary : _NSBridgeable, _SwiftBridgeable {
592592
internal var _swiftObject: [AnyHashable: Any] { return _nsObject._swiftObject }
593593
}
594594

595-
extension Dictionary : _NSBridgeable, _CFBridgeable {
595+
extension Dictionary : _NSBridgeable {
596596
internal var _nsObject: NSDictionary { return _bridgeToObjectiveC() }
597597
internal var _cfObject: CFDictionary { return _nsObject._cfObject }
598598
}

Diff for: Sources/Foundation/NSError.swift

-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,6 @@ open class NSError : NSObject, NSCopying, NSSecureCoding, NSCoding {
204204

205205
extension NSError : Swift.Error { }
206206

207-
extension NSError : _CFBridgeable { }
208207
extension CFError : _NSBridgeable {
209208
typealias NSType = NSError
210209
internal var _nsObject: NSType {

Diff for: Sources/Foundation/NSLocale.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
@_implementationOnly import CoreFoundation
1212

13-
open class NSLocale: NSObject, NSCopying, NSSecureCoding, _CFBridgeable {
13+
open class NSLocale: NSObject, NSCopying, NSSecureCoding {
1414
typealias CFType = CFLocale
1515

1616
// struct __CFLocale
@@ -222,7 +222,7 @@ extension NSLocale : _SwiftBridgeable {
222222
}
223223
}
224224

225-
extension Locale : _CFBridgeable {
225+
extension Locale {
226226
typealias CFType = CFLocale
227227
internal var _cfObject: CFLocale {
228228
return _bridgeToObjectiveC()._cfObject

Diff for: Sources/Foundation/NSNumber.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ extension Bool : _ObjectiveCBridgeable {
557557
}
558558
}
559559

560-
extension Bool : _CFBridgeable {
560+
extension Bool {
561561
typealias CFType = CFBoolean
562562
var _cfObject: CFType {
563563
return self ? kCFBooleanTrue : kCFBooleanFalse

Diff for: Sources/Foundation/NSSet.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ open class NSSet : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NSCodi
334334
}
335335
}
336336

337-
extension NSSet : _CFBridgeable, _SwiftBridgeable {
337+
extension NSSet : _SwiftBridgeable {
338338
internal var _cfObject: CFSet { return unsafeBitCast(self, to: CFSet.self) }
339339
internal var _swiftObject: Set<NSObject> { return Set._unconditionallyBridgeFromObjectiveC(self) }
340340
}
@@ -348,7 +348,7 @@ extension NSMutableSet {
348348
internal var _cfMutableObject: CFMutableSet { return unsafeBitCast(self, to: CFMutableSet.self) }
349349
}
350350

351-
extension Set : _NSBridgeable, _CFBridgeable {
351+
extension Set : _NSBridgeable {
352352
internal var _nsObject: NSSet { return _bridgeToObjectiveC() }
353353
internal var _cfObject: CFSet { return _nsObject._cfObject }
354354
}

Diff for: Sources/Foundation/NSString.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -1613,7 +1613,7 @@ extension String {
16131613
}
16141614
}
16151615

1616-
extension NSString : _CFBridgeable, _SwiftBridgeable {
1616+
extension NSString : _SwiftBridgeable {
16171617
typealias SwiftType = String
16181618
internal var _cfObject: CFString { return unsafeBitCast(self, to: CFString.self) }
16191619
internal var _swiftObject: String { return String._unconditionallyBridgeFromObjectiveC(self) }
@@ -1630,7 +1630,7 @@ extension CFString : _NSBridgeable, _SwiftBridgeable {
16301630
internal var _swiftObject: String { return _nsObject._swiftObject }
16311631
}
16321632

1633-
extension String : _NSBridgeable, _CFBridgeable {
1633+
extension String : _NSBridgeable {
16341634
typealias NSType = NSString
16351635
typealias CFType = CFString
16361636
internal var _nsObject: NSType { return _bridgeToObjectiveC() }

Diff for: Sources/Foundation/NSTimeZone.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ open class NSTimeZone : NSObject, NSCopying, NSSecureCoding, NSCoding {
252252

253253
}
254254

255-
extension NSTimeZone: _SwiftBridgeable, _CFBridgeable {
255+
extension NSTimeZone: _SwiftBridgeable {
256256
typealias SwiftType = TimeZone
257257
var _swiftObject: TimeZone { return TimeZone(reference: self) }
258258
}
@@ -263,7 +263,7 @@ extension CFTimeZone : _SwiftBridgeable, _NSBridgeable {
263263
var _swiftObject: TimeZone { return _nsObject._swiftObject }
264264
}
265265

266-
extension TimeZone : _NSBridgeable, _CFBridgeable {
266+
extension TimeZone : _NSBridgeable {
267267
typealias NSType = NSTimeZone
268268
typealias CFType = CFTimeZone
269269
var _nsObject : NSTimeZone { return _bridgeToObjectiveC() }

Diff for: Sources/Foundation/NSURL.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -1492,7 +1492,7 @@ open class NSURLComponents: NSObject, NSCopying {
14921492
}
14931493
}
14941494

1495-
extension NSURL: _CFBridgeable, _SwiftBridgeable {
1495+
extension NSURL: _SwiftBridgeable {
14961496
typealias SwiftType = URL
14971497
internal var _swiftObject: SwiftType { return URL(reference: self) }
14981498
}
@@ -1504,7 +1504,7 @@ extension CFURL : _NSBridgeable, _SwiftBridgeable {
15041504
internal var _swiftObject: SwiftType { return _nsObject._swiftObject }
15051505
}
15061506

1507-
extension URL : _NSBridgeable, _CFBridgeable {
1507+
extension URL : _NSBridgeable {
15081508
typealias NSType = NSURL
15091509
typealias CFType = CFURL
15101510
internal var _nsObject: NSType { return self.reference }

0 commit comments

Comments
 (0)