Skip to content

Commit cfbd2fe

Browse files
authored
Merge pull request #8 from mtj0928/swift6
Support Swift6
2 parents 69cac2a + 46e1240 commit cfbd2fe

11 files changed

+118
-123
lines changed

.github/workflows/docc.yml

+6-7
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@ on:
44
push:
55
branches:
66
- main
7-
env:
8-
DEVELOPER_DIR: "/Applications/Xcode_14.3.1.app/Contents/Developer"
97
jobs:
108
DocC:
11-
runs-on: macos-13
12-
env:
13-
DEVELOPER_DIR: /Applications/Xcode_15.0.1.app/Contents/Developer
9+
runs-on: macos-latest
1410
steps:
15-
- uses: actions/checkout@v3
11+
- uses: SwiftyLab/setup-swift@latest
12+
with:
13+
swift-version: "6.0"
14+
- uses: actions/checkout@v4
1615
- name: Build DocC
1716
run: |
1817
swift package --allow-writing-to-directory ./docs generate-documentation \
@@ -36,4 +35,4 @@ jobs:
3635
steps:
3736
- name: Deploy to GitHub Pages
3837
id: deployment
39-
uses: actions/deploy-pages@v2
38+
uses: actions/deploy-pages@v2

.github/workflows/test.yml

+19-14
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
1-
name: Tests
1+
name: Test
22

3-
on:
3+
on:
44
push:
5-
branches:
6-
- main
5+
branches: [ "main" ]
76
pull_request:
8-
branches:
9-
- '*'
7+
branches: [ "main" ]
8+
109
jobs:
11-
Tests:
12-
runs-on: macos-13
13-
env:
14-
DEVELOPER_DIR: /Applications/Xcode_15.0.1.app/Contents/Developer
10+
test:
11+
strategy:
12+
matrix:
13+
swift_version:
14+
- "5.9"
15+
- "5.10.0"
16+
- "6.0"
17+
runs-on: macos-latest
1518
steps:
16-
- uses: actions/checkout@v2
17-
- name: Run Tests
18-
run: |
19-
swift test --verbose
19+
- uses: SwiftyLab/setup-swift@latest
20+
with:
21+
swift-version: ${{ matrix.swift_version }}
22+
- uses: actions/checkout@v4
23+
- name: Run tests
24+
run: swift test

Package.resolved

-41
This file was deleted.

Package.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version: 5.9
1+
// swift-tools-version: 6.0
22

