Skip to content

Commit b86ea32

Browse files
authored
Merge pull request #3132 from compnerd/finalized
Foundation: `final`-ize many bridgeable interfaces
2 parents b8a67da + a303df8 commit b86ea32

25 files changed

+51
-59
lines changed

Sources/Foundation/Bundle.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ private func _getTypeContextDescriptor(of cls: AnyClass) -> UnsafeRawPointer
1414

1515
open class Bundle: NSObject {
1616
private var _bundleStorage: AnyObject!
17-
private var _bundle: CFBundle! {
17+
private final var _bundle: CFBundle! {
1818
get { unsafeBitCast(_bundleStorage, to: CFBundle?.self) }
1919
set { _bundleStorage = newValue }
2020
}

Sources/Foundation/DateFormatter.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
open class DateFormatter : Formatter {
1313
typealias CFType = CFDateFormatter
14-
private var __cfObject: CFType?
15-
private var _cfObject: CFType {
14+
private final var __cfObject: CFType?
15+
private final var _cfObject: CFType {
1616
guard let obj = __cfObject else {
1717
let dateStyle = CFDateFormatterStyle(rawValue: CFIndex(self.dateStyle.rawValue))!
1818
let timeStyle = CFDateFormatterStyle(rawValue: CFIndex(self.timeStyle.rawValue))!
@@ -147,7 +147,7 @@ open class DateFormatter : Formatter {
147147
__cfObject = nil
148148
}
149149

150-
internal func _setFormatterAttributes(_ formatter: CFDateFormatter) {
150+
internal final func _setFormatterAttributes(_ formatter: CFDateFormatter) {
151151
_setFormatterAttribute(formatter, attributeName: kCFDateFormatterIsLenient, value: isLenient._cfObject)
152152
_setFormatterAttribute(formatter, attributeName: kCFDateFormatterTimeZone, value: _timeZone?._cfObject)
153153
if let ident = _calendar?.identifier {
@@ -181,7 +181,7 @@ open class DateFormatter : Formatter {
181181
_setFormatterAttribute(formatter, attributeName: kCFDateFormatterGregorianStartDate, value: _gregorianStartDate?._cfObject)
182182
}
183183

184-
internal func _setFormatterAttribute(_ formatter: CFDateFormatter, attributeName: CFString, value: AnyObject?) {
184+
internal final func _setFormatterAttribute(_ formatter: CFDateFormatter, attributeName: CFString, value: AnyObject?) {
185185
if let value = value {
186186
CFDateFormatterSetProperty(formatter, attributeName, value)
187187
}

Sources/Foundation/DateIntervalFormatter.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ internal extension _CFDateIntervalFormatterBoundaryStyle {
8383
// DateIntervalFormatter returns nil and NO for all methods in Formatter.
8484

8585
open class DateIntervalFormatter: Formatter {
86-
var _core: AnyObject
87-
var core: CFDateIntervalFormatter {
86+
private var _core: AnyObject
87+
private final var core: CFDateIntervalFormatter {
8888
get { unsafeBitCast(_core, to: CFDateIntervalFormatter.self) }
8989
set { _core = newValue }
9090
}

Sources/Foundation/ISO8601DateFormatter.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ extension ISO8601DateFormatter {
5151
open class ISO8601DateFormatter : Formatter, NSSecureCoding {
5252

5353
typealias CFType = CFDateFormatter
54-
private var __cfObject: CFType?
55-
private var _cfObject: CFType {
54+
private final var __cfObject: CFType?
55+
private final var _cfObject: CFType {
5656
guard let obj = __cfObject else {
5757
let format = CFISO8601DateFormatOptions(rawValue: formatOptions.rawValue)
5858
let obj = CFDateFormatterCreateISO8601Formatter(kCFAllocatorSystemDefault, format)!

Sources/Foundation/NSCalendar.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ open class NSCalendar : NSObject, NSCopying, NSSecureCoding {
301301

302302
// Methods to return component name strings localized to the calendar's locale
303303

304-
private func _symbols(_ key: CFString) -> [String] {
304+
private final func _symbols(_ key: CFString) -> [String] {
305305
let dateFormatter = CFDateFormatterCreate(kCFAllocatorSystemDefault, locale?._cfObject, kCFDateFormatterNoStyle, kCFDateFormatterNoStyle)
306306
CFDateFormatterSetProperty(dateFormatter, kCFDateFormatterCalendarKey, _cfObject)
307307
let result = (CFDateFormatterCopyProperty(dateFormatter, key) as! NSArray)._swiftObject
@@ -310,7 +310,7 @@ open class NSCalendar : NSObject, NSCopying, NSSecureCoding {
310310
}
311311
}
312312

313-
private func _symbol(_ key: CFString) -> String {
313+
private final func _symbol(_ key: CFString) -> String {
314314
let dateFormatter = CFDateFormatterCreate(kCFAllocatorSystemDefault, locale?._bridgeToObjectiveC()._cfObject, kCFDateFormatterNoStyle, kCFDateFormatterNoStyle)
315315
CFDateFormatterSetProperty(dateFormatter, kCFDateFormatterCalendarKey, self._cfObject)
316316
return (CFDateFormatterCopyProperty(dateFormatter, key) as! NSString)._swiftObject

Sources/Foundation/NSCharacterSet.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ open class NSCharacterSet : NSObject, NSCopying, NSMutableCopying, NSSecureCodin
7272
return unsafeBitCast(self, to: CFType.self)
7373
}
7474

75-
internal var _cfMutableObject: CFMutableCharacterSet {
75+
internal final var _cfMutableObject: CFMutableCharacterSet {
7676
return unsafeBitCast(self, to: CFMutableCharacterSet.self)
7777
}
7878

Sources/Foundation/NSData.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ open class NSData : NSObject, NSCopying, NSMutableCopying, NSSecureCoding {
7777
private var _deallocHandler: _NSDataDeallocator? = _NSDataDeallocator() // for Swift
7878
private var _bytes: UnsafeMutablePointer<UInt8>? = nil
7979

80-
internal var _cfObject: CFType {
80+
internal final var _cfObject: CFType {
8181
if type(of: self) === NSData.self || type(of: self) === NSMutableData.self {
8282
return unsafeBitCast(self, to: CFType.self)
8383
} else {
@@ -957,7 +957,7 @@ extension CFData : _NSBridgeable, _SwiftBridgeable {
957957

958958
// MARK: -
959959
open class NSMutableData : NSData {
960-
internal var _cfMutableObject: CFMutableData { return unsafeBitCast(self, to: CFMutableData.self) }
960+
internal final var _cfMutableObject: CFMutableData { return unsafeBitCast(self, to: CFMutableData.self) }
961961

962962
public override init() {
963963
super.init(bytes: nil, length: 0)

Sources/Foundation/NSDate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ open class NSDate : NSObject, NSCopying, NSSecureCoding, NSCoding {
5252
_CFDeinit(self)
5353
}
5454

55-
internal var _cfObject: CFType {
55+
internal final var _cfObject: CFType {
5656
return unsafeBitCast(self, to: CFType.self)
5757
}
5858

Sources/Foundation/NSError.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public let NSFilePathErrorKey: String = "NSFilePathErrorKey"
5050
open class NSError : NSObject, NSCopying, NSSecureCoding, NSCoding {
5151
typealias CFType = CFError
5252

53-
internal var _cfObject: CFType {
53+
internal final var _cfObject: CFType {
5454
return CFErrorCreate(kCFAllocatorSystemDefault, domain._cfObject, code, nil)
5555
}
5656

Sources/Foundation/NSKeyedUnarchiver.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ open class NSKeyedUnarchiver : NSCoder {
5656
#endif
5757
}
5858

59-
private var _stream : Stream
59+
private final var _stream : Stream
6060
private var _flags = UnarchiverFlags(rawValue: 0)
6161
private var _containers : Array<DecodingContext>? = nil
6262
private var _objects : Array<Any> = []

Sources/Foundation/NSLocale.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ open class NSLocale: NSObject, NSCopying, NSSecureCoding {
2121
private var _lock: _NSCFLock = _NSCFLockInit()
2222
private var _nullLocale: Bool = false
2323

24-
internal var _cfObject: CFType {
24+
internal final var _cfObject: CFType {
2525
return unsafeBitCast(self, to: CFType.self)
2626
}
2727

Sources/Foundation/NSNumber.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ open class NSNumber : NSValue {
609609
private var _base = _CFInfo(typeID: CFNumberGetTypeID())
610610
private var _pad: UInt64 = 0
611611

612-
internal var _cfObject: CFType {
612+
internal final var _cfObject: CFType {
613613
return unsafeBitCast(self, to: CFType.self)
614614
}
615615

@@ -1088,7 +1088,7 @@ open class NSNumber : NSValue {
10881088
}
10891089
}
10901090

1091-
internal func _getValue(_ valuePtr: UnsafeMutableRawPointer, forType type: CFNumberType) -> Bool {
1091+
internal final func _getValue(_ valuePtr: UnsafeMutableRawPointer, forType type: CFNumberType) -> Bool {
10921092
switch type {
10931093
case kCFNumberSInt8Type:
10941094
valuePtr.assumingMemoryBound(to: Int8.self).pointee = int8Value

Sources/Foundation/NSRegularExpression.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ extension NSRegularExpression {
2929

3030
open class NSRegularExpression: NSObject, NSCopying, NSSecureCoding {
3131
internal var _internalStorage: AnyObject
32-
internal var _internal: _CFRegularExpression {
32+
internal final var _internal: _CFRegularExpression {
3333
unsafeBitCast(_internalStorage, to: _CFRegularExpression.self)
3434
}
3535

Sources/Foundation/NSTimeZone.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ open class NSTimeZone : NSObject, NSCopying, NSSecureCoding, NSCoding {
1818
private var _periods: UnsafeMutableRawPointer? = nil
1919
private var _periodCnt = Int32(0)
2020

21-
internal var _cfObject: CFType {
21+
internal final var _cfObject: CFType {
2222
return unsafeBitCast(self, to: CFType.self)
2323
}
2424

Sources/Foundation/NSURL.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ open class NSURL : NSObject, NSSecureCoding, NSCopying {
9393
internal var _range8 = NSRange(location: 0, length: 0)
9494
internal var _range9 = NSRange(location: 0, length: 0)
9595

96-
internal var _cfObject : CFType {
96+
internal final var _cfObject : CFType {
9797
if type(of: self) === NSURL.self {
9898
return unsafeBitCast(self, to: CFType.self)
9999
} else {

Sources/Foundation/NSURLComponents.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
open class NSURLComponents: NSObject, NSCopying {
1414
private let _componentsStorage: AnyObject!
15-
private var _components: CFURLComponents! { unsafeBitCast(_componentsStorage, to: CFURLComponents?.self) }
15+
private final var _components: CFURLComponents! { unsafeBitCast(_componentsStorage, to: CFURLComponents?.self) }
1616

1717
open override func copy() -> Any {
1818
return copy(with: nil)
@@ -298,7 +298,7 @@ open class NSURLComponents: NSObject, NSCopying {
298298
return NSRange(_CFURLComponentsGetRangeOfFragment(_components))
299299
}
300300

301-
private func mapQueryItemsFromArray(array: CFArray) -> [URLQueryItem] {
301+
private final func mapQueryItemsFromArray(array: CFArray) -> [URLQueryItem] {
302302
let count = CFArrayGetCount(array)
303303
return (0..<count).map { idx in
304304
let oneEntry = unsafeBitCast(CFArrayGetValueAtIndex(array, idx), to: NSDictionary.self)

Sources/Foundation/NotificationQueue.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ open class NotificationQueue: NSObject {
3636
internal let notificationCenter: NotificationCenter
3737
internal var asapList = NSNotificationList()
3838
internal var idleList = NSNotificationList()
39-
internal lazy var idleRunloopObserver: CFRunLoopObserver = {
39+
internal final lazy var idleRunloopObserver: CFRunLoopObserver = {
4040
return CFRunLoopObserverCreateWithHandler(kCFAllocatorDefault, CFOptionFlags(kCFRunLoopBeforeTimers), true, 0) {[weak self] observer, activity in
4141
self!.notifyQueues(.whenIdle)
4242
}
4343
}()
44-
internal lazy var asapRunloopObserver: CFRunLoopObserver = {
44+
internal final lazy var asapRunloopObserver: CFRunLoopObserver = {
4545
return CFRunLoopObserverCreateWithHandler(kCFAllocatorDefault, CFOptionFlags(kCFRunLoopBeforeWaiting | kCFRunLoopExit), true, 0) {[weak self] observer, activity in
4646
self!.notifyQueues(.asap)
4747
}
@@ -130,12 +130,12 @@ open class NotificationQueue: NSObject {
130130

131131
// MARK: Private
132132

133-
private func addRunloopObserver(_ observer: CFRunLoopObserver) {
133+
private final func addRunloopObserver(_ observer: CFRunLoopObserver) {
134134
CFRunLoopAddObserver(RunLoop.current._cfRunLoop, observer, kCFRunLoopDefaultMode)
135135
CFRunLoopAddObserver(RunLoop.current._cfRunLoop, observer, kCFRunLoopCommonModes)
136136
}
137137

138-
private func removeRunloopObserver(_ observer: CFRunLoopObserver) {
138+
private final func removeRunloopObserver(_ observer: CFRunLoopObserver) {
139139
CFRunLoopRemoveObserver(RunLoop.current._cfRunLoop, observer, kCFRunLoopDefaultMode)
140140
CFRunLoopRemoveObserver(RunLoop.current._cfRunLoop, observer, kCFRunLoopCommonModes)
141141
}

Sources/Foundation/NumberFormatter.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ extension NumberFormatter {
4444
open class NumberFormatter : Formatter {
4545

4646
typealias CFType = CFNumberFormatter
47-
private var _currentCfFormatter: CFType?
48-
private var _cfFormatter: CFType {
47+
private final var _currentCfFormatter: CFType?
48+
private final var _cfFormatter: CFType {
4949
if let obj = _currentCfFormatter {
5050
return obj
5151
} else {
@@ -192,7 +192,7 @@ open class NumberFormatter : Formatter {
192192
_currentCfFormatter = nil
193193
}
194194

195-
private func _setFormatterAttributes(_ formatter: CFNumberFormatter) {
195+
private final func _setFormatterAttributes(_ formatter: CFNumberFormatter) {
196196
if numberStyle == .currency {
197197
// Prefer currencySymbol, then currencyCode then locale.currencySymbol
198198
if let symbol = _currencySymbol {
@@ -253,13 +253,13 @@ open class NumberFormatter : Formatter {
253253
}
254254
}
255255

256-
private func _setFormatterAttribute(_ formatter: CFNumberFormatter, attributeName: CFString, value: AnyObject?) {
256+
private final func _setFormatterAttribute(_ formatter: CFNumberFormatter, attributeName: CFString, value: AnyObject?) {
257257
if let value = value {
258258
CFNumberFormatterSetProperty(formatter, attributeName, value)
259259
}
260260
}
261261

262-
private func _getFormatterAttribute(_ formatter: CFNumberFormatter, attributeName: CFString) -> String? {
262+
private final func _getFormatterAttribute(_ formatter: CFNumberFormatter, attributeName: CFString) -> String? {
263263
return CFNumberFormatterCopyProperty(formatter, attributeName) as? String
264264
}
265265

Sources/Foundation/Port.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ open class SocketPort : Port {
476476
self.init(protocolFamily: PF_INET, socketType: SOCK_STREAM, protocol: IPPROTO_TCP, address: data)
477477
}
478478

479-
private func createNonuniquedCore(from socket: CFSocket, protocolFamily family: Int32, socketType type: Int32, protocol: Int32) {
479+
private final func createNonuniquedCore(from socket: CFSocket, protocolFamily family: Int32, socketType type: Int32, protocol: Int32) {
480480
self.core = Core(isUniqued: false)
481481
let address = CFSocketCopyAddress(socket)._swiftObject
482482
core.signature = Signature(address: LocalAddress(address), protocolFamily: family, socketType: type, protocol: `protocol`)
@@ -732,7 +732,7 @@ open class SocketPort : Port {
732732

733733
// Sending and receiving:
734734

735-
fileprivate func socketDidAccept(_ socket: CFSocket?, _ type: CFSocketCallBackType, _ address: CFData?, _ data: UnsafeRawPointer?) {
735+
fileprivate final func socketDidAccept(_ socket: CFSocket?, _ type: CFSocketCallBackType, _ address: CFData?, _ data: UnsafeRawPointer?) {
736736
guard let handle = data?.assumingMemoryBound(to: SocketNativeHandle.self),
737737
let address = address else {
738738
return
@@ -753,7 +753,7 @@ open class SocketPort : Port {
753753
}
754754
}
755755

756-
private func addToLoopsAssumingLockHeld(_ socket: CFSocket) {
756+
private final func addToLoopsAssumingLockHeld(_ socket: CFSocket) {
757757
guard let source = CFSocketCreateRunLoopSource(nil, socket, 600) else {
758758
return
759759
}
@@ -772,7 +772,7 @@ open class SocketPort : Port {
772772
case port = 2
773773
}
774774

775-
fileprivate func socketDidReceiveData(_ socket: CFSocket?, _ type: CFSocketCallBackType, _ address: CFData?, _ dataPointer: UnsafeRawPointer?) {
775+
fileprivate final func socketDidReceiveData(_ socket: CFSocket?, _ type: CFSocketCallBackType, _ address: CFData?, _ dataPointer: UnsafeRawPointer?) {
776776
guard let socket = socket,
777777
let dataPointer = dataPointer else { return }
778778
let socketKey = ObjectIdentifier(socket)
@@ -839,7 +839,7 @@ open class SocketPort : Port {
839839
lock.unlock() // Release lock from above ⬆
840840
}
841841

842-
fileprivate func socketDidReceiveDatagram(_ socket: CFSocket?, _ type: CFSocketCallBackType, _ address: CFData?, _ data: UnsafeRawPointer?) {
842+
fileprivate final func socketDidReceiveDatagram(_ socket: CFSocket?, _ type: CFSocketCallBackType, _ address: CFData?, _ data: UnsafeRawPointer?) {
843843
guard let address = address?._swiftObject,
844844
let data = data else {
845845
return
@@ -859,7 +859,7 @@ open class SocketPort : Port {
859859
static let offsetOfSignatureAddressLength = 15
860860
}
861861

862-
private func handleMessage(_ message: Data, from address: Data, socket: CFSocket?) {
862+
private final func handleMessage(_ message: Data, from address: Data, socket: CFSocket?) {
863863
guard message.count > 24, let delegate = delegate() else { return }
864864
let portMessage = message.withUnsafeBytes { (messageBuffer) -> PortMessage? in
865865
guard SocketPort.magicNumber == messageBuffer.load(fromByteOffset: Structure.offsetOfMagicNumber, as: UInt32.self).bigEndian,
@@ -1027,7 +1027,7 @@ open class SocketPort : Port {
10271027
private static let sendingSocketsLock = NSLock()
10281028
private static var sendingSockets: [SocketKind: CFSocket] = [:]
10291029

1030-
private func sendingSocket(for port: SocketPort, before time: TimeInterval) -> CFSocket? {
1030+
private final func sendingSocket(for port: SocketPort, before time: TimeInterval) -> CFSocket? {
10311031
let signature = port.core.signature!
10321032
let socketKind = signature.socketKind
10331033

Sources/Foundation/Process.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,13 +350,13 @@ open class Process: NSObject {
350350
}
351351

352352
private var _runLoopSourceContextStorage = NonexportedCFRunLoopSourceContextStorage()
353-
private var runLoopSourceContext: CFRunLoopSourceContext? {
353+
private final var runLoopSourceContext: CFRunLoopSourceContext? {
354354
get { _runLoopSourceContextStorage.value }
355355
set { _runLoopSourceContextStorage.value = newValue }
356356
}
357357

358358
private var _runLoopSourceStorage = NonexportedCFRunLoopSourceStorage()
359-
private var runLoopSource: CFRunLoopSource? {
359+
private final var runLoopSource: CFRunLoopSource? {
360360
get { _runLoopSourceStorage.value }
361361
set { _runLoopSourceStorage.value = newValue }
362362
}

Sources/Foundation/PropertyListSerialization.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ open class PropertyListSerialization : NSObject {
7676
}
7777

7878
#if !os(WASI)
79-
internal class func propertyList(with stream: CFReadStream, options opt: ReadOptions, format: UnsafeMutablePointer <PropertyListFormat>?) throws -> Any {
79+
internal final class func propertyList(with stream: CFReadStream, options opt: ReadOptions, format: UnsafeMutablePointer <PropertyListFormat>?) throws -> Any {
8080
var fmt = kCFPropertyListBinaryFormat_v1_0
8181
var error: Unmanaged<CFError>? = nil
8282
let decoded = withUnsafeMutablePointer(to: &fmt) { (outFmt: UnsafeMutablePointer<CFPropertyListFormat>) -> AnyObject? in

Sources/Foundation/RunLoop.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ internal func _NSRunLoopNew(_ cf: CFRunLoop) -> Unmanaged<AnyObject> {
5858

5959
open class RunLoop: NSObject {
6060
internal var _cfRunLoopStorage : AnyObject!
61-
internal var _cfRunLoop: CFRunLoop! {
61+
internal final var _cfRunLoop: CFRunLoop! {
6262
get { unsafeBitCast(_cfRunLoopStorage, to: CFRunLoop?.self) }
6363
set { _cfRunLoopStorage = newValue }
6464
}
@@ -98,7 +98,7 @@ open class RunLoop: NSObject {
9898
return _cfRunLoop
9999
}
100100
#else
101-
internal var currentCFRunLoop: CFRunLoop { _cfRunLoop }
101+
internal final var currentCFRunLoop: CFRunLoop { _cfRunLoop }
102102

103103
@available(*, unavailable, message: "Core Foundation is not available on your platform.")
104104
open func getCFRunLoop() -> Never {

0 commit comments

Comments
 (0)