Skip to content

Commit d8d058b

Browse files
committed
Update to Swift 6 (#6)
* Update to Swift 6 * Move to Swift Testing from XCTest * Update .swiftformat to use Swift 6 ruleset
1 parent ca924b9 commit d8d058b

File tree

11 files changed

+133
-61
lines changed

11 files changed

+133
-61
lines changed

.github/workflows/publish-website.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Sample workflow for building and deploying a Jekyll site to GitHub Pages
2+
name: publish-website
3+
4+
on:
5+
push:
6+
branches: ["main"]
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: read
11+
pages: write
12+
id-token: write
13+
14+
concurrency:
15+
group: "pages"
16+
cancel-in-progress: false
17+
18+
jobs:
19+
build-docc:
20+
runs-on: macos-15
21+
outputs:
22+
artifact-name: docs
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@v4
26+
- name: Build Documentation
27+
run: ./.scripts/build-docs
28+
- name: Compress Documentation
29+
run: zip -r docs.zip docs
30+
- name: Upload Documentation
31+
uses: actions/upload-artifact@v4
32+
with:
33+
name: docs
34+
path: docs.zip
35+
build:
36+
needs: build-docc
37+
runs-on: ubuntu-latest
38+
steps:
39+
- name: Checkout
40+
uses: actions/checkout@v4
41+
- name: Download Documentation
42+
uses: actions/download-artifact@v4
43+
with:
44+
name: docs
45+
path: .
46+
- name: Decompress Documentation
47+
run: unzip docs.zip
48+
- name: Fix README
49+
run: ./.scripts/clean-readme
50+
- name: Setup Pages
51+
uses: actions/configure-pages@v5
52+
- name: Build with Jekyll
53+
uses: actions/jekyll-build-pages@v1
54+
with:
55+
source: ./
56+
destination: ./_site
57+
- name: Upload artifact
58+
uses: actions/upload-pages-artifact@v3
59+
deploy:
60+
environment:
61+
name: github-pages
62+
url: ${{ steps.deployment.outputs.page_url }}
63+
runs-on: ubuntu-latest
64+
needs: build
65+
steps:
66+
- name: Deploy to GitHub Pages
67+
id: deployment
68+
uses: actions/deploy-pages@v4

.github/workflows/spm-build-test.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ on:
88

99
jobs:
1010
build:
11-
12-
runs-on: macos-12
13-
11+
runs-on: macos-15
1412
steps:
1513
- uses: actions/checkout@v3
1614
- name: Build

.scripts/build-docs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
swift package --allow-writing-to-directory docs \
2+
generate-documentation --target WeakReference \
3+
--disable-indexing \
4+
--transform-for-static-hosting \
5+
--hosting-base-path docs \
6+
--output-path docs

.scripts/clean-readme

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tail -n +2 README.md > README-2.md && rm README.md && mv README-2.md README.md

.swiftformat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
--enable isEmpty
22
--disable blankLinesAtEndOfScope, blankLinesAtStartOfScope, redundantNilInit, unusedArguments, redundantParens, wrapMultilineStatementBraces, trailingCommas, braces
3-
--swiftversion 5.6
4-
--header "WeakReference\n{file}\n\nMIT License\n\nCopyright (c) 2021 Varun Santhanam\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the "Software"), to deal\n\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE."
3+
--swiftversion 6.0
4+
--header "WeakReference\n{file}\n\nMIT License\n\nCopyright (c) 2025 Varun Santhanam\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the "Software"), to deal\n\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE."

Package.resolved

Lines changed: 13 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
1-
// swift-tools-version: 5.6
1+
// swift-tools-version: 6.0
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

44
import PackageDescription
55

66
let package = Package(
77
name: "WeakReference",
88
platforms: [
9-
.iOS(.v11),
10-
.macOS(.v10_13),
11-
.tvOS(.v11),
12-
.watchOS(.v4)
9+
.iOS(.v12),
10+
.macOS(.v10_14),
11+
.macCatalyst(.v13),
12+
.tvOS(.v12),
13+
.watchOS(.v5),
14+
.visionOS(.v1)
1315
],
1416
products: [
15-
// Products define the executables and libraries a package produces, and make them visible to other packages.
1617
.library(
1718
name: "WeakReference",
1819
targets: ["WeakReference"]
1920
),
2021
],
2122
dependencies: [
22-
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0")
23+
.package(
24+
url: "https://github.com/swiftlang/swift-docc-plugin.git",
25+
from: "1.4.3"
26+
)
2327
],
2428
targets: [
25-
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
26-
// Targets can depend on other targets in this package, and on products in packages this package depends on.
2729
.target(
2830
name: "WeakReference",
2931
dependencies: []

README.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
[![MIT License](https://img.shields.io/github/license/vsanthanam/WeakReference)](https://github.com/vsanthanam/WeakReference/blob/main/LICENSE)
44
[![Package Releases](https://img.shields.io/github/v/release/vsanthanam/WeakReference)](https://github.com/vsanthanam/WeakReference/releases)
5-
[![Build Results](https://img.shields.io/github/workflow/status/vsanthanam/WeakReference/spm-build-test)](https://img.shields.io/github/workflow/status/vsanthanam/WeakReference/spm-build-test)
6-
[![Swift Version](https://img.shields.io/badge/swift-5.6-critical)](https://swift.org)
7-
[![Supported Platforms](https://img.shields.io/badge/platform-iOS%2011%20%7C%20macOS%2010.13%20%7C%20tvOS%2011%20%7C%20watchOS%204-lightgrey)](https://developer.apple.com)
5+
[![Build Status](https://img.shields.io/github/check-runs/vsanthanam/WeakReference/main)](https://github.com/vsanthanam/WeakReference/actions)
6+
[![Swift Version](https://img.shields.io/badge/swift-6.0-critical)](https://swift.org)
7+
[![Supported Platforms](https://img.shields.io/badge/platform-iOS%2012%20%7C%20macOS%2010.14%20%7C%20tvOS%2012%20%7C%20watchOS%205%20%7C%20visionOS%201-lightgrey)](https://developer.apple.com)
88

99
An existential weak reference.
1010
Use this wrapper class to pass around weakly-referenced instances of an object.
@@ -17,22 +17,24 @@ To add WeakReference as a dependency to an existing Swift package, add the follo
1717

1818
```swift
1919
dependencies: [
20-
.package(url: "https://github.com/vsanthanam/WeakReference.git", .upToNextMajor(from: "1.0.0"))
20+
.package(
21+
url: "https://github.com/vsanthanam/WeakReference.git",
22+
from: "1.0.0"
23+
)
2124
]
2225
```
2326

24-
To add AnyAsyncSequence as a dependency to an Xcode Project:
27+
To add WeakReference as a dependency to an Xcode Project:
2528

26-
* Choose File → Add Packages...
27-
* Enter package URL https://github.com/vsanthanam/WeakReference.git and select your release and of choice.
29+
* Choose `File``Add Packages...`
30+
* Enter package URL `https://github.com/vsanthanam/WeakReference.git` and select your release and of choice.
2831

2932
Other distribution mechanisms like CocoaPods or Carthage may be added in the future.
3033

3134
Additional installation instructions are available on the [Swift Package Index](https://swiftpackageindex.com/vsanthanam/WeakReference)
3235

33-
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fvsanthanam%2FAnyAsyncSequence%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/vsanthanam/AnyAsyncSequence)
34-
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fvsanthanam%2FAnyAsyncSequence%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/vsanthanam/AnyAsyncSequence)
35-
36+
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fvsanthanam%2FWeakReference%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/vsanthanam/WeakReference)
37+
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fvsanthanam%2FWeakReference%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/vsanthanam/WeakReference)
3638

3739
## Usage
3840

Sources/WeakReference/WeakReference.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//
44
// MIT License
55
//
6-
// Copyright (c) 2021 Varun Santhanam
6+
// Copyright (c) 2025 Varun Santhanam
77
// Permission is hereby granted, free of charge, to any person obtaining a copy
88
// of this software and associated documentation files (the Software), to deal
99
//
@@ -23,7 +23,7 @@
2323
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2424
// SOFTWARE.
2525

26-
/// An existential weak reference.
26+
/// A portable weak reference
2727
///
2828
/// Use this wrapper class to pass around weakly-referenced instances of an object.
2929
///
@@ -39,6 +39,7 @@
3939
///
4040
/// assert(weakReference.obj == nil)
4141
/// ```
42+
@available(macOS 10.14, macCatalyst 13.0, iOS 12.0, watchOS 5.0, tvOS 5.0, visionOS 1.0, *)
4243
public final class WeakReference<T: AnyObject> {
4344

4445
/// Create a weak reference to the provided object instance
@@ -49,11 +50,15 @@ public final class WeakReference<T: AnyObject> {
4950

5051
/// A weak reference to the object
5152
public weak var obj: T?
53+
5254
}
5355

5456
/// Create a ``WeakReference`` from an object
5557
/// - Parameter obj: An instance to weakify
5658
/// - Returns: a ``WeakReference`` wrapper containing the provided object
57-
public func weak<T: AnyObject>(_ obj: T) -> WeakReference<T> {
59+
@available(macOS 10.14, macCatalyst 13.0, iOS 12.0, watchOS 5.0, tvOS 5.0, visionOS 1.0, *)
60+
public func weak<T>(
61+
_ obj: T
62+
) -> WeakReference<T> where T: AnyObject {
5863
.init(obj)
5964
}

Tests/WeakReferenceTests/WeakReferenceTests.swift

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//
44
// MIT License
55
//
6-
// Copyright (c) 2021 Varun Santhanam
6+
// Copyright (c) 2025 Varun Santhanam
77
// Permission is hereby granted, free of charge, to any person obtaining a copy
88
// of this software and associated documentation files (the Software), to deal
99
//
@@ -23,23 +23,21 @@
2323
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2424
// SOFTWARE.
2525

26-
@testable import WeakReference
27-
import XCTest
26+
import Testing
27+
import WeakReference
2828

29-
final class WeakTests: XCTestCase {
29+
@Test
30+
func test() throws {
3031

31-
func test() throws {
32+
class MyObject {}
3233

33-
class MyObject {}
34+
var myObject: MyObject? = .init()
3435

35-
var myObject: MyObject? = .init()
36+
let weakReference = weak(myObject!)
3637

37-
let weakReference = weak(myObject!)
38+
#expect(weakReference.obj != nil)
3839

39-
XCTAssertNotNil(weakReference.obj)
40+
myObject = nil
4041

41-
myObject = nil
42-
43-
XCTAssertNil(weakReference.obj)
44-
}
42+
#expect(weakReference.obj == nil)
4543
}

generate-static-site.sh

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)