Skip to content

Commit d75be69

Browse files
author
Hadevs
committed
some fixes
1 parent f4c9d23 commit d75be69

File tree

5 files changed

+73
-4
lines changed

5 files changed

+73
-4
lines changed

SwiftInjector/SwiftInjector.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
E676F73322C955B200DC1282 /* DIContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = E676F73222C955B200DC1282 /* DIContainer.swift */; };
2222
E676F73522C9688F00DC1282 /* TestClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = E676F73422C9688F00DC1282 /* TestClass.swift */; };
2323
E6BF5C6322CD2A32009A9331 /* SILogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = E6BF5C6222CD2A32009A9331 /* SILogger.swift */; };
24+
E6BF5C6522CD45C0009A9331 /* RecursiveResolvingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E6BF5C6422CD45C0009A9331 /* RecursiveResolvingTests.swift */; };
2425
/* End PBXBuildFile section */
2526

2627
/* Begin PBXContainerItemProxy section */
@@ -52,6 +53,7 @@
5253
E676F73222C955B200DC1282 /* DIContainer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DIContainer.swift; sourceTree = "<group>"; };
5354
E676F73422C9688F00DC1282 /* TestClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestClass.swift; sourceTree = "<group>"; };
5455
E6BF5C6222CD2A32009A9331 /* SILogger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SILogger.swift; sourceTree = "<group>"; };
56+
E6BF5C6422CD45C0009A9331 /* RecursiveResolvingTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecursiveResolvingTests.swift; sourceTree = "<group>"; };
5557
/* End PBXFileReference section */
5658

5759
/* Begin PBXFrameworksBuildPhase section */
@@ -110,6 +112,7 @@
110112
children = (
111113
E676F71A22C94F2E00DC1282 /* SwiftInjectorTests.swift */,
112114
E676F72A22C9511200DC1282 /* ContainerableMainTests.swift */,
115+
E6BF5C6422CD45C0009A9331 /* RecursiveResolvingTests.swift */,
113116
E676F71C22C94F2E00DC1282 /* Info.plist */,
114117
);
115118
path = SwiftInjectorTests;
@@ -245,6 +248,7 @@
245248
isa = PBXSourcesBuildPhase;
246249
buildActionMask = 2147483647;
247250
files = (
251+
E6BF5C6522CD45C0009A9331 /* RecursiveResolvingTests.swift in Sources */,
248252
E676F72B22C9511200DC1282 /* ContainerableMainTests.swift in Sources */,
249253
E676F71B22C94F2E00DC1282 /* SwiftInjectorTests.swift in Sources */,
250254
);

SwiftInjector/SwiftInjector/AppDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1818
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
1919
let newVc: ViewController? = self.container.resolve(name: "123")
2020
let testClass = newVc?.testClass
21-
21+
#error("NOT FINISHED RECURSIVE RESOLVING. BECAUSE AFTER RESOLVING I DONT PASS NAME VARIABLE TO RESOLVE.")
2222
print(testClass)
2323
return true
2424
}

SwiftInjector/SwiftInjector/Source/Containerable.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ protocol Containerable: class {
1515
typealias RelationIn = String
1616
typealias RelationOut = String
1717

18-
var container: Containerable? { get set }
1918
var dispatchRegistrationGroup: DispatchGroup { get }
2019

2120
var services: [ServiceName: [ContainerObject]] { get set }
@@ -48,6 +47,7 @@ extension Containerable {
4847
}
4948

5049
if let object = array?.first?.object {
50+
print(1)
5151
return object
5252
} else if let object = array?.first?.registration() {
5353

@@ -78,7 +78,6 @@ extension Containerable {
7878
for object in recursiveNotResolvedObjects {
7979
autoresolve(on: object)
8080
}
81-
recursiveNotResolvedObjects.removeAll()
8281
}
8382

8483
private func autoresolve<T: Object>(on object: T) {
@@ -101,6 +100,7 @@ extension Containerable {
101100
return
102101
}
103102
if let value = resolveAny(typeString: typeString) {
103+
print("I SETTED VALUE FOR \(typeString)")
104104
object_setIvar(object, ivar, value)
105105
}
106106
}

SwiftInjector/SwiftInjector/Source/RootContainer.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ class RootContainer: Containerable {
1616

1717
var dispatchRegistrationGroup: DispatchGroup = DispatchGroup()
1818

19-
var container: Containerable?
2019

2120
init() {
2221
let date = Date()
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
//
2+
// SwiftInjectorTests.swift
3+
// SwiftInjectorTests
4+
//
5+
// Created by Ghost on 30.06.2019.
6+
// Copyright © 2019 Ghost. All rights reserved.
7+
//
8+
9+
import XCTest
10+
@testable import SwiftInjector
11+
12+
class RecursiveResolvingTests: XCTestCase {
13+
14+
15+
class FirstClass: Equatable {
16+
var name: String = "123"
17+
var secondClass: SecondClass!
18+
19+
static func == (lhs: FirstClass, rhs: FirstClass) -> Bool {
20+
return "\(Unmanaged.passUnretained(lhs).toOpaque())" == "\(Unmanaged.passUnretained(rhs).toOpaque())"
21+
}
22+
}
23+
24+
class SecondClass: Equatable {
25+
var name: String = "234"
26+
weak var firstClass: FirstClass!
27+
28+
static func == (lhs: SecondClass, rhs: SecondClass) -> Bool {
29+
return "\(Unmanaged.passUnretained(lhs).toOpaque())" == "\(Unmanaged.passUnretained(rhs).toOpaque())"
30+
}
31+
32+
}
33+
34+
override func setUp() {
35+
// Put setup code here. This method is called before the invocation of each test method in the class.
36+
}
37+
38+
override func tearDown() {
39+
// Put teardown code here. This method is called after the invocation of each test method in the class.
40+
}
41+
42+
43+
class TestingContainer_1: DIContainer {
44+
let firstClass = FirstClass()
45+
let secondClass = SecondClass()
46+
override func register() {
47+
register { self.firstClass }
48+
register { self.secondClass }
49+
}
50+
}
51+
let container = TestingContainer_1()
52+
func testClassToClassRegister() {
53+
54+
var firstClass: FirstClass? = container.resolve()
55+
let secondClass: SecondClass? = container.resolve()
56+
print("---------")
57+
print(firstClass, secondClass?.firstClass)
58+
print("---------")
59+
XCTAssertNotNil(firstClass)
60+
XCTAssertNotNil(secondClass)
61+
XCTAssertNotNil(secondClass?.firstClass)
62+
XCTAssertEqual(firstClass?.secondClass, secondClass)
63+
XCTAssertEqual(secondClass?.firstClass, firstClass)
64+
}
65+
66+
}

0 commit comments

Comments
 (0)