Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions Sources/WeakMapTable/WeakMapTable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ final public class WeakMapTable<Key, Value> where Key: AnyObject {
}
}

public func removeAll() {
self.lock.lock()
defer {
self.lock.unlock()
}
self.dictionary.removeAll()
}

// MARK: Getting and Setting Values without Locking

Expand Down
17 changes: 17 additions & 0 deletions Tests/WeakMapTableTests/WeakMapTableTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,23 @@ final class WeakMapTableTests: XCTestCase {
XCTAssertNil(weakKey)
XCTAssertNil(weakValue)
}

func testRemoveAll() {
let map = WeakMapTable<KeyObject, ValueObject>()
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 {
Expand Down
Loading