diff --git a/Package.swift b/Package.swift index ca67ce9..47c2009 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.3 +// swift-tools-version:6.0 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription diff --git a/Sources/MicroInjection/MicroInjection.swift b/Sources/MicroInjection/MicroInjection.swift index 602a0d3..c06bb99 100644 --- a/Sources/MicroInjection/MicroInjection.swift +++ b/Sources/MicroInjection/MicroInjection.swift @@ -51,7 +51,7 @@ public struct InjectionValues { } /// Conform to this and you can then add `@Injection` wrapped properties to your class -public protocol Injectable : class { +public protocol Injectable : AnyObject { /// This is where the `@Injection` properties will actually look up their values. You will often want to /// inject this in the init. You can also create an empty one, expose a mutable var or even have this implemetned with a computed var /// potentially to access a shared app injection if you want. diff --git a/Tests/MicroInjectionTests/MicroInjectionNonCompileTests.swift.swift b/Tests/MicroInjectionTests/MicroInjectionNonCompileTests.swift.swift index cd6c5ba..9a043ea 100644 --- a/Tests/MicroInjectionTests/MicroInjectionNonCompileTests.swift.swift +++ b/Tests/MicroInjectionTests/MicroInjectionNonCompileTests.swift.swift @@ -8,7 +8,8 @@ fileprivate class Foo { } } -fileprivate struct AKey : InjectionKey { +fileprivate struct AKey : @preconcurrency InjectionKey { + @MainActor static var defaultValue = "a" } diff --git a/Tests/MicroInjectionTests/MicroInjectionTests.swift b/Tests/MicroInjectionTests/MicroInjectionTests.swift index 88e946c..a1a8cd1 100644 --- a/Tests/MicroInjectionTests/MicroInjectionTests.swift +++ b/Tests/MicroInjectionTests/MicroInjectionTests.swift @@ -1,7 +1,7 @@ import XCTest import MicroInjection -fileprivate class Foo { +fileprivate final class Foo : Sendable{ let text: String init(text: String) { self.text = text @@ -9,7 +9,7 @@ fileprivate class Foo { } fileprivate struct AKey : InjectionKey { - static var defaultValue = "a" + static let defaultValue = "a" } extension InjectionValues { @@ -19,18 +19,20 @@ extension InjectionValues { } } -final class MicroInjectionTests: XCTestCase { +final class MicroInjectionTests: XCTestCase, @unchecked Sendable { func testDefaultValue() { struct TestKey : InjectionKey { - static var defaultValue = 5 + static let defaultValue = 5 } let injection = InjectionValues() XCTAssertEqual(injection[TestKey.self], 5) } func testDefaultValueComputed() { - struct TestKey : InjectionKey { + struct TestKey : @preconcurrency InjectionKey { + @MainActor static var lastValue = 0 + @MainActor static var defaultValue: Int { let next = lastValue + 5 lastValue = next @@ -44,7 +46,7 @@ final class MicroInjectionTests: XCTestCase { func testSetValue() { struct TestKey : InjectionKey { - static var defaultValue = 5 + static let defaultValue = 5 } var injection = InjectionValues() injection[TestKey.self] = 8 @@ -53,7 +55,7 @@ final class MicroInjectionTests: XCTestCase { func testDefaultObject() { struct TestKey : InjectionKey { - static var defaultValue = Foo(text: "default") + static let defaultValue = Foo(text: "default") } let injection = InjectionValues() XCTAssertEqual(injection[TestKey.self].text, "default") @@ -61,7 +63,7 @@ final class MicroInjectionTests: XCTestCase { func testSetObject() { struct TestKey : InjectionKey { - static var defaultValue = Foo(text: "default") + static let defaultValue = Foo(text: "default") } var injection = InjectionValues() injection[TestKey.self] = Foo(text: "Updated") @@ -153,7 +155,7 @@ final class MicroInjectionTests: XCTestCase { // The functionality to set an overriding closure has been removed. It could potentially -// be readded in the future but I think it is an unnecessary level of complication. +// be re-added in the future but I think it is an unnecessary level of complication. // Just because something can be done doesn't mean it should be done. // func testExtendInjectionSetValueClosure() { // var injection = InjectionValues() @@ -185,7 +187,7 @@ final class MicroInjectionTests: XCTestCase { // } // } - static var allTests = [ + static let allTests = [ ("testDefaultValue", testDefaultValue), ("testDefaultValueComputed", testDefaultValueComputed), ("testSetValue", testSetValue),