Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift 6 #102

Merged
merged 37 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
1e2621f
Make changes so the projects builds and passes
0xLeif Sep 19, 2024
8d6cd44
Update macOS.yml
0xLeif Sep 19, 2024
4e90bc4
Update macOS.yml
0xLeif Sep 19, 2024
84fe03e
Update ubuntu.yml
0xLeif Sep 19, 2024
c8b7c3b
Update windows.yml
0xLeif Sep 19, 2024
5c64860
Update windows.yml
0xLeif Sep 19, 2024
d420020
Update ubuntu.yml
0xLeif Sep 19, 2024
48ee7da
Fix windows and linux error
0xLeif Sep 19, 2024
68bb8ed
Add MainActor where needed
0xLeif Sep 19, 2024
a264454
Update AppLogger to struct from class
0xLeif Sep 19, 2024
28aaaaa
Import foundation
0xLeif Sep 19, 2024
c2f1112
Add mirror function
0xLeif Sep 19, 2024
6398a78
Fix mirror functions
0xLeif Sep 19, 2024
cd12a86
Fix windows and ubuntu tests
0xLeif Sep 19, 2024
36ce3f8
Fix windows error ci
0xLeif Sep 19, 2024
75755c7
Update ubuntu.yml
0xLeif Sep 19, 2024
3b73abe
Revert change.
0xLeif Sep 19, 2024
691b5de
Add Loggable protocol for state and dependency
0xLeif Sep 19, 2024
13298e4
Update README
0xLeif Sep 19, 2024
d9cf656
Update ubuntu.yml
0xLeif Sep 19, 2024
13dd27d
Fix "class 'ApplicationTests' does not conform to the 'Sendable' prot…
0xLeif Sep 19, 2024
945c2a9
Attempt to fix Linux and Windows CI
0xLeif Sep 19, 2024
51f80e9
TEMP: Remove all but one test.
0xLeif Sep 19, 2024
e4d5549
Add back another test
0xLeif Sep 19, 2024
496df33
Add back another test
0xLeif Sep 19, 2024
118421a
Remove test from testcase
0xLeif Sep 19, 2024
40160d3
Remove remaining tests leaving setup and teardown
0xLeif Sep 19, 2024
1101e79
Add test that is expected to fail
0xLeif Sep 19, 2024
9fe495b
Attempt a simple fix.
0xLeif Sep 19, 2024
528e99f
Leave a few lines for the failing test
0xLeif Sep 20, 2024
e3aa6c4
Leave a single line to determine the issue
0xLeif Sep 20, 2024
c388b2a
Move around MainActor
0xLeif Sep 20, 2024
2718954
Attempt to fix CI
0xLeif Sep 20, 2024
b3c5973
Attempt to fix failing test
0xLeif Sep 20, 2024
b26ee51
Update tests to hopefully pass
0xLeif Sep 20, 2024
3856eda
Attemp to fix dependency slice tests
0xLeif Sep 20, 2024
5e2af62
Attempt to fix all tests for linux and windows
0xLeif Sep 20, 2024
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
27 changes: 12 additions & 15 deletions .github/workflows/macOS.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
# This workflow will build a Swift project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-swift

name: macOS

on:
push:
branches: ["**"]
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:
runs-on: macos-13

runs-on: macos-latest
steps:
- uses: swift-actions/setup-swift@v1
- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: latest-stable
- uses: actions/checkout@v3
- name: Build for release
run: swift build -v -c release
- name: Test
run: swift test -v
- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: 16.0
- uses: actions/checkout@v3
- name: Build
run: swift build -v
- name: Run tests
run: swift test -v
5 changes: 4 additions & 1 deletion .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: swift-actions/setup-swift@v1
- uses: compnerd/gha-setup-swift@main
with:
branch: swift-6.0-release
tag: 6.0-RELEASE
- uses: actions/checkout@v3
- name: Build for release
run: swift build -v -c release
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ jobs:
steps:
- uses: compnerd/gha-setup-swift@main
with:
branch: swift-5.9.2-release
tag: 5.9.2-RELEASE
branch: swift-6.0-release
tag: 6.0-RELEASE

- uses: actions/checkout@v2
- run: swift build
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version: 5.9
// swift-tools-version: 6.0

import PackageDescription

