From a303df8ffd4d54389bbe2f69a35e66747dd46a4d Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Mon, 24 Jan 2022 10:41:08 -0800 Subject: [PATCH] Foundation: `final`-ize many bridgeable interfaces These are not overridden and are private fields which do not need to be emitted to the vtable. This allows these members to not impact the module serialization when `@_implementationOnly import`s are used for CoreFoundation by removing them entirely from the serialization path. --- Sources/Foundation/Bundle.swift | 2 +- Sources/Foundation/DateFormatter.swift | 8 ++++---- Sources/Foundation/DateIntervalFormatter.swift | 4 ++-- Sources/Foundation/ISO8601DateFormatter.swift | 4 ++-- Sources/Foundation/NSCalendar.swift | 4 ++-- Sources/Foundation/NSCharacterSet.swift | 2 +- Sources/Foundation/NSData.swift | 4 ++-- Sources/Foundation/NSDate.swift | 2 +- Sources/Foundation/NSError.swift | 2 +- Sources/Foundation/NSKeyedUnarchiver.swift | 2 +- Sources/Foundation/NSLocale.swift | 2 +- Sources/Foundation/NSNumber.swift | 4 ++-- Sources/Foundation/NSRegularExpression.swift | 2 +- Sources/Foundation/NSTimeZone.swift | 2 +- Sources/Foundation/NSURL.swift | 2 +- Sources/Foundation/NSURLComponents.swift | 4 ++-- Sources/Foundation/NotificationQueue.swift | 8 ++++---- Sources/Foundation/NumberFormatter.swift | 10 +++++----- Sources/Foundation/Port.swift | 14 +++++++------- Sources/Foundation/Process.swift | 4 ++-- Sources/Foundation/PropertyListSerialization.swift | 2 +- Sources/Foundation/RunLoop.swift | 4 ++-- Sources/Foundation/Stream.swift | 12 ++---------- Sources/Foundation/Thread.swift | 2 +- Sources/Foundation/Timer.swift | 4 ++-- 25 files changed, 51 insertions(+), 59 deletions(-) diff --git a/Sources/Foundation/Bundle.swift b/Sources/Foundation/Bundle.swift index 2ecf759296..f20a46eca4 100644 --- a/Sources/Foundation/Bundle.swift +++ b/Sources/Foundation/Bundle.swift @@ -14,7 +14,7 @@ private func _getTypeContextDescriptor(of cls: AnyClass) -> UnsafeRawPointer open class Bundle: NSObject { private var _bundleStorage: AnyObject! - private var _bundle: CFBundle! { + private final var _bundle: CFBundle! { get { unsafeBitCast(_bundleStorage, to: CFBundle?.self) } set { _bundleStorage = newValue } } diff --git a/Sources/Foundation/DateFormatter.swift b/Sources/Foundation/DateFormatter.swift index 7131242647..e6b8020fb8 100644 --- a/Sources/Foundation/DateFormatter.swift +++ b/Sources/Foundation/DateFormatter.swift @@ -11,8 +11,8 @@ open class DateFormatter : Formatter { typealias CFType = CFDateFormatter - private var __cfObject: CFType? - private var _cfObject: CFType { + private final var __cfObject: CFType? + private final var _cfObject: CFType { guard let obj = __cfObject else { let dateStyle = CFDateFormatterStyle(rawValue: CFIndex(self.dateStyle.rawValue))! let timeStyle = CFDateFormatterStyle(rawValue: CFIndex(self.timeStyle.rawValue))! @@ -147,7 +147,7 @@ open class DateFormatter : Formatter { __cfObject = nil } - internal func _setFormatterAttributes(_ formatter: CFDateFormatter) { + internal final func _setFormatterAttributes(_ formatter: CFDateFormatter) { _setFormatterAttribute(formatter, attributeName: kCFDateFormatterIsLenient, value: isLenient._cfObject) _setFormatterAttribute(formatter, attributeName: kCFDateFormatterTimeZone, value: _timeZone?._cfObject) if let ident = _calendar?.identifier { @@ -181,7 +181,7 @@ open class DateFormatter : Formatter { _setFormatterAttribute(formatter, attributeName: kCFDateFormatterGregorianStartDate, value: _gregorianStartDate?._cfObject) } - internal func _setFormatterAttribute(_ formatter: CFDateFormatter, attributeName: CFString, value: AnyObject?) { + internal final func _setFormatterAttribute(_ formatter: CFDateFormatter, attributeName: CFString, value: AnyObject?) { if let value = value { CFDateFormatterSetProperty(formatter, attributeName, value) } diff --git a/Sources/Foundation/DateIntervalFormatter.swift b/Sources/Foundation/DateIntervalFormatter.swift index ddafa84184..7a08780b7c 100644 --- a/Sources/Foundation/DateIntervalFormatter.swift +++ b/Sources/Foundation/DateIntervalFormatter.swift @@ -83,8 +83,8 @@ internal extension _CFDateIntervalFormatterBoundaryStyle { // DateIntervalFormatter returns nil and NO for all methods in Formatter. open class DateIntervalFormatter: Formatter { - var _core: AnyObject - var core: CFDateIntervalFormatter { + private var _core: AnyObject + private final var core: CFDateIntervalFormatter { get { unsafeBitCast(_core, to: CFDateIntervalFormatter.self) } set { _core = newValue } } diff --git a/Sources/Foundation/ISO8601DateFormatter.swift b/Sources/Foundation/ISO8601DateFormatter.swift index 54de843b52..e186994868 100644 --- a/Sources/Foundation/ISO8601DateFormatter.swift +++ b/Sources/Foundation/ISO8601DateFormatter.swift @@ -51,8 +51,8 @@ extension ISO8601DateFormatter { open class ISO8601DateFormatter : Formatter, NSSecureCoding { typealias CFType = CFDateFormatter - private var __cfObject: CFType? - private var _cfObject: CFType { + private final var __cfObject: CFType? + private final var _cfObject: CFType { guard let obj = __cfObject else { let format = CFISO8601DateFormatOptions(rawValue: formatOptions.rawValue) let obj = CFDateFormatterCreateISO8601Formatter(kCFAllocatorSystemDefault, format)! diff --git a/Sources/Foundation/NSCalendar.swift b/Sources/Foundation/NSCalendar.swift index 2a885ed2a8..5b78defcfc 100644 --- a/Sources/Foundation/NSCalendar.swift +++ b/Sources/Foundation/NSCalendar.swift @@ -301,7 +301,7 @@ open class NSCalendar : NSObject, NSCopying, NSSecureCoding { // Methods to return component name strings localized to the calendar's locale - private func _symbols(_ key: CFString) -> [String] { + private final func _symbols(_ key: CFString) -> [String] { let dateFormatter = CFDateFormatterCreate(kCFAllocatorSystemDefault, locale?._cfObject, kCFDateFormatterNoStyle, kCFDateFormatterNoStyle) CFDateFormatterSetProperty(dateFormatter, kCFDateFormatterCalendarKey, _cfObject) let result = (CFDateFormatterCopyProperty(dateFormatter, key) as! NSArray)._swiftObject @@ -310,7 +310,7 @@ open class NSCalendar : NSObject, NSCopying, NSSecureCoding { } } - private func _symbol(_ key: CFString) -> String { + private final func _symbol(_ key: CFString) -> String { let dateFormatter = CFDateFormatterCreate(kCFAllocatorSystemDefault, locale?._bridgeToObjectiveC()._cfObject, kCFDateFormatterNoStyle, kCFDateFormatterNoStyle) CFDateFormatterSetProperty(dateFormatter, kCFDateFormatterCalendarKey, self._cfObject) return (CFDateFormatterCopyProperty(dateFormatter, key) as! NSString)._swiftObject diff --git a/Sources/Foundation/NSCharacterSet.swift b/Sources/Foundation/NSCharacterSet.swift index 757eef31fe..0148771bbe 100644 --- a/Sources/Foundation/NSCharacterSet.swift +++ b/Sources/Foundation/NSCharacterSet.swift @@ -72,7 +72,7 @@ open class NSCharacterSet : NSObject, NSCopying, NSMutableCopying, NSSecureCodin return unsafeBitCast(self, to: CFType.self) } - internal var _cfMutableObject: CFMutableCharacterSet { + internal final var _cfMutableObject: CFMutableCharacterSet { return unsafeBitCast(self, to: CFMutableCharacterSet.self) } diff --git a/Sources/Foundation/NSData.swift b/Sources/Foundation/NSData.swift index 5c468f1f4c..9892d0968b 100644 --- a/Sources/Foundation/NSData.swift +++ b/Sources/Foundation/NSData.swift @@ -77,7 +77,7 @@ open class NSData : NSObject, NSCopying, NSMutableCopying, NSSecureCoding { private var _deallocHandler: _NSDataDeallocator? = _NSDataDeallocator() // for Swift private var _bytes: UnsafeMutablePointer? = nil - internal var _cfObject: CFType { + internal final var _cfObject: CFType { if type(of: self) === NSData.self || type(of: self) === NSMutableData.self { return unsafeBitCast(self, to: CFType.self) } else { @@ -957,7 +957,7 @@ extension CFData : _NSBridgeable, _SwiftBridgeable { // MARK: - open class NSMutableData : NSData { - internal var _cfMutableObject: CFMutableData { return unsafeBitCast(self, to: CFMutableData.self) } + internal final var _cfMutableObject: CFMutableData { return unsafeBitCast(self, to: CFMutableData.self) } public override init() { super.init(bytes: nil, length: 0) diff --git a/Sources/Foundation/NSDate.swift b/Sources/Foundation/NSDate.swift index 1c039bfa54..904e8e1f19 100644 --- a/Sources/Foundation/NSDate.swift +++ b/Sources/Foundation/NSDate.swift @@ -52,7 +52,7 @@ open class NSDate : NSObject, NSCopying, NSSecureCoding, NSCoding { _CFDeinit(self) } - internal var _cfObject: CFType { + internal final var _cfObject: CFType { return unsafeBitCast(self, to: CFType.self) } diff --git a/Sources/Foundation/NSError.swift b/Sources/Foundation/NSError.swift index dc1f57afa1..d5a8f67a07 100644 --- a/Sources/Foundation/NSError.swift +++ b/Sources/Foundation/NSError.swift @@ -50,7 +50,7 @@ public let NSFilePathErrorKey: String = "NSFilePathErrorKey" open class NSError : NSObject, NSCopying, NSSecureCoding, NSCoding { typealias CFType = CFError - internal var _cfObject: CFType { + internal final var _cfObject: CFType { return CFErrorCreate(kCFAllocatorSystemDefault, domain._cfObject, code, nil) } diff --git a/Sources/Foundation/NSKeyedUnarchiver.swift b/Sources/Foundation/NSKeyedUnarchiver.swift index a72b3213cd..e8c4ae5e45 100644 --- a/Sources/Foundation/NSKeyedUnarchiver.swift +++ b/Sources/Foundation/NSKeyedUnarchiver.swift @@ -56,7 +56,7 @@ open class NSKeyedUnarchiver : NSCoder { #endif } - private var _stream : Stream + private final var _stream : Stream private var _flags = UnarchiverFlags(rawValue: 0) private var _containers : Array? = nil private var _objects : Array = [] diff --git a/Sources/Foundation/NSLocale.swift b/Sources/Foundation/NSLocale.swift index 6670fb24c9..e7e35e452b 100644 --- a/Sources/Foundation/NSLocale.swift +++ b/Sources/Foundation/NSLocale.swift @@ -21,7 +21,7 @@ open class NSLocale: NSObject, NSCopying, NSSecureCoding { private var _lock: _NSCFLock = _NSCFLockInit() private var _nullLocale: Bool = false - internal var _cfObject: CFType { + internal final var _cfObject: CFType { return unsafeBitCast(self, to: CFType.self) } diff --git a/Sources/Foundation/NSNumber.swift b/Sources/Foundation/NSNumber.swift index 38e89043ec..883a44c2ee 100644 --- a/Sources/Foundation/NSNumber.swift +++ b/Sources/Foundation/NSNumber.swift @@ -609,7 +609,7 @@ open class NSNumber : NSValue { private var _base = _CFInfo(typeID: CFNumberGetTypeID()) private var _pad: UInt64 = 0 - internal var _cfObject: CFType { + internal final var _cfObject: CFType { return unsafeBitCast(self, to: CFType.self) } @@ -1088,7 +1088,7 @@ open class NSNumber : NSValue { } } - internal func _getValue(_ valuePtr: UnsafeMutableRawPointer, forType type: CFNumberType) -> Bool { + internal final func _getValue(_ valuePtr: UnsafeMutableRawPointer, forType type: CFNumberType) -> Bool { switch type { case kCFNumberSInt8Type: valuePtr.assumingMemoryBound(to: Int8.self).pointee = int8Value diff --git a/Sources/Foundation/NSRegularExpression.swift b/Sources/Foundation/NSRegularExpression.swift index 836040fe15..24adba513a 100644 --- a/Sources/Foundation/NSRegularExpression.swift +++ b/Sources/Foundation/NSRegularExpression.swift @@ -29,7 +29,7 @@ extension NSRegularExpression { open class NSRegularExpression: NSObject, NSCopying, NSSecureCoding { internal var _internalStorage: AnyObject - internal var _internal: _CFRegularExpression { + internal final var _internal: _CFRegularExpression { unsafeBitCast(_internalStorage, to: _CFRegularExpression.self) } diff --git a/Sources/Foundation/NSTimeZone.swift b/Sources/Foundation/NSTimeZone.swift index c2ee5350fe..df42999316 100644 --- a/Sources/Foundation/NSTimeZone.swift +++ b/Sources/Foundation/NSTimeZone.swift @@ -18,7 +18,7 @@ open class NSTimeZone : NSObject, NSCopying, NSSecureCoding, NSCoding { private var _periods: UnsafeMutableRawPointer? = nil private var _periodCnt = Int32(0) - internal var _cfObject: CFType { + internal final var _cfObject: CFType { return unsafeBitCast(self, to: CFType.self) } diff --git a/Sources/Foundation/NSURL.swift b/Sources/Foundation/NSURL.swift index bfe77f6de8..38c260d17d 100644 --- a/Sources/Foundation/NSURL.swift +++ b/Sources/Foundation/NSURL.swift @@ -93,7 +93,7 @@ open class NSURL : NSObject, NSSecureCoding, NSCopying { internal var _range8 = NSRange(location: 0, length: 0) internal var _range9 = NSRange(location: 0, length: 0) - internal var _cfObject : CFType { + internal final var _cfObject : CFType { if type(of: self) === NSURL.self { return unsafeBitCast(self, to: CFType.self) } else { diff --git a/Sources/Foundation/NSURLComponents.swift b/Sources/Foundation/NSURLComponents.swift index 602053660e..7b495c76cb 100644 --- a/Sources/Foundation/NSURLComponents.swift +++ b/Sources/Foundation/NSURLComponents.swift @@ -12,7 +12,7 @@ open class NSURLComponents: NSObject, NSCopying { private let _componentsStorage: AnyObject! - private var _components: CFURLComponents! { unsafeBitCast(_componentsStorage, to: CFURLComponents?.self) } + private final var _components: CFURLComponents! { unsafeBitCast(_componentsStorage, to: CFURLComponents?.self) } open override func copy() -> Any { return copy(with: nil) @@ -298,7 +298,7 @@ open class NSURLComponents: NSObject, NSCopying { return NSRange(_CFURLComponentsGetRangeOfFragment(_components)) } - private func mapQueryItemsFromArray(array: CFArray) -> [URLQueryItem] { + private final func mapQueryItemsFromArray(array: CFArray) -> [URLQueryItem] { let count = CFArrayGetCount(array) return (0.. String? { + private final func _getFormatterAttribute(_ formatter: CFNumberFormatter, attributeName: CFString) -> String? { return CFNumberFormatterCopyProperty(formatter, attributeName) as? String } diff --git a/Sources/Foundation/Port.swift b/Sources/Foundation/Port.swift index cc13055717..8a69b1be6c 100644 --- a/Sources/Foundation/Port.swift +++ b/Sources/Foundation/Port.swift @@ -476,7 +476,7 @@ open class SocketPort : Port { self.init(protocolFamily: PF_INET, socketType: SOCK_STREAM, protocol: IPPROTO_TCP, address: data) } - private func createNonuniquedCore(from socket: CFSocket, protocolFamily family: Int32, socketType type: Int32, protocol: Int32) { + private final func createNonuniquedCore(from socket: CFSocket, protocolFamily family: Int32, socketType type: Int32, protocol: Int32) { self.core = Core(isUniqued: false) let address = CFSocketCopyAddress(socket)._swiftObject core.signature = Signature(address: LocalAddress(address), protocolFamily: family, socketType: type, protocol: `protocol`) @@ -732,7 +732,7 @@ open class SocketPort : Port { // Sending and receiving: - fileprivate func socketDidAccept(_ socket: CFSocket?, _ type: CFSocketCallBackType, _ address: CFData?, _ data: UnsafeRawPointer?) { + fileprivate final func socketDidAccept(_ socket: CFSocket?, _ type: CFSocketCallBackType, _ address: CFData?, _ data: UnsafeRawPointer?) { guard let handle = data?.assumingMemoryBound(to: SocketNativeHandle.self), let address = address else { return @@ -753,7 +753,7 @@ open class SocketPort : Port { } } - private func addToLoopsAssumingLockHeld(_ socket: CFSocket) { + private final func addToLoopsAssumingLockHeld(_ socket: CFSocket) { guard let source = CFSocketCreateRunLoopSource(nil, socket, 600) else { return } @@ -772,7 +772,7 @@ open class SocketPort : Port { case port = 2 } - fileprivate func socketDidReceiveData(_ socket: CFSocket?, _ type: CFSocketCallBackType, _ address: CFData?, _ dataPointer: UnsafeRawPointer?) { + fileprivate final func socketDidReceiveData(_ socket: CFSocket?, _ type: CFSocketCallBackType, _ address: CFData?, _ dataPointer: UnsafeRawPointer?) { guard let socket = socket, let dataPointer = dataPointer else { return } let socketKey = ObjectIdentifier(socket) @@ -839,7 +839,7 @@ open class SocketPort : Port { lock.unlock() // Release lock from above ⬆ } - fileprivate func socketDidReceiveDatagram(_ socket: CFSocket?, _ type: CFSocketCallBackType, _ address: CFData?, _ data: UnsafeRawPointer?) { + fileprivate final func socketDidReceiveDatagram(_ socket: CFSocket?, _ type: CFSocketCallBackType, _ address: CFData?, _ data: UnsafeRawPointer?) { guard let address = address?._swiftObject, let data = data else { return @@ -859,7 +859,7 @@ open class SocketPort : Port { static let offsetOfSignatureAddressLength = 15 } - private func handleMessage(_ message: Data, from address: Data, socket: CFSocket?) { + private final func handleMessage(_ message: Data, from address: Data, socket: CFSocket?) { guard message.count > 24, let delegate = delegate() else { return } let portMessage = message.withUnsafeBytes { (messageBuffer) -> PortMessage? in guard SocketPort.magicNumber == messageBuffer.load(fromByteOffset: Structure.offsetOfMagicNumber, as: UInt32.self).bigEndian, @@ -1027,7 +1027,7 @@ open class SocketPort : Port { private static let sendingSocketsLock = NSLock() private static var sendingSockets: [SocketKind: CFSocket] = [:] - private func sendingSocket(for port: SocketPort, before time: TimeInterval) -> CFSocket? { + private final func sendingSocket(for port: SocketPort, before time: TimeInterval) -> CFSocket? { let signature = port.core.signature! let socketKind = signature.socketKind diff --git a/Sources/Foundation/Process.swift b/Sources/Foundation/Process.swift index b264b286e1..8d4834320e 100644 --- a/Sources/Foundation/Process.swift +++ b/Sources/Foundation/Process.swift @@ -350,13 +350,13 @@ open class Process: NSObject { } private var _runLoopSourceContextStorage = NonexportedCFRunLoopSourceContextStorage() - private var runLoopSourceContext: CFRunLoopSourceContext? { + private final var runLoopSourceContext: CFRunLoopSourceContext? { get { _runLoopSourceContextStorage.value } set { _runLoopSourceContextStorage.value = newValue } } private var _runLoopSourceStorage = NonexportedCFRunLoopSourceStorage() - private var runLoopSource: CFRunLoopSource? { + private final var runLoopSource: CFRunLoopSource? { get { _runLoopSourceStorage.value } set { _runLoopSourceStorage.value = newValue } } diff --git a/Sources/Foundation/PropertyListSerialization.swift b/Sources/Foundation/PropertyListSerialization.swift index e34d7bd98a..7f742a6a8e 100644 --- a/Sources/Foundation/PropertyListSerialization.swift +++ b/Sources/Foundation/PropertyListSerialization.swift @@ -76,7 +76,7 @@ open class PropertyListSerialization : NSObject { } #if !os(WASI) - internal class func propertyList(with stream: CFReadStream, options opt: ReadOptions, format: UnsafeMutablePointer ?) throws -> Any { + internal final class func propertyList(with stream: CFReadStream, options opt: ReadOptions, format: UnsafeMutablePointer ?) throws -> Any { var fmt = kCFPropertyListBinaryFormat_v1_0 var error: Unmanaged? = nil let decoded = withUnsafeMutablePointer(to: &fmt) { (outFmt: UnsafeMutablePointer) -> AnyObject? in diff --git a/Sources/Foundation/RunLoop.swift b/Sources/Foundation/RunLoop.swift index b90fcd5e1c..de87902c94 100644 --- a/Sources/Foundation/RunLoop.swift +++ b/Sources/Foundation/RunLoop.swift @@ -58,7 +58,7 @@ internal func _NSRunLoopNew(_ cf: CFRunLoop) -> Unmanaged { open class RunLoop: NSObject { internal var _cfRunLoopStorage : AnyObject! - internal var _cfRunLoop: CFRunLoop! { + internal final var _cfRunLoop: CFRunLoop! { get { unsafeBitCast(_cfRunLoopStorage, to: CFRunLoop?.self) } set { _cfRunLoopStorage = newValue } } @@ -98,7 +98,7 @@ open class RunLoop: NSObject { return _cfRunLoop } #else - internal var currentCFRunLoop: CFRunLoop { _cfRunLoop } + internal final var currentCFRunLoop: CFRunLoop { _cfRunLoop } @available(*, unavailable, message: "Core Foundation is not available on your platform.") open func getCFRunLoop() -> Never { diff --git a/Sources/Foundation/Stream.swift b/Sources/Foundation/Stream.swift index 328e60cfdb..3ea8a9d01f 100644 --- a/Sources/Foundation/Stream.swift +++ b/Sources/Foundation/Stream.swift @@ -109,7 +109,7 @@ open class InputStream: Stream { } internal let _streamStorage: AnyObject! - internal var _stream: CFReadStream { unsafeBitCast(_streamStorage, to: CFReadStream.self) } + internal final var _stream: CFReadStream { unsafeBitCast(_streamStorage, to: CFReadStream.self) } // reads up to length bytes into the supplied buffer, which must be at least of size len. Returns the actual number of bytes read. open func read(_ buffer: UnsafeMutablePointer, maxLength len: Int) -> Int { @@ -131,10 +131,6 @@ open class InputStream: Stream { return CFReadStreamHasBytesAvailable(_stream) } - fileprivate init(readStream: CFReadStream) { - _streamStorage = readStream - } - public init(data: Data) { _streamStorage = CFReadStreamCreateWithData(kCFAllocatorSystemDefault, data._cfObject) } @@ -186,7 +182,7 @@ open class InputStream: Stream { open class OutputStream : Stream { internal let _streamStorage: AnyObject! - internal var _stream: CFWriteStream { unsafeBitCast(_streamStorage, to: CFWriteStream.self) } + internal final var _stream: CFWriteStream { unsafeBitCast(_streamStorage, to: CFWriteStream.self) } // writes the bytes from the specified buffer to the stream up to len bytes. Returns the number of bytes actually written. open func write(_ buffer: UnsafePointer, maxLength len: Int) -> Int { @@ -197,10 +193,6 @@ open class OutputStream : Stream { open var hasSpaceAvailable: Bool { return CFWriteStreamCanAcceptBytes(_stream) } - - fileprivate init(writeStream: CFWriteStream) { - _streamStorage = writeStream - } // NOTE: on Darwin this is 'open class func toMemory() -> Self' required public init(toMemory: ()) { diff --git a/Sources/Foundation/Thread.swift b/Sources/Foundation/Thread.swift index 9f2f6a1344..7fc74fb160 100644 --- a/Sources/Foundation/Thread.swift +++ b/Sources/Foundation/Thread.swift @@ -207,7 +207,7 @@ open class Thread : NSObject { private let _attrStorage = NonexportedAttrStorage() - internal var _attr: _CFThreadAttributes { + internal final var _attr: _CFThreadAttributes { get { _attrStorage.value } set { _attrStorage.value = newValue } } diff --git a/Sources/Foundation/Timer.swift b/Sources/Foundation/Timer.swift index b93b45f7e8..83a3efa0de 100644 --- a/Sources/Foundation/Timer.swift +++ b/Sources/Foundation/Timer.swift @@ -16,7 +16,7 @@ internal func __NSFireTimer(_ timer: CFRunLoopTimer?, info: UnsafeMutableRawPoin } open class Timer : NSObject { - internal var _cfObject: CFRunLoopTimer { + internal final var _cfObject: CFRunLoopTimer { get { return _timer! } @@ -26,7 +26,7 @@ open class Timer : NSObject { } internal var _timerStorage: AnyObject? - internal var _timer: CFRunLoopTimer? { unsafeBitCast(_timerStorage, to: CFRunLoopTimer?.self) } // has to be optional because this is a chicken/egg problem with initialization in swift + internal final var _timer: CFRunLoopTimer? { unsafeBitCast(_timerStorage, to: CFRunLoopTimer?.self) } // has to be optional because this is a chicken/egg problem with initialization in swift internal var _fire: (Timer) -> Void = { (_: Timer) in } /// Alternative API for timer creation with a block.