Skip to content

Commit d109657

Browse files
committed
feat: Support functional programming
1 parent 7fe3b1b commit d109657

File tree

5 files changed

+65
-17
lines changed

5 files changed

+65
-17
lines changed

README.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,16 @@
99
#### 🤔 Why do you need SwiftUINavigator when you have a UIHostingController?
1010
> With UIHostingController, I faced bugs that were hard to predict and could not be resolved. That's why I made SwiftUINavigator to solve those problems.
1111
12-
## ✔️ Example
12+
## ✔️ Simple Example
13+
```swift
14+
SwiftUIView() // return View
15+
.asViewController() // return WrapperViewController
16+
.title("SwiftUIView") // return UIViewController
17+
.backgroundColor(.gray) // return UIViewController
18+
.hidesBottomBarWhenPushed(true) // return UIViewController
19+
```
20+
21+
## ✔️ Project Example
1322

1423
### UIKit side
1524
```swift

Sources/SwiftUINavigator/UIViewController+.swift Sources/SwiftUINavigator/UIViewController+/UIViewController+.swift

-13
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,7 @@
99
import UIKit
1010

1111
public extension UIViewController {
12-
13-
private struct AssociatedKeys {
14-
static var identifier = "Identifier"
15-
}
1612

17-
var identifier: String? {
18-
get {
19-
objc_getAssociatedObject(self, &AssociatedKeys.identifier) as? String
20-
}
21-
set {
22-
objc_setAssociatedObject(self, &AssociatedKeys.identifier, newValue, .OBJC_ASSOCIATION_RETAIN)
23-
}
24-
}
25-
2613
func addChildAndSubView(_ controller: UIViewController) {
2714
self.addChild(controller)
2815
controller.view.frame = self.view.frame
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//
2+
// UIViewController+functional.swift
3+
//
4+
//
5+
// Created by 김인섭 on 10/15/23.
6+
//
7+
8+
#if canImport(UIKit)
9+
import UIKit
10+
11+
public extension UIViewController {
12+
13+
func title(_ title: String?) -> Self {
14+
self.title = title
15+
return self
16+
}
17+
18+
func hidesBottomBarWhenPushed(_ state: Bool) -> Self {
19+
self.hidesBottomBarWhenPushed = state
20+
return self
21+
}
22+
23+
func backgroundColor(_ color: UIColor?) -> Self {
24+
self.view.backgroundColor = color
25+
return self
26+
}
27+
}
28+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//
2+
// UIViewController+indentifier.swift
3+
//
4+
//
5+
// Created by 김인섭 on 10/15/23.
6+
//
7+
8+
#if canImport(UIKit)
9+
import UIKit
10+
11+
public extension UIViewController {
12+
13+
private struct AssociatedKeys {
14+
static var identifier = "Identifier"
15+
}
16+
17+
var identifier: String? {
18+
get {
19+
objc_getAssociatedObject(self, &AssociatedKeys.identifier) as? String
20+
}
21+
set {
22+
objc_setAssociatedObject(self, &AssociatedKeys.identifier, newValue, .OBJC_ASSOCIATION_RETAIN)
23+
}
24+
}
25+
}
26+
#endif

Sources/SwiftUINavigator/WrapperViewController.swift

+1-3
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ public class WrapperViewController<Content: Wrappable>: UIViewController {
1717
init(
1818
content: Content,
1919
indentifier: String,
20-
backgroundColor: UIColor? = nil,
21-
hidesBottomBarWhenPushed: Bool = true
20+
backgroundColor: UIColor? = nil
2221
) {
2322
self.navigator = Navigator()
2423
self.content = content
@@ -27,7 +26,6 @@ public class WrapperViewController<Content: Wrappable>: UIViewController {
2726

2827
self.identifier = indentifier
2928
self.view.backgroundColor = backgroundColor ?? .systemBackground
30-
self.hidesBottomBarWhenPushed = hidesBottomBarWhenPushed
3129

3230
setHController()
3331
}

0 commit comments

Comments
 (0)