Expand Down
4 changes: 4 additions & 0 deletions Sources/AppState/Application/Application+internal.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
extension Application {
@MainActor
static var cacheDescription: String {
shared.cache.allValues
.map { key, value in
Expand Down Expand Up @@ -28,6 +29,7 @@ extension Application {
}

/// Internal log function.
@MainActor
static func log(
debug message: String,
fileID: StaticString,
Expand All @@ -45,6 +47,7 @@ extension Application {
}

/// Internal log function.
@MainActor
static func log(
debug message: () -> String,
fileID: StaticString,
Expand Down Expand Up @@ -72,6 +75,7 @@ extension Application {
}

/// Internal log function.
@MainActor
static func log(
error: Error,
message: String,
Expand Down
52 changes: 42 additions & 10 deletions Sources/AppState/Application/Application+public.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import SwiftUI

public extension Application {
/// Provides a description of the current application state
@MainActor
static var description: String {
"""
{
Expand Down Expand Up @@ -55,6 +56,7 @@ public extension Application {

In this way, your custom Application subclass becomes the shared singleton instance, which you can then use throughout your application.
*/
@MainActor
@discardableResult
static func promote<CustomApplication: Application>(
to customApplication: CustomApplication.Type
Expand All @@ -74,6 +76,7 @@ public extension Application {
}

/// Enables or disabled the default logging inside of Application.
@MainActor
@discardableResult
static func logging(isEnabled: Bool) -> Application.Type {
Application.isLoggingEnabled = isEnabled
Expand All @@ -91,6 +94,7 @@ public extension Application {
- Parameter dependency: KeyPath of the Dependency to be loaded
- Returns: `Application.self` to allow chaining.
*/
@MainActor
@discardableResult
static func load<Value>(
dependency keyPath: KeyPath<Application, Dependency<Value>>
Expand All @@ -106,6 +110,7 @@ public extension Application {
- Parameter keyPath: KeyPath of the Dependency to be fetched
- Returns: The requested state of type `Value`.
*/
@MainActor
static func dependency<Value>(
_ keyPath: KeyPath<Application, Dependency<Value>>,
_ fileID: StaticString = #fileID,
Expand Down Expand Up @@ -134,6 +139,7 @@ public extension Application {

Note: If the `DependencyOverride` object gets deallocated without calling `cancel()`, it will automatically cancel the override, restoring the original dependency.
*/
@MainActor
static func `override`<Value>(
_ keyPath: KeyPath<Application, Dependency<Value>>,
with value: Value,
Expand All @@ -157,19 +163,23 @@ public extension Application {
forKey: dependency.scope.key
)

let keyPath = String(describing: keyPath)

return DependencyOverride {
log(
debug: "🔗 Cancelling Dependency Override \(String(describing: keyPath)) ",
await log(
debug: "🔗 Cancelling Dependency Override \(keyPath) ",
fileID: fileID,
function: function,
line: line,
column: column
)

shared.cache.set(
value: dependency,
forKey: dependency.scope.key
)
await MainActor.run {
shared.cache.set(
value: dependency,
forKey: dependency.scope.key
)
}
}
}

Expand All @@ -183,6 +193,7 @@ public extension Application {

Note: There is no way to undo the promotion other than re-promoting a dependency. It is advised you use `override` if you ever need to undo the change.
*/
@MainActor
@discardableResult
static func promote<CustomDependency>(
_ keyPath: KeyPath<Application, Dependency<CustomDependency>>,
Expand Down Expand Up @@ -309,6 +320,7 @@ public extension Application {

- Returns: A View with the overridden dependencies applied.
*/
@MainActor
@ViewBuilder
static func preview<Content: View>(
_ dependencyOverrides: DependencyOverride...,
Expand All @@ -331,6 +343,7 @@ public extension Application {
- Parameter keyPath: KeyPath of the state value to be fetched
- Returns: The requested state of type `Value`.
*/
@MainActor
static func state<Value, ApplicationState: MutableApplicationState>(
_ keyPath: KeyPath<Application, ApplicationState>,
_ fileID: StaticString = #fileID,
Expand Down Expand Up @@ -396,6 +409,7 @@ public extension Application {

public extension Application {
/// Resets the value to the inital value. If the inital value was `nil`, then the value will be removed from `UserDefaults`
@MainActor
static func reset<Value>(
storedState keyPath: KeyPath<Application, StoredState<Value>>,
_ fileID: StaticString = #fileID,
Expand All @@ -416,6 +430,7 @@ public extension Application {
}

/// Removes the value from `UserDefaults` and resets the value to the inital value.
@MainActor
@available(*, deprecated, renamed: "reset")
static func remove<Value>(
storedState keyPath: KeyPath<Application, StoredState<Value>>,
Expand All @@ -439,6 +454,7 @@ public extension Application {
- Parameter keyPath: KeyPath of the state value to be fetched
- Returns: The requested state of type `Value`.
*/
@MainActor
static func storedState<Value>(
_ keyPath: KeyPath<Application, StoredState<Value>>,
_ fileID: StaticString = #fileID,
Expand Down Expand Up @@ -504,7 +520,8 @@ public extension Application {

@available(watchOS 9.0, *)
public extension Application {
/// Resets the value to the inital value. If the inital value was `nil`, then the value will be removed from `iClouds`
/// Resets the value to the inital value. If the inital value was `nil`, then the value will be removed from `iCloud`
@MainActor
static func reset<Value>(
syncState keyPath: KeyPath<Application, SyncState<Value>>,
_ fileID: StaticString = #fileID,
Expand All @@ -525,6 +542,7 @@ public extension Application {
}

/// Removes the value from `iCloud` and resets the value to the inital value.
@MainActor
@available(*, deprecated, renamed: "reset")
static func remove<Value>(
syncState keyPath: KeyPath<Application, SyncState<Value>>,
Expand All @@ -548,7 +566,8 @@ public extension Application {
- Parameter keyPath: KeyPath of the state value to be fetched
- Returns: The requested state of type `Value`.
*/
static func syncState<Value: Codable>(
@MainActor
static func syncState<Value: Codable & Sendable>(
_ keyPath: KeyPath<Application, SyncState<Value>>,
_ fileID: StaticString = #fileID,
_ function: StaticString = #function,
Expand Down Expand Up @@ -577,7 +596,7 @@ public extension Application {
- id: The specific identifier for this state.
- Returns: The state of type `Value`.
*/
func syncState<Value: Codable>(
func syncState<Value: Codable & Sendable>(
initial: @escaping @autoclosure () -> Value,
feature: String = "App",
id: String
Expand All @@ -596,7 +615,7 @@ public extension Application {
- id: The specific identifier for this state.
- Returns: The state of type `Value`.
*/
func syncState<Value: Codable>(
func syncState<Value: Codable & Sendable>(
feature: String = "App",
id: String
) -> SyncState<Value?> {
Expand All @@ -617,6 +636,7 @@ public extension Application {
- Parameters:
- keyPath: A key path of the SecureState to be reset.
*/
@MainActor
static func reset(
secureState keyPath: KeyPath<Application, SecureState>,
_ fileID: StaticString = #fileID,
Expand Down Expand Up @@ -644,6 +664,7 @@ public extension Application {

- Returns: The SecureState at provided keyPath.
*/
@MainActor
static func secureState(
_ keyPath: KeyPath<Application, SecureState>,
_ fileID: StaticString = #fileID,
Expand Down Expand Up @@ -730,6 +751,7 @@ extension Application {

- Returns: A Slice that allows access to a specific part of an AppState's state.
*/
@MainActor
public static func slice<SlicedState: MutableApplicationState, Value, SliceValue>(
_ stateKeyPath: KeyPath<Application, SlicedState>,
_ valueKeyPath: KeyPath<Value, SliceValue>,
Expand Down Expand Up @@ -775,6 +797,7 @@ extension Application {

- Returns: A Slice that allows access and modification to a specific part of an AppState's state.
*/
@MainActor
public static func slice<SlicedState: MutableApplicationState, Value, SliceValue>(
_ stateKeyPath: KeyPath<Application, SlicedState>,
_ valueKeyPath: WritableKeyPath<Value, SliceValue>,
Expand Down Expand Up @@ -820,6 +843,7 @@ extension Application {

- Returns: A Slice that allows access to a specific part of an AppState's state.
*/
@MainActor
public static func slice<SlicedState: MutableApplicationState, Value, SliceValue>(
_ stateKeyPath: KeyPath<Application, SlicedState>,
_ valueKeyPath: KeyPath<Value, SliceValue>,
Expand Down Expand Up @@ -869,6 +893,7 @@ extension Application {

- Returns: A Slice that allows access and modification to a specific part of an AppState's state.
*/
@MainActor
public static func slice<SlicedState: MutableApplicationState, Value, SliceValue>(
_ stateKeyPath: KeyPath<Application, SlicedState>,
_ valueKeyPath: WritableKeyPath<Value, SliceValue>,
Expand Down Expand Up @@ -918,6 +943,7 @@ extension Application {

- Returns: A Slice that allows access and modification to a specific part of an AppState's state.
*/
@MainActor
public static func slice<SlicedState: MutableApplicationState, Value, SliceValue>(
_ stateKeyPath: KeyPath<Application, SlicedState>,
_ valueKeyPath: WritableKeyPath<Value, SliceValue?>,
Expand Down Expand Up @@ -971,6 +997,7 @@ extension Application {

- Returns: A Slice that allows access to a specific part of an AppState's state.
*/
@MainActor
public static func dependencySlice<Value, SliceValue>(
_ dependencyKeyPath: KeyPath<Application, Dependency<Value>>,
_ valueKeyPath: KeyPath<Value, SliceValue>,
Expand Down Expand Up @@ -1016,6 +1043,7 @@ extension Application {

- Returns: A Slice that allows access to a specific part of an AppState's state.
*/
@MainActor
public static func dependencySlice<Value, SliceValue>(
_ dependencyKeyPath: KeyPath<Application, Dependency<Value>>,
_ valueKeyPath: WritableKeyPath<Value, SliceValue>,
Expand Down Expand Up @@ -1053,6 +1081,7 @@ extension Application {

public extension Application {
/// Resets the value to the inital value. If the inital value was `nil`, then the value will be removed from `FileManager`
@MainActor
static func reset<Value>(
fileState keyPath: KeyPath<Application, FileState<Value>>,
_ fileID: StaticString = #fileID,
Expand All @@ -1078,6 +1107,7 @@ public extension Application {
- Parameter keyPath: KeyPath of the state value to be fetched
- Returns: The requested state of type `Value`.
*/
@MainActor
static func fileState<Value>(
_ keyPath: KeyPath<Application, FileState<Value>>,
_ fileID: StaticString = #fileID,
Expand Down Expand Up @@ -1108,6 +1138,7 @@ public extension Application {
- isBase64Encoded: Boolean to determine if the value should be encoded as Base64. The default is `true`.
- Returns: The state of type `Value`.
*/
@MainActor
func fileState<Value>(
initial: @escaping @autoclosure () -> Value,
path: String = FileManager.defaultFileStatePath,
Expand All @@ -1130,6 +1161,7 @@ public extension Application {
- isBase64Encoded: Boolean to determine if the value should be encoded as Base64. The default is `true`.
- Returns: The state of type `Value`.
*/
@MainActor
func fileState<Value>(
path: String = FileManager.defaultFileStatePath,
filename: String,
Expand Down
3 changes: 3 additions & 0 deletions Sources/AppState/Application/Application.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Foundation
/// `Application` is a class that can be observed for changes, keeping track of the states within the application.
open class Application: NSObject {
/// Singleton shared instance of `Application`
@MainActor
static var shared: Application = Application()

#if !os(Linux) && !os(Windows)
Expand All @@ -19,6 +20,7 @@ open class Application: NSObject {
public static var logger: ApplicationLogger = ApplicationLogger()
#endif

@MainActor
static var isLoggingEnabled: Bool = false

let lock: NSRecursiveLock
Expand Down Expand Up @@ -65,6 +67,7 @@ open class Application: NSObject {

- Note: Calling `Application.dependency(\.icloudStore).synchronize()` does not force new keys and values to be written to iCloud. Rather, it lets iCloud know that new keys and values are available to be uploaded. Do not rely on your keys and values being available on other devices immediately. The system controls when those keys and values are uploaded. The frequency of upload requests for key-value storage is limited to several per minute.
*/
@MainActor
@objc @available(watchOS 9.0, *)
open func didChangeExternally(notification: Notification) {
Application.log(
Expand Down
Loading
Loading