diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 51e9b88..f3d5f66 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,24 +8,24 @@ on: jobs: test: - runs-on: macOS-latest + runs-on: macos-15-arm64 # Apple Silicon strategy: matrix: env: - sdk: iphonesimulator - destination: platform=iOS Simulator,name=iPhone 12 Pro,OS=latest + destination: platform=iOS Simulator,name=iPhone 15 Pro,OS=latest - sdk: macosx - destination: arch=x86_64 + destination: arch=arm64 - sdk: appletvsimulator - destination: platform=tvOS Simulator,name=Apple TV,OS=latest + destination: platform=tvOS Simulator,name=Apple TV 4K (3rd generation),OS=latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - - name: Select Xcode 12.4 - run: sudo xcode-select -s /Applications/Xcode_12.4.app + - name: Select Xcode 16.4 + run: sudo xcode-select -s /Applications/Xcode_16.4.app - name: Generate Xcode Project run: swift package generate-xcodeproj --enable-code-coverage diff --git a/Sources/WeakMapTable/WeakMapTable.swift b/Sources/WeakMapTable/WeakMapTable.swift index b5e74c1..e996334 100644 --- a/Sources/WeakMapTable/WeakMapTable.swift +++ b/Sources/WeakMapTable/WeakMapTable.swift @@ -68,6 +68,13 @@ final public class WeakMapTable where Key: AnyObject { } } + public func removeAll() { + self.lock.lock() + defer { + self.lock.unlock() + } + self.dictionary.removeAll() + } // MARK: Getting and Setting Values without Locking diff --git a/Tests/WeakMapTableTests/WeakMapTableTests.swift b/Tests/WeakMapTableTests/WeakMapTableTests.swift index 344ad89..e1cb70e 100644 --- a/Tests/WeakMapTableTests/WeakMapTableTests.swift +++ b/Tests/WeakMapTableTests/WeakMapTableTests.swift @@ -81,6 +81,23 @@ final class WeakMapTableTests: XCTestCase { XCTAssertNil(weakKey) XCTAssertNil(weakValue) } + + func testRemoveAll() { + let map = WeakMapTable() + let key = KeyObject() + weak var weakValue: ValueObject? + + _ = { + let value = ValueObject() + map.setValue(value, forKey: key) + weakValue = value + + map.removeAll() + }() + + XCTAssertNil(map.value(forKey: key)) + XCTAssertNil(weakValue) + } } private final class KeyObject {