33
import CompilerPluginSupport
44
import PackageDescription
@@ -10,9 +10,9 @@ let package = Package(
1010
.library(name: "TypedNotifications", targets: ["TypedNotifications"]),
1111
],
1212
dependencies: [
13-
.package(url: "https://github.com/apple/swift-syntax.git", from: "509.0.0"),
13+
.package(url: "https://github.com/apple/swift-syntax", from: "600.0.0"),
1414
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
15-
.package(url: "https://github.com/mtj0928/userinfo-representable", from: "1.0.2")
15+
.package(url: "https://github.com/mtj0928/userinfo-representable", from: "1.1.1")
1616
],
1717
targets: [
1818
.target(

[email protected]

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// swift-tools-version: 5.9
2+
3+
import CompilerPluginSupport
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "typed-notifications",
8+
platforms: [.iOS(.v13), .macOS(.v10_15), .watchOS(.v6), .tvOS(.v13)],
9+
products: [
10+
.library(name: "TypedNotifications", targets: ["TypedNotifications"]),
11+
],
12+
dependencies: [
13+
.package(url: "https://github.com/apple/swift-syntax.git", from: "509.0.0"),
14+
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
15+
.package(url: "https://github.com/mtj0928/userinfo-representable", from: "1.0.2")
16+
],
17+
targets: [
18+
.target(
19+
name: "TypedNotifications",
20+
dependencies: [
21+
.product(name: "UserInfoRepresentable", package: "userinfo-representable"),
22+
"TypedNotificationsMacro"
23+
]
24+
),
25+
.macro(
26+
name: "TypedNotificationsMacro",
27+
dependencies: [
28+
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
29+
.product(name: "SwiftCompilerPlugin", package: "swift-syntax")
30+
]
31+
),
32+
.testTarget(name: "TypedNotificationsTests", dependencies: ["TypedNotifications"]),
33+
.testTarget(
34+
name: "TypedNotificationsMacroTests",
35+
dependencies: [
36+
"TypedNotificationsMacro",
37+
.product(name: "SwiftSyntaxMacrosTestSupport", package: "swift-syntax"),
38+
]
39+
)
40+
]
41+
)

Sources/TypedNotifications/NotificagtionMacro.swift

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import Foundation
2+
13
/// A macro for defining a notification whose notification name is attached property name.
24
@attached(accessor)
35
public macro Notification() = #externalMacro(module: "TypedNotificationsMacro", type: "NotificationMacro")
@@ -7,3 +9,10 @@ public macro Notification() = #externalMacro(module: "TypedNotificationsMacro",
79
/// - Parameter name: A name of the notification.
810
@attached(accessor)
911
public macro Notification(name: String) = #externalMacro(module: "TypedNotificationsMacro", type: "NotificationMacro")
12+
13+
14+
/// A macro for defining a notification.
15+
///
16+
/// - Parameter name: A name of the notification.
17+
@attached(accessor)
18+
public macro Notification(name: Notification.Name) = #externalMacro(module: "TypedNotificationsMacro", type: "NotificationMacro")

Sources/TypedNotifications/TypedNotificationCenter.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ extension TypedNotificationCenter {
3434
public typealias Notifications<Element> = AsyncCompactMapSequence<NotificationCenter.Notifications, Element>
3535

3636
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
37-
public func notifications<Storage, Object: AnyObject>(
37+
public func notifications<Storage, Object: AnyObject & Sendable>(
3838
for definition: TypedNotificationDefinition<Storage, Object>,
3939
object: Object? = nil
4040
) -> Notifications<TypedNotification<Storage, Object>> {

Sources/TypedNotifications/UIKit/UIApplication.swift

+10-16
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,19 @@
22
import UIKit
33

44
extension UIApplication {
5+
@Notification(name: UIApplication.didBecomeActiveNotification)
6+
public static var didBecomeActiveTypedNotification: TypedNotificationDefinition<Void, UIApplication>
57

6-
public static var didBecomeActiveTypedNotification: TypedNotificationDefinition<Void, UIApplication> {
7-
.init(name: UIApplication.didBecomeActiveNotification)
8-
}
8+
@Notification(name: UIApplication.didEnterBackgroundNotification)
9+
public static var didEnterBackgroundTypedNotification: TypedNotificationDefinition<Void, UIApplication>
910

10-
public static var didEnterBackgroundTypedNotification: TypedNotificationDefinition<Void, UIApplication> {
11-
.init(name: UIApplication.didEnterBackgroundNotification)
12-
}
11+
@Notification(name: UIApplication.willEnterForegroundNotification)
12+
public static var willEnterForegroundTypedNotification: TypedNotificationDefinition<Void, UIApplication>
1313

14-
public static var willEnterForegroundTypedNotification: TypedNotificationDefinition<Void, UIApplication> {
15-
.init(name: UIApplication.willEnterForegroundNotification)
16-
}
14+
@Notification(name: UIApplication.willResignActiveNotification)
15+
public static var willResignActiveTypedNotification: TypedNotificationDefinition<Void, UIApplication>
1716

18-
public static var willResignActiveTypedNotification: TypedNotificationDefinition<Void, UIApplication> {
19-
.init(name: UIApplication.willResignActiveNotification)
20-
}
21-
22-
public static var willTerminateTypedNotification: TypedNotificationDefinition<Void, UIApplication> {
23-
.init(name: UIApplication.willTerminateNotification)
24-
}
17+
@Notification(name: UIApplication.willTerminateNotification)
18+
public static var willTerminateTypedNotification: TypedNotificationDefinition<Void, UIApplication>
2519
}
2620
#endif

Sources/TypedNotifications/UIKit/UIResponder.swift

+12-18
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,23 @@ import UserInfoRepresentable
33
import UIKit
44

55
extension UIResponder {
6-
public static var keyboardWillShowTypedNotification: TypedNotificationDefinition<KeyboardNotificationStorage, UIScreen> {
7-
.init(name: UIResponder.keyboardWillShowNotification)
8-
}
6+
@Notification(name: UIResponder.keyboardWillShowNotification)
7+
public static var keyboardWillShowTypedNotification: TypedNotificationDefinition<KeyboardNotificationStorage, UIScreen>
98

10-
public static var keyboardDidShowTypedNotification: TypedNotificationDefinition<KeyboardNotificationStorage, UIScreen> {
11-
.init(name: UIResponder.keyboardDidShowNotification)
12-
}
9+
@Notification(name: UIResponder.keyboardDidShowNotification)
10+
public static var keyboardDidShowTypedNotification: TypedNotificationDefinition<KeyboardNotificationStorage, UIScreen>
1311

14-
public static var keyboardWillHideTypedNotification: TypedNotificationDefinition<KeyboardNotificationStorage, UIScreen> {
15-
.init(name: UIResponder.keyboardWillHideNotification)
16-
}
12+
@Notification(name: UIResponder.keyboardWillHideNotification)
13+
public static var keyboardWillHideTypedNotification: TypedNotificationDefinition<KeyboardNotificationStorage, UIScreen>
1714

18-
public static var keyboardDidHideTypedNotification: TypedNotificationDefinition<KeyboardNotificationStorage, UIScreen> {
19-
.init(name: UIResponder.keyboardDidHideNotification)
20-
}
15+
@Notification(name: UIResponder.keyboardDidHideNotification)
16+
public static var keyboardDidHideTypedNotification: TypedNotificationDefinition<KeyboardNotificationStorage, UIScreen>
2117

22-
public static var keyboardWillChangeFrameTypedNotification: TypedNotificationDefinition<KeyboardNotificationStorage, UIScreen> {
23-
.init(name: UIResponder.keyboardWillChangeFrameNotification)
24-
}
18+
@Notification(name: UIResponder.keyboardWillChangeFrameNotification)
19+
public static var keyboardWillChangeFrameTypedNotification: TypedNotificationDefinition<KeyboardNotificationStorage, UIScreen>
2520

26-
public static var keyboardDidChangeFrameTypedNotification: TypedNotificationDefinition<KeyboardNotificationStorage, UIScreen> {
27-
.init(name: UIResponder.keyboardDidChangeFrameNotification)
28-
}
21+
@Notification(name: UIResponder.keyboardDidChangeFrameNotification)
22+
public static var keyboardDidChangeFrameTypedNotification: TypedNotificationDefinition<KeyboardNotificationStorage, UIScreen>
2923
}
3024

3125
public struct KeyboardNotificationStorage: UserInfoRepresentable {

Sources/TypedNotifications/UIKit/UIScene.swift

+12-18
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,22 @@
22
import UIKit
33

44
extension UIScene {
5-
public static var willConnectTypedNotification: TypedNotificationDefinition<Void, UIScene> {
6-
.init(name: UIScene.willConnectNotification)
7-
}
5+
@Notification(name: UIScene.willConnectNotification)
6+
public static var willConnectTypedNotification: TypedNotificationDefinition<Void, UIScene>
87

9-
public static var didActivateTypedNotification: TypedNotificationDefinition<Void, UIScene> {
10-
.init(name: UIScene.didActivateNotification)
11-
}
8+
@Notification(name: UIScene.didActivateNotification)
9+
public static var didActivateTypedNotification: TypedNotificationDefinition<Void, UIScene>
1210

13-
public static var didDisconnectTypedNotification: TypedNotificationDefinition<Void, UIScene> {
14-
.init(name: UIScene.didDisconnectNotification)
15-
}
11+
@Notification(name: UIScene.didDisconnectNotification)
12+
public static var didDisconnectTypedNotification: TypedNotificationDefinition<Void, UIScene>
1613

17-
public static var willEnterForegroundTypedNotification: TypedNotificationDefinition<Void, UIScene> {
18-
.init(name: UIScene.willEnterForegroundNotification)
19-
}
14+
@Notification(name: UIScene.willEnterForegroundNotification)
15+
public static var willEnterForegroundTypedNotification: TypedNotificationDefinition<Void, UIScene>
2016

21-
public static var willDeactivateTypedNotification: TypedNotificationDefinition<Void, UIScene> {
22-
.init(name: UIScene.willDeactivateNotification)
23-
}
17+
@Notification(name: UIScene.willDeactivateNotification)
18+
public static var willDeactivateTypedNotification: TypedNotificationDefinition<Void, UIScene>
2419

25-
public static var didEnterBackgroundTypedNotification: TypedNotificationDefinition<Void, UIScene> {
26-
.init(name: UIScene.didEnterBackgroundNotification)
27-
}
20+
@Notification(name: UIScene.didEnterBackgroundNotification)
21+
public static var didEnterBackgroundTypedNotification: TypedNotificationDefinition<Void, UIScene>
2822
}
2923
#endif

Tests/TypedNotificationsTests/TypedNotificationsTests.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ final class TypedNotificationsTests: XCTestCase {
7070
_ = cancellable
7171
}
7272

73-
func testMacro() {
73+
func testMacro() throws {
7474
#if canImport(TypedNotificationsMacro)
7575
let center = TypedNotificationCenter()
7676
let expectation = expectation(description: "receive an empty notification")
@@ -85,11 +85,11 @@ final class TypedNotificationsTests: XCTestCase {
8585
wait(for: [expectation], timeout: 1)
8686
_ = cancellable
8787
#else
88-
XCTSkip("Macro is not support on the current test environment.")
88+
throw XCTSkip("Macro is not support on the current test environment.")
8989
#endif
9090
}
9191

92-
func testMacroWithName() {
92+
func testMacroWithName() throws {
9393
#if canImport(TypedNotificationsMacro)
9494
let center = TypedNotificationCenter()
9595
let expectation = expectation(description: "receive an empty notification")
@@ -105,12 +105,12 @@ final class TypedNotificationsTests: XCTestCase {
105105
wait(for: [expectation], timeout: 1)
106106
_ = cancellable
107107
#else
108-
XCTSkip("Macro is not support on the current test environment.")
108+
throw XCTSkip("Macro is not support on the current test environment.")
109109
#endif
110110
}
111111
}
112112

113-
class Foo {
113+
final class Foo: Sendable {
114114
let value: String
115115

116116
init(value: String) {

0 commit comments

Comments
 (0)