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

Updates for Swift 6 and concurrency. #7

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
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.3
// swift-tools-version:6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand Down
2 changes: 1 addition & 1 deletion Sources/MicroInjection/MicroInjection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ fileprivate class Foo {
}
}

fileprivate struct AKey : InjectionKey {
fileprivate struct AKey : @preconcurrency InjectionKey {
@MainActor
static var defaultValue = "a"
}

Expand Down
22 changes: 12 additions & 10 deletions Tests/MicroInjectionTests/MicroInjectionTests.swift
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import XCTest
import MicroInjection

fileprivate class Foo {
fileprivate final class Foo : Sendable{
let text: String
init(text: String) {
self.text = text
}
}

fileprivate struct AKey : InjectionKey {
static var defaultValue = "a"
static let defaultValue = "a"
}

extension InjectionValues {
Expand All @@ -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
Expand All @@ -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
Expand All @@ -53,15 +55,15 @@ 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")
}

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")
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -185,7 +187,7 @@ final class MicroInjectionTests: XCTestCase {
// }
// }

static var allTests = [
static let allTests = [
("testDefaultValue", testDefaultValue),
("testDefaultValueComputed", testDefaultValueComputed),
("testSetValue", testSetValue),
Expand Down
Loading