diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 434c18ac..ee31cf80 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,7 @@ on: jobs: pod-lint: name: Pod Lint - runs-on: macOS-11 + runs-on: macOS-13 steps: - uses: ruby/setup-ruby@v1 with: @@ -19,34 +19,17 @@ jobs: - name: Bundle Install run: bundle install - name: Select Xcode Version - run: sudo xcode-select --switch /Applications/Xcode_11.7.app/Contents/Developer + run: sudo xcode-select --switch /Applications/Xcode_15.0.1.app/Contents/Developer - name: Lint Podspec - run: bundle exec pod lib lint --verbose --fail-fast --swift-version=5.1 - carthage: - name: Carthage - runs-on: macOS-11 - steps: - - uses: ruby/setup-ruby@v1 - with: - ruby-version: '3.1.3' - - name: Checkout Repo - uses: actions/checkout@v3 - - name: Bundle Install - run: bundle install - - name: Select Xcode Version - run: sudo xcode-select --switch /Applications/Xcode_11.7.app/Contents/Developer - - name: Install Carthage - run: brew outdated carthage || brew upgrade carthage - - name: Build Framework - run: swift package generate-xcodeproj --output generated/ && carthage build --project-directory generated/ --verbose --no-skip-current - spm-11: - name: Build Xcode 11 - runs-on: macOS-11 + run: bundle exec pod lib lint --verbose --fail-fast --swift-version=5.6 + spm-13: + name: Build Xcode 13 + runs-on: macOS-12 strategy: matrix: platforms: [ - 'iOS_13,watchOS_6', - 'macOS_10_15,tvOS_13', + 'iOS_15,watchOS_8', + 'macOS_12,tvOS_15', ] fail-fast: false steps: @@ -58,21 +41,19 @@ jobs: - name: Bundle Install run: bundle install - name: Select Xcode Version - run: sudo xcode-select --switch /Applications/Xcode_11.7.app/Contents/Developer + run: sudo xcode-select --switch /Applications/Xcode_13.4.1.app/Contents/Developer - name: Prepare Simulator Runtimes run: Scripts/github/prepare-simulators.sh ${{ matrix.platforms }} - name: Build and Test Framework run: Scripts/build.swift ${{ matrix.platforms }} - spm-12: - name: Build Xcode 12 - runs-on: macOS-11 - strategy: - matrix: - platforms: [ - 'iOS_14,watchOS_7', - 'macOS_11,tvOS_14', - ] - fail-fast: false + - name: Prepare Coverage Reports + run: ./Scripts/prepare-coverage-reports.sh + - name: Upload Coverage Reports + if: success() + uses: codecov/codecov-action@v3 + spm-13-swift: + name: Swift Build Xcode 13 + runs-on: macOS-12 steps: - uses: ruby/setup-ruby@v1 with: @@ -82,19 +63,17 @@ jobs: - name: Bundle Install run: bundle install - name: Select Xcode Version - run: sudo xcode-select --switch /Applications/Xcode_12.4.app/Contents/Developer - - name: Prepare Simulator Runtimes - run: Scripts/github/prepare-simulators.sh ${{ matrix.platforms }} + run: sudo xcode-select --switch /Applications/Xcode_13.4.1.app/Contents/Developer - name: Build and Test Framework - run: Scripts/build.swift ${{ matrix.platforms }} - spm-13: - name: Build Xcode 13 + run: xcrun swift test -c release -Xswiftc -enable-testing + spm-14: + name: Build Xcode 14 runs-on: macOS-12 strategy: matrix: platforms: [ - 'iOS_15,watchOS_8', - 'macOS_12,tvOS_15', + 'iOS_16,watchOS_9', + 'macOS_12,tvOS_16', ] fail-fast: false steps: @@ -106,7 +85,7 @@ jobs: - name: Bundle Install run: bundle install - name: Select Xcode Version - run: sudo xcode-select --switch /Applications/Xcode_13.4.1.app/Contents/Developer + run: sudo xcode-select --switch /Applications/Xcode_14.0.1.app/Contents/Developer - name: Prepare Simulator Runtimes run: Scripts/github/prepare-simulators.sh ${{ matrix.platforms }} - name: Build and Test Framework @@ -116,8 +95,8 @@ jobs: - name: Upload Coverage Reports if: success() uses: codecov/codecov-action@v3 - spm-13-swift: - name: Swift Build Xcode 13 + spm-14-swift: + name: Swift Build Xcode 14 runs-on: macOS-12 steps: - uses: ruby/setup-ruby@v1 @@ -128,17 +107,18 @@ jobs: - name: Bundle Install run: bundle install - name: Select Xcode Version - run: sudo xcode-select --switch /Applications/Xcode_13.4.1.app/Contents/Developer + run: sudo xcode-select --switch /Applications/Xcode_14.0.1.app/Contents/Developer - name: Build and Test Framework run: xcrun swift test -c release -Xswiftc -enable-testing - spm-14: - name: Build Xcode 14 - runs-on: macOS-12 + spm-15: + name: Build Xcode 15 + runs-on: macos-13 strategy: matrix: platforms: [ - 'iOS_16,watchOS_9', - 'macOS_12,tvOS_16', + 'iOS_17,watchOS_10', + 'macOS_14,tvOS_17', + 'macCatalyst_14' ] fail-fast: false steps: @@ -150,9 +130,7 @@ jobs: - name: Bundle Install run: bundle install - name: Select Xcode Version - run: sudo xcode-select --switch /Applications/Xcode_14.0.1.app/Contents/Developer - - name: Prepare Simulator Runtimes - run: Scripts/github/prepare-simulators.sh ${{ matrix.platforms }} + run: sudo xcode-select --switch /Applications/Xcode_15.0.1.app/Contents/Developer - name: Build and Test Framework run: Scripts/build.swift ${{ matrix.platforms }} - name: Prepare Coverage Reports @@ -160,9 +138,9 @@ jobs: - name: Upload Coverage Reports if: success() uses: codecov/codecov-action@v3 - spm-14-swift: - name: Swift Build Xcode 14 - runs-on: macOS-12 + spm-15-swift: + name: Swift Build Xcode 15 + runs-on: macos-13 steps: - uses: ruby/setup-ruby@v1 with: @@ -172,6 +150,6 @@ jobs: - name: Bundle Install run: bundle install - name: Select Xcode Version - run: sudo xcode-select --switch /Applications/Xcode_14.0.1.app/Contents/Developer + run: sudo xcode-select --switch /Applications/Xcode_15.0.1.app/Contents/Developer - name: Build and Test Framework run: xcrun swift test -c release -Xswiftc -enable-testing diff --git a/CacheAdvance.podspec b/CacheAdvance.podspec index d382d39f..0fe9745f 100644 --- a/CacheAdvance.podspec +++ b/CacheAdvance.podspec @@ -1,15 +1,15 @@ Pod::Spec.new do |s| s.name = 'CacheAdvance' - s.version = '1.2.5' + s.version = '2.0.0' s.license = 'Apache License, Version 2.0' s.summary = 'A performant cache for logging systems. CacheAdvance persists log events 30x faster than SQLite.' s.homepage = 'https://github.com/dfed/CacheAdvance' s.authors = 'Dan Federman' s.source = { :git => 'https://github.com/dfed/CacheAdvance.git', :tag => s.version } - s.swift_version = '5.1' + s.swift_version = '5.6' s.source_files = 'Sources/**/*.{swift}', 'Sources/**/*.{h,m}' - s.ios.deployment_target = '12.0' - s.tvos.deployment_target = '12.0' - s.watchos.deployment_target = '5.0' - s.macos.deployment_target = '10.14' + s.ios.deployment_target = '13.0' + s.tvos.deployment_target = '13.0' + s.watchos.deployment_target = '6.0' + s.macos.deployment_target = '10.15' end diff --git a/Package.swift b/Package.swift index a592134c..2c61d110 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.1 +// swift-tools-version:5.6 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription @@ -6,10 +6,11 @@ import PackageDescription let package = Package( name: "CacheAdvance", platforms: [ - .iOS(.v12), - .tvOS(.v12), - .watchOS(.v5), - .macOS(.v10_14), + .iOS(.v13), + .tvOS(.v13), + .watchOS(.v6), + .macOS(.v10_15), + .macCatalyst(.v13), ], products: [ .library( @@ -24,7 +25,6 @@ let package = Package( targets: [ .target( name: "CacheAdvance", - dependencies: ["SwiftTryCatch"], swiftSettings: [.define("SWIFT_PACKAGE_MANAGER")] ), .testTarget( @@ -44,18 +44,5 @@ let package = Package( name: "CADCacheAdvanceTests", dependencies: ["CADCacheAdvance", "LorumIpsum"] ), - .target( - name: "SwiftTryCatch", - dependencies: [], - publicHeadersPath: "./", - // Make Objective-C exceptions not leak, since we can now recover from them. - // For more info, see https://clang.llvm.org/docs/AutomaticReferenceCounting.html#exceptions - swiftSettings: [SwiftSetting.define("-fobjc-arc-exceptions")] - ), - .testTarget( - name: "SwiftTryCatchTests", - dependencies: ["SwiftTryCatch"] - ) - ], - swiftLanguageVersions: [.v5] + ] ) diff --git a/Package@swift-5.7.swift b/Package@swift-5.7.swift new file mode 100644 index 00000000..01533b86 --- /dev/null +++ b/Package@swift-5.7.swift @@ -0,0 +1,48 @@ +// swift-tools-version:5.7 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "CacheAdvance", + platforms: [ + .iOS(.v13), + .tvOS(.v13), + .watchOS(.v6), + .macOS(.v10_15), + .macCatalyst(.v13), + ], + products: [ + .library( + name: "CacheAdvance", + targets: ["CacheAdvance"] + ), + .library( + name: "CADCacheAdvance", + targets: ["CADCacheAdvance"] + ) + ], + targets: [ + .target( + name: "CacheAdvance", + swiftSettings: [.define("SWIFT_PACKAGE_MANAGER")] + ), + .testTarget( + name: "CacheAdvanceTests", + dependencies: ["CacheAdvance", "LorumIpsum"] + ), + .target( + name: "CADCacheAdvance", + dependencies: ["CacheAdvance"], + swiftSettings: [.define("SWIFT_PACKAGE_MANAGER")] + ), + .target( + name: "LorumIpsum", + dependencies: [] + ), + .testTarget( + name: "CADCacheAdvanceTests", + dependencies: ["CADCacheAdvance", "LorumIpsum"] + ), + ] +) diff --git a/Package@swift-5.8.swift b/Package@swift-5.8.swift new file mode 100644 index 00000000..a1d804bb --- /dev/null +++ b/Package@swift-5.8.swift @@ -0,0 +1,48 @@ +// swift-tools-version:5.8 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "CacheAdvance", + platforms: [ + .iOS(.v13), + .tvOS(.v13), + .watchOS(.v6), + .macOS(.v10_15), + .macCatalyst(.v13), + ], + products: [ + .library( + name: "CacheAdvance", + targets: ["CacheAdvance"] + ), + .library( + name: "CADCacheAdvance", + targets: ["CADCacheAdvance"] + ) + ], + targets: [ + .target( + name: "CacheAdvance", + swiftSettings: [.define("SWIFT_PACKAGE_MANAGER")] + ), + .testTarget( + name: "CacheAdvanceTests", + dependencies: ["CacheAdvance", "LorumIpsum"] + ), + .target( + name: "CADCacheAdvance", + dependencies: ["CacheAdvance"], + swiftSettings: [.define("SWIFT_PACKAGE_MANAGER")] + ), + .target( + name: "LorumIpsum", + dependencies: [] + ), + .testTarget( + name: "CADCacheAdvanceTests", + dependencies: ["CADCacheAdvance", "LorumIpsum"] + ), + ] +) diff --git a/Package@swift-5.9.swift b/Package@swift-5.9.swift new file mode 100644 index 00000000..fcb2d7b9 --- /dev/null +++ b/Package@swift-5.9.swift @@ -0,0 +1,49 @@ +// swift-tools-version:5.9 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "CacheAdvance", + platforms: [ + .iOS(.v13), + .tvOS(.v13), + .watchOS(.v6), + .macOS(.v10_15), + .macCatalyst(.v13), + .visionOS(.v1) + ], + products: [ + .library( + name: "CacheAdvance", + targets: ["CacheAdvance"] + ), + .library( + name: "CADCacheAdvance", + targets: ["CADCacheAdvance"] + ) + ], + targets: [ + .target( + name: "CacheAdvance", + swiftSettings: [.define("SWIFT_PACKAGE_MANAGER")] + ), + .testTarget( + name: "CacheAdvanceTests", + dependencies: ["CacheAdvance", "LorumIpsum"] + ), + .target( + name: "CADCacheAdvance", + dependencies: ["CacheAdvance"], + swiftSettings: [.define("SWIFT_PACKAGE_MANAGER")] + ), + .target( + name: "LorumIpsum", + dependencies: [] + ), + .testTarget( + name: "CADCacheAdvanceTests", + dependencies: ["CADCacheAdvance", "LorumIpsum"] + ), + ] +) diff --git a/README.md b/README.md index 62158629..eb19909b 100644 --- a/README.md +++ b/README.md @@ -79,12 +79,12 @@ The first 64bytes of a CacheAdvance is reserved for storing metadata about the f ## Requirements -* Xcode 11.2 or later. -* iOS 12 or later. -* tvOS 12 or later. -* watchOS 5 or later. -* macOS 10.14 or later. -* Swift 5.0 or later. +* Xcode 12.4 or later. +* iOS 13 or later. +* tvOS 13 or later. +* watchOS 6 or later. +* macOS 10.15 or later. +* Swift 5.6 or later. ## Installation @@ -94,7 +94,7 @@ To install CacheAdvance in your iOS project with [Swift Package Manager](https:/ ```swift dependencies: [ - .package(url: "https://github.com/dfed/CacheAdvance", from: "1.0.0"), + .package(url: "https://github.com/dfed/CacheAdvance", from: "2.0.0"), ] ``` @@ -103,20 +103,10 @@ dependencies: [ To install CacheAdvance in your iOS project with [CocoaPods](http://cocoapods.org), add the following to your `Podfile`: ``` -platform :ios, '12.0' -pod 'CacheAdvance', '~> 1.0' +platform :ios, '13.0' +pod 'CacheAdvance', '~> 2.0' ``` -### Carthage - -To install CacheAdvance in your iOS project with [Carthage](https://github.com/Carthage/Carthage), add the following to your `Cartfile`: - -```ogdl -github "dfed/CacheAdvance" -``` - -Run `carthage` to build the framework and drag the built `CacheAdvance.framework` into your Xcode project. - ### Submodules To use git submodules, checkout the submodule with `git submodule add git@github.com:dfed/CacheAdvance.git`, drag CacheAdvance.xcodeproj to your project, and add CacheAdvance as a build dependency. diff --git a/Scripts/build.swift b/Scripts/build.swift index c5a3c814..61e676d5 100755 --- a/Scripts/build.swift +++ b/Scripts/build.swift @@ -25,18 +25,24 @@ enum Platform: String, CaseIterable, CustomStringConvertible { case iOS_14 case iOS_15 case iOS_16 + case iOS_17 case tvOS_13 case tvOS_14 case tvOS_15 case tvOS_16 + case tvOS_17 case macOS_10_15 case macOS_11 case macOS_12 case macOS_13 + case macOS_14 + case macCatalyst_13 + case macCatalyst_14 case watchOS_6 case watchOS_7 case watchOS_8 case watchOS_9 + case watchOS_10 var destination: String { switch self { @@ -48,6 +54,8 @@ enum Platform: String, CaseIterable, CustomStringConvertible { return "platform=iOS Simulator,OS=15.5,name=iPad Pro (12.9-inch) (5th generation)" case .iOS_16: return "platform=iOS Simulator,OS=16.0,name=iPad Pro (12.9-inch) (5th generation)" + case .iOS_17: + return "platform=iOS Simulator,OS=17.0.1,name=iPad Pro (12.9-inch) (6th generation)" case .tvOS_13: return "platform=tvOS Simulator,OS=13.4,name=Apple TV" @@ -57,11 +65,16 @@ enum Platform: String, CaseIterable, CustomStringConvertible { return "platform=tvOS Simulator,OS=15.4,name=Apple TV" case .tvOS_16: return "platform=tvOS Simulator,OS=16.0,name=Apple TV" + case .tvOS_17: + return "platform=tvOS Simulator,OS=17.0,name=Apple TV" case .macOS_10_15, .macOS_11, .macOS_12, - .macOS_13: + .macOS_13, + .macOS_14, + .macCatalyst_13, + .macCatalyst_14: return "platform=OS X" case .watchOS_6: @@ -72,6 +85,8 @@ enum Platform: String, CaseIterable, CustomStringConvertible { return "OS=8.5,name=Apple Watch Series 6 - 44mm" case .watchOS_9: return "OS=9.0,name=Apple Watch Series 7 (45mm)" + case .watchOS_10: + return "OS=10.0,name=Apple Watch Series 7 (45mm)" } } @@ -80,13 +95,15 @@ enum Platform: String, CaseIterable, CustomStringConvertible { case .iOS_13, .iOS_14, .iOS_15, - .iOS_16: + .iOS_16, + .iOS_17: return "iphonesimulator" case .tvOS_13, .tvOS_14, .tvOS_15, - .tvOS_16: + .tvOS_16, + .tvOS_17: return "appletvsimulator" case .macOS_10_15: @@ -97,11 +114,18 @@ enum Platform: String, CaseIterable, CustomStringConvertible { return "macosx12.3" case .macOS_13: return "macosx13.0" + case .macOS_14: + return "macosx14.0" + case .macCatalyst_13: + return "macosx13.0" + case .macCatalyst_14: + return "macosx14.0" case .watchOS_6, .watchOS_7, .watchOS_8, - .watchOS_9: + .watchOS_9, + .watchOS_10: return "watchsimulator" } } @@ -112,20 +136,26 @@ enum Platform: String, CaseIterable, CustomStringConvertible { .iOS_14, .iOS_15, .iOS_16, + .iOS_17, .tvOS_13, .tvOS_14, .tvOS_15, .tvOS_16, + .tvOS_17, .macOS_10_15, .macOS_11, .macOS_12, - .macOS_13: + .macOS_13, + .macOS_14, + .macCatalyst_13, + .macCatalyst_14: return true case .watchOS_6, .watchOS_7, .watchOS_8, - .watchOS_9: + .watchOS_9, + .watchOS_10: // watchOS does not support unit testing (yet?). return false } @@ -145,12 +175,18 @@ enum Platform: String, CaseIterable, CustomStringConvertible { case .iOS_15, .iOS_16, + .iOS_17, .tvOS_15, .tvOS_16, + .tvOS_17, .macOS_12, .macOS_13, + .macOS_14, + .macCatalyst_13, + .macCatalyst_14, .watchOS_8, - .watchOS_9: + .watchOS_9, + .watchOS_10: // Xcode 13+ do not require xcodeproj generation return false } diff --git a/Sources/CacheAdvance/FileHandleExtensions.swift b/Sources/CacheAdvance/FileHandleExtensions.swift index c597da3e..6d666134 100644 --- a/Sources/CacheAdvance/FileHandleExtensions.swift +++ b/Sources/CacheAdvance/FileHandleExtensions.swift @@ -29,48 +29,32 @@ extension FileHandle { } else { return Data() } - } else if #available(iOS 13.0, tvOS 13.0, watchOS 6.2, macOS 10.15, *) { - return try __readDataUp(toLength: length) } else { - return try ObjectiveC.unsafe { readData(ofLength: length) } + return try __readDataUp(toLength: length) } } /// A method to write data to a file handle that is safe to call in Swift from any operation system version. func write(data: Data) throws { if #available(iOS 13.4, tvOS 13.4, watchOS 6.2, macOS 10.15.4, *) { - return try write(contentsOf: data) - } else if #available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *) { - return try __write(data, error: ()) + try write(contentsOf: data) } else { - return try ObjectiveC.unsafe { write(data) } + try __write(data, error: ()) } } /// A method to seek on a file handle that is safe to call in Swift from any operation system version. func seek(to offset: UInt64) throws { - if #available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *) { - return try seek(toOffset: offset) - } else { - return try ObjectiveC.unsafe { seek(toFileOffset: offset) } - } + try seek(toOffset: offset) } /// A method to close a file handle that is safe to call in Swift from any operation system version. func closeHandle() throws { - if #available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *) { - return try close() - } else { - return try ObjectiveC.unsafe { closeFile() } - } + try close() } /// A method to truncate a file handle that is safe to call in Swift from any operation system version. func truncate(at offset: UInt64) throws { - if #available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *) { - return try truncate(atOffset: offset) - } else { - return try ObjectiveC.unsafe { truncateFile(atOffset: offset) } - } + try truncate(atOffset: offset) } } diff --git a/Sources/CacheAdvance/ObjectiveC.swift b/Sources/CacheAdvance/ObjectiveC.swift deleted file mode 100644 index ac9866fc..00000000 --- a/Sources/CacheAdvance/ObjectiveC.swift +++ /dev/null @@ -1,58 +0,0 @@ -// -// Created by Dan Federman on 12/20/19. -// Copyright © 2019 Dan Federman. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -//    http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -import Foundation -#if SWIFT_PACKAGE_MANAGER -// Swift Package Manager defines multiple modules, while other distribution mechanisms do not. -// We only need to import SwiftTryCatch if this project is being built with Swift Package Manager. -import SwiftTryCatch -#endif - -/// A class that enables Objective-C code that would normally be unsafe to call from Swift to be safe. -final class ObjectiveC { - - /// Attempts to execute work that may raise an Objective-C exception. - /// If an exception is raised, it is caught, and then thrown as a Swift `Error`. - /// - /// - Parameter work: Work that may raise an Objective-C exception. - static func unsafe(_ work: () -> T) throws -> T { - var result: Result = .failure(ObjectiveCTryFailure()) - SwiftTryCatch.try({ - result = .success(work()) - }, catch: { exception in - result = .failure(ObjectiveCError( - exceptionName: exception.name, - reason: exception.reason)) - }) - - switch result { - case let .success(value): - return value - case let .failure(error): - throw error - } - } -} - -/// A sentinel error to indicate that our Objective-C try/catch block didn't work as intended. -struct ObjectiveCTryFailure: Error {} - -/// A `throw`able NSException. -struct ObjectiveCError: Error { - let exceptionName: NSExceptionName - let reason: String? -} diff --git a/Sources/SwiftTryCatch/SwiftTryCatch.h b/Sources/SwiftTryCatch/SwiftTryCatch.h deleted file mode 100644 index 875f8b7f..00000000 --- a/Sources/SwiftTryCatch/SwiftTryCatch.h +++ /dev/null @@ -1,33 +0,0 @@ -// -// SwiftTryCatch.h -// -// Created by William Falcon on 10/10/14. -// Copyright (c) 2014 William Falcon. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -//    http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -#import - -NS_ASSUME_NONNULL_BEGIN - -@interface SwiftTryCatch : NSObject - -/** - Provides try catch functionality for swift by wrapping around Objective-C - */ - -+ (void)try:(__attribute__((noescape)) void(^ _Nonnull)(void))try catch:(__attribute__((noescape)) void(^ _Nonnull)(NSException *exception))catch; -@end - -NS_ASSUME_NONNULL_END diff --git a/Sources/SwiftTryCatch/SwiftTryCatch.m b/Sources/SwiftTryCatch/SwiftTryCatch.m deleted file mode 100644 index 4cb0bccb..00000000 --- a/Sources/SwiftTryCatch/SwiftTryCatch.m +++ /dev/null @@ -1,37 +0,0 @@ -// -// SwiftTryCatch.h -// -// Created by William Falcon on 10/10/14. -// Copyright (c) 2014 William Falcon. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -//    http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -#import "SwiftTryCatch.h" - -@implementation SwiftTryCatch - -/** - Provides try catch functionality for swift by wrapping around Objective-C - */ -+ (void)try:(__attribute__((noescape)) void(^ _Nonnull)(void))try catch:(__attribute__((noescape)) void(^ _Nonnull)(NSException *exception))catch; -{ - @try { - try(); - } - @catch (NSException *exception) { - catch(exception); - } -} - -@end diff --git a/Tests/CacheAdvanceTests/ObjectiveCTests.swift b/Tests/CacheAdvanceTests/ObjectiveCTests.swift deleted file mode 100644 index e96054e3..00000000 --- a/Tests/CacheAdvanceTests/ObjectiveCTests.swift +++ /dev/null @@ -1,57 +0,0 @@ -// -// SwiftTryCatch.h -// -// Created by Dan Federman on 12/20/19. -// Copyright (c) 2019 Dan Federman. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -//    http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -import Foundation -import XCTest - -@testable import CacheAdvance - -final class ObjectiveCTests: XCTestCase { - - func test_unsafe_throwsObjectiveCExceptionOnRaise() { - let doomedFileHandle = FileHandle(fileDescriptor: 101) - var didThrow = false - do { - _ = try ObjectiveC.unsafe { - // This will raise an exception. - doomedFileHandle.readData(ofLength: 5) - } - } - catch { - didThrow = true - } - XCTAssertTrue(didThrow) - } - - func test_unsafe_doesNotThrowWhenNoExceptionRaise() { - var didThrow = false - do { - _ = try ObjectiveC.unsafe { _ = didThrow } - } - catch { - didThrow = true - } - XCTAssertFalse(didThrow) - } - - func test_unsafe_returnsExpectedValueWhenNoExceptionRaised() { - XCTAssertTrue(try ObjectiveC.unsafe { true }) - } - -} diff --git a/Tests/SwiftTryCatchTests/SwiftTryCatchTests.swift b/Tests/SwiftTryCatchTests/SwiftTryCatchTests.swift deleted file mode 100644 index d067e577..00000000 --- a/Tests/SwiftTryCatchTests/SwiftTryCatchTests.swift +++ /dev/null @@ -1,76 +0,0 @@ -// -// SwiftTryCatch.h -// -// Created by Dan Federman on 12/20/19. -// Copyright (c) 2019 Dan Federman. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -//    http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -import SwiftTryCatch -import XCTest - -final class SwiftTryCatchTests: XCTestCase { - - func test_try_catchesObjectiveCFailure() { - let doomedFileHandle = FileHandle(fileDescriptor: 101) - var didCatch = false - SwiftTryCatch.try({ - // This will raise an exception. - doomedFileHandle.readData(ofLength: 5) - }, catch: { exception in - XCTAssertNotNil(exception) - didCatch = true - }) - XCTAssertTrue(didCatch) - } - - func test_try_stopsExecutingOnRaise() { - let doomedFileHandle = FileHandle(fileDescriptor: 101) - var didStopAfterRaisedException = false - SwiftTryCatch.try({ - didStopAfterRaisedException = true - // This will raise an exception. - doomedFileHandle.readData(ofLength: 5) - didStopAfterRaisedException = false - }, catch: { _ in }) - - XCTAssertTrue(didStopAfterRaisedException) - } - - func test_try_doesNotExecuteCatchIfNoExceptionThrown() { - var didCatch = false - SwiftTryCatch.try({ - // Nothing to do here. - }, catch: { exception in - didCatch = true - }) - XCTAssertFalse(didCatch) - } - - func test_try_executesTryBeforeCatch() { - let doomedFileHandle = FileHandle(fileDescriptor: 101) - var tryExecuteCount = 0 - var catchExecuteCount = 0 - SwiftTryCatch.try({ - tryExecuteCount += 1 - // This will raise an exception. - doomedFileHandle.readData(ofLength: 5) - }, catch: { exception in - XCTAssertEqual(tryExecuteCount, 1) - catchExecuteCount += 1 - }) - XCTAssertEqual(catchExecuteCount, 1) - } - -}