From 8f0bb0538bcf48ed566b986268a054802531f10e Mon Sep 17 00:00:00 2001 From: Yehor Popovych Date: Wed, 15 Oct 2025 12:27:31 +0100 Subject: [PATCH] removed objc exports Signed-off-by: Yehor Popovych --- Kronos.xcodeproj/project.pbxproj | 4 -- Sources/DNSResolver.swift | 16 +++----- Sources/NSTimer+ClosureKit.swift | 52 ------------------------ Sources/NTPClient.swift | 2 +- Tests/KronosTests/DNSResolverTests.swift | 2 +- 5 files changed, 8 insertions(+), 68 deletions(-) delete mode 100644 Sources/NSTimer+ClosureKit.swift diff --git a/Kronos.xcodeproj/project.pbxproj b/Kronos.xcodeproj/project.pbxproj index 01c7de0..7099526 100644 --- a/Kronos.xcodeproj/project.pbxproj +++ b/Kronos.xcodeproj/project.pbxproj @@ -11,7 +11,6 @@ 26447D7D1D6E54D400159BEE /* DNSResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26447D741D6E54D400159BEE /* DNSResolver.swift */; }; 26447D7E1D6E54D400159BEE /* InternetAddress.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26447D751D6E54D400159BEE /* InternetAddress.swift */; }; 26447D7F1D6E54D400159BEE /* Data+Bytes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26447D761D6E54D400159BEE /* Data+Bytes.swift */; }; - 26447D801D6E54D400159BEE /* NSTimer+ClosureKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26447D771D6E54D400159BEE /* NSTimer+ClosureKit.swift */; }; 26447D811D6E54D400159BEE /* NTPClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26447D781D6E54D400159BEE /* NTPClient.swift */; }; 26447D821D6E54D400159BEE /* NTPPacket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26447D791D6E54D400159BEE /* NTPPacket.swift */; }; 26447D831D6E54D400159BEE /* NTPProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26447D7A1D6E54D400159BEE /* NTPProtocol.swift */; }; @@ -41,7 +40,6 @@ 26447D741D6E54D400159BEE /* DNSResolver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DNSResolver.swift; sourceTree = ""; }; 26447D751D6E54D400159BEE /* InternetAddress.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InternetAddress.swift; sourceTree = ""; }; 26447D761D6E54D400159BEE /* Data+Bytes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Data+Bytes.swift"; sourceTree = ""; }; - 26447D771D6E54D400159BEE /* NSTimer+ClosureKit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSTimer+ClosureKit.swift"; sourceTree = ""; }; 26447D781D6E54D400159BEE /* NTPClient.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NTPClient.swift; sourceTree = ""; }; 26447D791D6E54D400159BEE /* NTPPacket.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NTPPacket.swift; sourceTree = ""; }; 26447D7A1D6E54D400159BEE /* NTPProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NTPProtocol.swift; sourceTree = ""; }; @@ -118,7 +116,6 @@ 26447D741D6E54D400159BEE /* DNSResolver.swift */, 26447D751D6E54D400159BEE /* InternetAddress.swift */, 26447D761D6E54D400159BEE /* Data+Bytes.swift */, - 26447D771D6E54D400159BEE /* NSTimer+ClosureKit.swift */, 26447D781D6E54D400159BEE /* NTPClient.swift */, 26447D791D6E54D400159BEE /* NTPPacket.swift */, 26447D7A1D6E54D400159BEE /* NTPProtocol.swift */, @@ -249,7 +246,6 @@ 26447D7F1D6E54D400159BEE /* Data+Bytes.swift in Sources */, 26447D841D6E54D400159BEE /* TimeFreeze.swift in Sources */, 26447D821D6E54D400159BEE /* NTPPacket.swift in Sources */, - 26447D801D6E54D400159BEE /* NSTimer+ClosureKit.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Sources/DNSResolver.swift b/Sources/DNSResolver.swift index d0c2b9f..326e816 100644 --- a/Sources/DNSResolver.swift +++ b/Sources/DNSResolver.swift @@ -51,29 +51,25 @@ final class DNSResolver { retain: nil, release: nil, copyDescription: kCopyNoOperation) let hostReference = CFHostCreateWithName(kCFAllocatorDefault, host as CFString).takeUnretainedValue() - resolver.timer = Timer.scheduledTimer(timeInterval: timeout, target: resolver, - selector: #selector(DNSResolver.onTimeout), - userInfo: hostReference, repeats: false) + + resolver.timer = Timer.scheduledTimer(withTimeInterval: timeout, repeats: false) { [unowned resolver] _ in + resolver.onTimeout(hostReference: hostReference) + } CFHostSetClient(hostReference, callback, &clientContext) CFHostScheduleWithRunLoop(hostReference, CFRunLoopGetMain(), CFRunLoopMode.commonModes.rawValue) CFHostStartInfoResolution(hostReference, .addresses, nil) } - @objc - private func onTimeout() { + private func onTimeout(hostReference: CFHost) { defer { self.completion?([]) + self.timer = nil // Manually release the previously retained self. Unmanaged.passUnretained(self).release() } - guard let userInfo = self.timer?.userInfo else { - return - } - - let hostReference = unsafeBitCast(userInfo as AnyObject, to: CFHost.self) CFHostCancelInfoResolution(hostReference, .addresses) CFHostUnscheduleFromRunLoop(hostReference, CFRunLoopGetMain(), CFRunLoopMode.commonModes.rawValue) CFHostSetClient(hostReference, nil, nil) diff --git a/Sources/NSTimer+ClosureKit.swift b/Sources/NSTimer+ClosureKit.swift deleted file mode 100644 index 9c5d4c6..0000000 --- a/Sources/NSTimer+ClosureKit.swift +++ /dev/null @@ -1,52 +0,0 @@ -import Foundation - -typealias CKTimerHandler = (Timer) -> Void - -/// Simple closure implementation on NSTimer scheduling. -/// -/// Example: -/// -/// ```swift -/// BlockTimer.scheduledTimer(withTimeInterval: 1.0) { timer in -/// print("Did something after 1s!") -/// } -/// ``` -final class BlockTimer: NSObject { - - /// Creates and returns a block-based NSTimer object and schedules it on the current run loop. - /// - /// - parameter interval: The number of seconds between firings of the timer. - /// - parameter repeated: If true, the timer will repeatedly reschedule itself until invalidated. If - /// false, the timer will be invalidated after it fires. - /// - parameter handler: The closure that the NSTimer fires. - /// - /// - returns: A new NSTimer object, configured according to the specified parameters. - class func scheduledTimer(withTimeInterval interval: TimeInterval, repeated: Bool = false, - handler: @escaping CKTimerHandler) -> Timer - { - return Timer.scheduledTimer(timeInterval: interval, target: self, - selector: #selector(BlockTimer.invokeFrom(timer:)), - userInfo: TimerClosureWrapper(handler: handler, repeats: repeated), repeats: repeated) - } - - // MARK: Private methods - - @objc - class private func invokeFrom(timer: Timer) { - if let closureWrapper = timer.userInfo as? TimerClosureWrapper { - closureWrapper.handler(timer) - } - } -} - -// MARK: - Private classes - -private final class TimerClosureWrapper { - fileprivate var handler: CKTimerHandler - private var repeats: Bool - - init(handler: @escaping CKTimerHandler, repeats: Bool) { - self.handler = handler - self.repeats = repeats - } -} diff --git a/Sources/NTPClient.swift b/Sources/NTPClient.swift index 322146e..636cb76 100644 --- a/Sources/NTPClient.swift +++ b/Sources/NTPClient.swift @@ -108,7 +108,7 @@ final class NTPClient { completion: UnsafeMutableRawPointer(retainedCallback.toOpaque()) ) - timer = BlockTimer.scheduledTimer(withTimeInterval: timeout, repeated: true) { _ in + timer = Timer.scheduledTimer(withTimeInterval: timeout, repeats: true) { _ in bridgeCallback(nil, TimeInterval.infinity) retainedCallback.release() diff --git a/Tests/KronosTests/DNSResolverTests.swift b/Tests/KronosTests/DNSResolverTests.swift index 3db9564..3574aa3 100644 --- a/Tests/KronosTests/DNSResolverTests.swift +++ b/Tests/KronosTests/DNSResolverTests.swift @@ -5,7 +5,7 @@ final class DNSResolverTests: XCTestCase { func testResolveOneIP() { let expectation = self.expectation(description: "Query host's DNS for a single IP") - DNSResolver.resolve(host: "test.com") { addresses in + DNSResolver.resolve(host: "httpbin.net") { addresses in XCTAssertEqual(addresses.count, 1) expectation.fulfill() }