Skip to content

Commit d6b6020

Browse files
committed
Swift6 대응
1 parent 3362c96 commit d6b6020

File tree

13 files changed

+76
-35
lines changed

13 files changed

+76
-35
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
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
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

44
import PackageDescription

Sources/DIContainer/Container/Container.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import Foundation
22

33
public class Container {
4-
static var root = Container()
4+
@MainActor
5+
static private(set) var root = Container()
56

67
/// Stored object instance factories.
78
var modules: [String: Module] = [:]
@@ -33,6 +34,7 @@ extension Container {
3334
/// Resolves through inference and returns an instance of the given type from the current default container.
3435
///
3536
/// If the dependency is not found, an exception will occur.
37+
@MainActor
3638
static func resolve<T>(for type: AnyObject.Type) -> T {
3739
guard let component: T = weakResolve(for: type) else {
3840
fatalError("Dependency '\(T.self)' not resolved!")
@@ -44,6 +46,7 @@ extension Container {
4446
/// Resolves through inference and returns an instance of the given type from the current default container.
4547
///
4648
/// If the dependency is not found, return nil
49+
@MainActor
4750
static func weakResolve<T>(for type: AnyObject.Type) -> T? {
4851
root.module(type)?.resolve() as? T
4952
}
@@ -78,10 +81,23 @@ public extension Container {
7881
self.init()
7982
register(contentsOf: [module()])
8083
}
84+
}
8185

86+
public extension Container {
8287
/// Assigns the current container to the composition root.
88+
@MainActor
8389
func build() {
8490
// Used later in property wrapper
8591
Self.root = self
8692
}
8793
}
94+
95+
#if DEBUG
96+
public extension Container {
97+
@MainActor
98+
static func clear() {
99+
root.modules.removeAll()
100+
}
101+
}
102+
103+
#endif
File renamed without changes.

Sources/DIContainer/Key/InjectionKeyType.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
import Foundation
22

3+
@MainActor
34
public protocol InjectionKeyType: AnyObject {
45
associatedtype Value
56
static var value: Value { get }
67
static var weakValue: Value? { get }
78
}
89

910
public extension InjectionKeyType {
11+
@MainActor
1012
static var value: Value {
1113
Container.resolve(for: Self.self)
1214
}
1315

16+
@MainActor
1417
static var weakValue: Value? {
1518
Container.weakResolve(for: Self.self)
1619
}

Sources/DIContainer/PropertyWrapper/Inject.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Foundation
22

3+
@MainActor
34
@propertyWrapper
45
public class Inject<Value> {
56
private let lazyValue: () -> Value

Sources/DIContainer/PropertyWrapper/WeakInject.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Foundation
22

3+
@MainActor
34
@propertyWrapper
45
public class WeakInject<Value> {
56
private let lazyValue: () -> Value?

Tests/DIContainerTests/Helper/Helper.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Foundation
33
@testable import DIContainer
44

55
extension InjectionKeyType {
6+
@MainActor
67
static var module: Module? {
78
return Container.root.module(Self.self)
89
}

Tests/DIContainerTests/Mock/MockService.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import DIContainer
22
import Foundation
33

4+
@MainActor
45
final class MockServiceKey: InjectionKey {
56
typealias Value = MockService
67
}
78

9+
@MainActor
810
protocol MockService {
911
func doSomething()
1012
}
1113

14+
@MainActor
1215
final class MockServiceImpl: AutoModule, MockService {
1316
typealias ModuleKeyType = MockServiceKey
1417

Tests/DIContainerTests/Tests/InjectTestsTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import XCTest
22

33
@testable import DIContainer
44

5+
@MainActor
56
class ContainerTests: XCTestCase {
67
func test_container1() {
78
testContainer(withSetup: .init {

Tests/DIContainerTests/Tests/ModuleListExtensionTests.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import Foundation
2+
import Testing
23
import XCTest
34

45
@testable import DIContainer
56

6-
final class ModuleListExtensionTests: XCTestCase {
7-
func testReplaceOneModule() {
7+
@MainActor
8+
struct ModuleListExtensionTest {
9+
@Test
10+
func replaceOneModule() {
811
// Given
912
let newModule = Module(MockServiceKey.self) { Service1() }
1013
var moduleList = ModuleScanner().scanModuleList
@@ -23,7 +26,8 @@ final class ModuleListExtensionTests: XCTestCase {
2326
XCTAssertEqual(service?.count, 1)
2427
}
2528

26-
func testReplaceMultipleModules() {
29+
@Test
30+
func replaceMultipleModules() {
2731
// Given
2832
let newModule1 = Module(MockServiceKey.self) { Service1() }
2933
let newModule2 = Module(WeakMockServiceKey.self) { Service2() }
@@ -60,7 +64,7 @@ final class ModuleListExtensionTests: XCTestCase {
6064
}
6165
}
6266

63-
private extension ModuleListExtensionTests {
67+
private extension ModuleListExtensionTest {
6468
final class Service1: MockService {
6569
var count = 0
6670

0 commit comments

Comments
 (0)