From d21303cc2cb8c79c09aa7c90141426365f636239 Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Fri, 29 Nov 2024 09:42:57 -0500 Subject: [PATCH] Add native bridging support --- Package.swift | 8 ++++++++ Sources/SkipKeychain/Skip/skip.yml | 3 +++ Sources/SkipKeychain/SkipKeychain.swift | 6 +++--- Tests/SkipKeychainTests/SkipKeychainTests.swift | 4 ++-- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Package.swift b/Package.swift index cf6058e..4fb8f4c 100644 --- a/Package.swift +++ b/Package.swift @@ -5,6 +5,7 @@ // Swift Package, Sources, and Tests into an // Android Gradle Project with Kotlin sources and JUnit tests. import PackageDescription +import Foundation let package = Package( name: "skip-keychain", @@ -22,3 +23,10 @@ let package = Package( .testTarget(name: "SkipKeychainTests", dependencies: ["SkipKeychain", .product(name: "SkipTest", package: "skip")], plugins: [.plugin(name: "skipstone", package: "skip")]), ] ) + +if ProcessInfo.processInfo.environment["SKIP_BRIDGE"] ?? "0" != "0" { + package.dependencies += [.package(url: "https://source.skip.tools/skip-bridge.git", "0.0.0"..<"2.0.0")] + package.targets.forEach({ target in + target.dependencies += [.product(name: "SkipBridge", package: "skip-bridge")] + }) +} diff --git a/Sources/SkipKeychain/Skip/skip.yml b/Sources/SkipKeychain/Skip/skip.yml index 51b58f7..9053cbe 100644 --- a/Sources/SkipKeychain/Skip/skip.yml +++ b/Sources/SkipKeychain/Skip/skip.yml @@ -1,6 +1,9 @@ # Configuration file for https://skip.tools project # # Kotlin dependencies and Gradle build options for this module can be configured here +skip: + bridging: true + build: contents: - block: 'dependencies' diff --git a/Sources/SkipKeychain/SkipKeychain.swift b/Sources/SkipKeychain/SkipKeychain.swift index 0f2c7f2..218ae30 100644 --- a/Sources/SkipKeychain/SkipKeychain.swift +++ b/Sources/SkipKeychain/SkipKeychain.swift @@ -3,6 +3,7 @@ // This is free software: you can redistribute and/or modify it // under the terms of the GNU Lesser General Public License 3.0 // as published by the Free Software Foundation https://fsf.org +#if !SKIP_BRIDGE import Foundation #if !SKIP import Security @@ -187,8 +188,7 @@ public struct Keychain { #endif /// Return the set of all stored keys. - public var keys: [String] { - get throws { + public func keys() throws -> [String] { #if !SKIP lock.lock() defer { lock.unlock() } @@ -213,7 +213,6 @@ public struct Keychain { #else return Array(initializePreferences().getAll().keys) #endif - } } /// Remove all stored key value pairs. @@ -292,3 +291,4 @@ public struct KeychainError: Error, CustomStringConvertible { return message } } +#endif diff --git a/Tests/SkipKeychainTests/SkipKeychainTests.swift b/Tests/SkipKeychainTests/SkipKeychainTests.swift index 65db652..bcfe3d3 100644 --- a/Tests/SkipKeychainTests/SkipKeychainTests.swift +++ b/Tests/SkipKeychainTests/SkipKeychainTests.swift @@ -49,9 +49,9 @@ final class SkipKeychainTests: XCTestCase { try skipiOSSimulator() let keychain = Keychain.shared try keychain.removeValue(forKey: key) - try XCTAssertFalse(keychain.keys.contains(key)) + try XCTAssertFalse(keychain.keys().contains(key)) try keychain.set("value", forKey: key) - try XCTAssertTrue(keychain.keys.contains(key)) + try XCTAssertTrue(keychain.keys().contains(key)) } func testBool() throws {