Skip to content

Commit ccd2025

Browse files
committed
Keep weak reference to view from Flex; hide view property
1 parent c880dc1 commit ccd2025

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

Sources/FlexLayout.swift

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public final class Flex {
3131
/**
3232
Flex items's UIView.
3333
*/
34-
public let view: UIView
34+
private weak var view: UIView?
3535
private let yoga: YGLayout
3636

3737
/**
@@ -73,8 +73,12 @@ public final class Flex {
7373
*/
7474
@discardableResult
7575
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+
}
7882
}
7983

8084
/**
@@ -954,8 +958,12 @@ public final class Flex {
954958
*/
955959
@discardableResult
956960
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+
}
959967
}
960968

961969
// MARK: Enums

0 commit comments

Comments
 (0)