File tree 2 files changed +22
-25
lines changed
2 files changed +22
-25
lines changed Original file line number Diff line number Diff line change @@ -15,26 +15,15 @@ import XCTest
15
15
16
16
class FlexLayoutTests : XCTestCase {
17
17
18
- override func setUp( ) {
19
- super. setUp ( )
20
- // Put setup code here. This method is called before the invocation of each test method in the class.
21
- }
22
-
23
- override func tearDown( ) {
24
- // Put teardown code here. This method is called after the invocation of each test method in the class.
25
- super. tearDown ( )
26
- }
27
-
28
- func testExample( ) {
29
- // This is an example of a functional test case.
30
- // Use XCTAssert and related functions to verify your tests produce the correct results.
31
- }
32
-
33
- func testPerformanceExample( ) {
34
- // This is an example of a performance test case.
35
- self . measure {
36
- // Put the code you want to measure the time of here.
37
- }
18
+ func testRetainCycle( ) {
19
+ weak var weakView : UIView ? = nil
20
+ _ = { _ in
21
+ let strongView = UIView ( )
22
+ strongView. flex. direction ( . column)
23
+ weakView = strongView
24
+ } ( )
25
+
26
+ XCTAssertNil ( weakView, " Creation of flex should not lead to retain cycle " )
38
27
}
39
28
40
29
}
Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ public final class Flex {
31
31
/**
32
32
Flex items's UIView.
33
33
*/
34
- public let view : UIView
34
+ private ( set ) weak var view : UIView ?
35
35
private let yoga : YGLayout
36
36
37
37
/**
@@ -73,8 +73,12 @@ public final class Flex {
73
73
*/
74
74
@discardableResult
75
75
public func addItem( _ view: UIView ) -> Flex {
76
- self . view. addSubview ( view)
77
- return view. flex
76
+ if let host = self . view {
77
+ host. addSubview ( view)
78
+ return view. flex
79
+ } else {
80
+ preconditionFailure ( " Trying to modify deallocated host view " )
81
+ }
78
82
}
79
83
80
84
/**
@@ -954,8 +958,12 @@ public final class Flex {
954
958
*/
955
959
@discardableResult
956
960
public func backgroundColor( _ color: UIColor ) -> Flex {
957
- view. backgroundColor = color
958
- return self
961
+ if let host = self . view {
962
+ host. backgroundColor = color
963
+ return self
964
+ } else {
965
+ preconditionFailure ( " Trying to modify deallocated host view " )
966
+ }
959
967
}
960
968
961
969
// MARK: Enums
You can’t perform that action at this time.
0 commit comments