Skip to content

Commit 5390b14

Browse files
Update custom configuration documentation (#874)
* Update custom configuration documentation * Fix RxSwift documentation * Add “and setup” * Add line breaks in perceptible preview store * Update perception documentation * Fix relative link * Use GitHub styles alerts in markdown * Improve header * Turn optional guidance into tip
1 parent 4073512 commit 5390b14

File tree

4 files changed

+73
-37
lines changed

4 files changed

+73
-37
lines changed

Customization/Configuration.md

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# Nodes Configuration
22

3-
While Nodes works out-of-the-box with [UIKit](https://developer.apple.com/documentation/uikit) and [SwiftUI](https://developer.apple.com/xcode/swiftui) (for iOS), the following custom configuration is required to use other UI frameworks, such as [AppKit](https://developer.apple.com/documentation/appkit).
3+
Nodes is easily customized using a YAML configuration file. The [sample](#sample-config-file) below demonstrates the available options.
4+
5+
While Nodes is configured by default for iOS with [UIKit](https://developer.apple.com/documentation/uikit) and [SwiftUI](https://developer.apple.com/xcode/swiftui), UI frameworks for [AppKit](https://developer.apple.com/documentation/appkit) or other platforms may be enabled.
46

57
## Configure the Xcode Templates Generator
68

7-
Specify a path to a custom config file by providing the `--config` option when executing `nodes-xcode-templates-gen`.
9+
Specify a path to a custom config file by providing the `--config` option when executing the `nodes-xcode-templates-gen` command.
810

911
<details>
1012

@@ -18,7 +20,7 @@ If utilizing the [quick start project setup](https://github.com/Tinder/Nodes#qui
1820
swift run --skip-build -- nodes-xcode-templates-gen --id "Custom" --config "nodes.yml"
1921
```
2022

21-
> TIP: The provided `id` value is used to uniquely identify different sets of templates within the new file dialog in Xcode.
23+
> The provided `id` value is used to uniquely identify different sets of templates within the new file dialog in Xcode.
2224
2325
The script that creates the presets in the quick start project should use the same config file:
2426

@@ -28,16 +30,17 @@ swift run --skip-build -- nodes-code-gen --preset "$PRESET" --author "$AUTHOR" -
2830

2931
</details>
3032

31-
### Sample Config File
33+
## Sample Config File
3234

33-
All values shown in the samples below are the defaults.
35+
All values shown in the sample are the defaults.
3436

35-
> TIP: It is only necessary to include config options that are different from the defaults.
37+
> [!TIP]
38+
> It is only necessary to include config options that are different from the defaults.
3639
3740
```yaml
3841
uiFrameworks:
3942
- framework: UIKit
40-
- framework: SwiftUI
43+
- framework: UIKit (SwiftUI)
4144
baseImports: []
4245
baseTestImports:
4346
- Nimble
@@ -83,36 +86,28 @@ isTestTemplatesGenerationEnabled: true
8386
isPeripheryCommentEnabled: false
8487
```
8588
86-
To control which UI Frameworks are made available within the new file dialog in Xcode, include AppKit, UIKit, or SwiftUI as shown below; or a fully custom UI framework may be configured for unique use cases. More than one UI framework can be included in the configuration. And by default, without providing any UI framework configuration, UIKit and SwiftUI (for iOS) are automatically configured.
89+
## UI Frameworks
8790
88-
> TIP: For use in an iOS app that allows both UIKit and SwiftUI, both may be enabled simultaneously if desired.
91+
The UI framework presets available to enable in the config file are `AppKit`, `AppKit (SwiftUI)`, `UIKit` and `UIKit (SwiftUI)`. A fully custom UI framework may be configured for unique use cases.
8992

90-
#### AppKit
93+
More than one UI framework may be included in the configuration. Without specifying any UI frameworks, `UIKit` and `UIKit (SwiftUI)` are enabled by default.
9194

9295
```yaml
9396
- framework: AppKit
9497
```
9598

96-
#### UIKit
99+
```yaml
100+
- framework: AppKit (SwiftUI)
101+
```
97102

98103
```yaml
99104
- framework: UIKit
100105
```
101106

102-
#### SwiftUI
103-
104-
> IMPORTANT: SwiftUI is only supported in iOS apps currently (SwiftUI support for macOS apps may be added in the future).
105-
106107
```yaml
107-
- framework: SwiftUI
108+
- framework: UIKit (SwiftUI)
108109
```
109110

110-
#### Custom
111-
112-
> IMPORTANT: A non-empty string must be provided for `name`, `import` and `viewControllerType`.
113-
114-
> TIP: The `viewControllerSuperParameters` and `viewControllerMethods` keys may be omitted.
115-
116111
```yaml
117112
- framework:
118113
custom:
@@ -122,3 +117,9 @@ To control which UI Frameworks are made available within the new file dialog in
122117
viewControllerSuperParameters: ""
123118
viewControllerMethods: ""
124119
```
120+
121+
> [!IMPORTANT]
122+
> A non-empty string must be provided for `name`, `import` and `viewControllerType`.
123+
124+
> [!TIP]
125+
> The `viewControllerSuperParameters` and `viewControllerMethods` keys may be omitted.

Customization/Perception.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
A store compatible with [Perception](https://github.com/pointfreeco/swift-perception).
1+
# Using Perception with Nodes
2+
3+
While Nodes is compatible with the [Observation](https://developer.apple.com/documentation/observation) framework for newer operating system versions or can be [configured](Configuration.md) to use [`ObservableObject`](https://developer.apple.com/documentation/Combine/ObservableObject) for backward compatibility, other observation libraries such [Perception](https://github.com/pointfreeco/swift-perception) require custom setup.
4+
5+
## Add Supporting Types
6+
7+
Add the following types to the application:
28

39
```swift
410
//
@@ -149,7 +155,9 @@ private class PerceptibleViewStateStoreBase<
149155
@Perceptible
150156
@preconcurrency
151157
@MainActor
152-
public final class PerceptiblePreviewStore<ViewState: Equatable>: PerceptibleViewStateStore {
158+
public final class PerceptiblePreviewStore<
159+
ViewState: Equatable
160+
>: PerceptibleViewStateStore {
153161

154162
public var viewState: ViewState
155163

Customization/RxSwift.md

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Using RxSwift with Nodes
22

3-
While Nodes works out-of-the-box with [Combine](https://developer.apple.com/documentation/combine), the following custom configuration and setup is required to use other reactive frameworks, such [RxSwift](https://github.com/ReactiveX/RxSwift).
3+
While Nodes is configured by default for [Combine](https://developer.apple.com/documentation/combine), other reactive frameworks such [RxSwift](https://github.com/ReactiveX/RxSwift) require custom configuration and setup.
44

55
## Configure the Xcode Templates Generator
66

7-
Specify a path to a custom config file by providing the `--config` option when executing `nodes-xcode-templates-gen`.
7+
Specify a path to a custom config file by providing the `--config` option when executing the `nodes-xcode-templates-gen` command.
88

99
<details>
1010

@@ -18,7 +18,7 @@ If utilizing the [quick start project setup](https://github.com/Tinder/Nodes#qui
1818
swift run --skip-build -- nodes-xcode-templates-gen --id "RxSwift" --config "nodes.yml"
1919
```
2020

21-
> TIP: The provided `id` value is used to uniquely identify different sets of templates within the new file dialog in Xcode.
21+
> The provided `id` value is used to uniquely identify different sets of templates within the new file dialog in Xcode.
2222
2323
The script that creates the presets in the quick start project should use the same config file:
2424

@@ -28,13 +28,13 @@ swift run --skip-build -- nodes-code-gen --preset "$PRESET" --author "$AUTHOR" -
2828

2929
</details>
3030

31-
### Sample Config File
31+
## Sample Config File
3232

3333
```yaml
3434
uiFrameworks:
3535
- framework:
3636
custom:
37-
name: UIKit
37+
name: UIKit (RxSwift)
3838
import: UIKit
3939
viewControllerType: UIViewController
4040
viewControllerSuperParameters: "nibName: nil, bundle: nil"
@@ -60,7 +60,6 @@ uiFrameworks:
6060
LeakDetector.detect(disposeBag)
6161
disposeBag = DisposeBag()
6262
}
63-
- framework: SwiftUI
6463
reactiveImports:
6564
- RxSwift
6665
viewControllerSubscriptionsProperty: |-
@@ -72,7 +71,7 @@ viewStateOperators: |-
7271
.observe(on: MainScheduler.instance)
7372
viewStatePropertyComment: The view state observable
7473
viewStatePropertyName: stateObservable
75-
viewStateTransform: context.$state.map { viewStateFactory($0) }
74+
viewStateTransform: store.viewStatePublisher.asObservable()
7675
publisherType: Observable
7776
publisherFailureType: ""
7877
contextGenericTypes: []
@@ -138,6 +137,27 @@ extension StateObserver {
138137
}
139138
}
140139

140+
extension Publisher {
141+
142+
public func asObservable() -> Observable<Output> {
143+
Observable.create { observer in
144+
let cancellable: AnyCancellable = sink { completion in
145+
switch completion {
146+
case .finished:
147+
observer.onCompleted()
148+
case let .failure(error):
149+
observer.onError(error)
150+
}
151+
} receiveValue: { value in
152+
observer.onNext(value)
153+
}
154+
return Disposables.create {
155+
cancellable.cancel()
156+
}
157+
}
158+
}
159+
}
160+
141161
extension Observable: Publisher {
142162

143163
public typealias Output = Element

README.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,12 @@ Each node is comprised of a few pre-defined types working in conjunction to powe
5656

5757
Nodes' Xcode templates are required to ensure correct use of the Nodes framework and to guarantee that every created node is properly defined.
5858

59-
Installation of the templates is performed by the Xcode templates generator (the `nodes-xcode-templates-gen` executable in the Swift package). Without customizing the generator, Xcode templates for UIKit and SwiftUI (for iOS) are installed by default. The generator supports [optional customization](#optional-customization) if needed.
59+
Installation of the templates is performed by the Xcode templates generator (the `nodes-xcode-templates-gen` executable in the Swift package). Without customizing the generator, Xcode templates for iOS with [UIKit](https://developer.apple.com/documentation/uikit) and [SwiftUI](https://developer.apple.com/xcode/swiftui) are installed by default. The generator supports [optional customization](#optional-customization) if needed.
6060

6161
#### Xcode Templates Installation
6262

63-
> TIP: After completing the [Quick Start](#quick-start) setup (below), Nodes' Xcode templates will be ***installed automatically***, so these instructions to manually install the Xcode templates ***may be skipped*** and are included here simply as a reference.
63+
> [!TIP]
64+
> After completing the [Quick Start](#quick-start) setup (below), Nodes' Xcode templates will be ***installed automatically***, so these instructions to manually install the Xcode templates ***may be skipped*** and are included here simply as a reference.
6465
6566
<details>
6667

@@ -92,7 +93,8 @@ The Xcode templates will be installed to the following location to be made avail
9293

9394
Documentation is available online at: [https://Tinder.github.io/Nodes](https://Tinder.github.io/Nodes)
9495

95-
> TIP: After completing the [Quick Start](#quick-start) setup (below), documentation is viewable in Xcode by selecting `Build Documentation` from the `Product` menu.
96+
> [!TIP]
97+
> After completing the [Quick Start](#quick-start) setup (below), documentation is viewable in Xcode by selecting `Build Documentation` from the `Product` menu.
9698
9799
## Quick Start
98100

@@ -139,7 +141,8 @@ mint run genesis generate <path>/genesis.yml --options "author:$(git config user
139141

140142
When prompted, enter the latest Nodes version, a name for the new iOS Xcode project and an organization identifier (which is the bundle ID prefix such as `com.tinder`).
141143

142-
**OPTIONAL:** The cloned Nodes repository is no longer needed at this point and may be removed if there is no plan to create additional projects.
144+
> [!TIP]
145+
> The cloned Nodes repository is no longer needed at this point and may be removed if there is no plan to create additional projects.
143146
144147
### Generate Xcode Project
145148

@@ -178,11 +181,15 @@ brew reinstall --build-from-source mockolo
178181

179182
### UI Frameworks
180183

181-
While Nodes works out-of-the-box with [UIKit](https://developer.apple.com/documentation/uikit) and [SwiftUI](https://developer.apple.com/xcode/swiftui) (for iOS), custom [configuration is required](Customization/Configuration.md) to use other UI frameworks, such as [AppKit](https://developer.apple.com/documentation/appkit).
184+
While Nodes is configured by default for iOS with [UIKit](https://developer.apple.com/documentation/uikit) and [SwiftUI](https://developer.apple.com/xcode/swiftui), UI frameworks for [AppKit](https://developer.apple.com/documentation/appkit) or other platforms may be enabled with [custom configuration](Customization/Configuration.md).
185+
186+
### Observation Frameworks
187+
188+
While Nodes is compatible with the [Observation](https://developer.apple.com/documentation/observation) framework for newer operating system versions or can be [configured](Customization/Configuration.md) to use [`ObservableObject`](https://developer.apple.com/documentation/Combine/ObservableObject) for backward compatibility, other observation libraries such [Perception](https://github.com/pointfreeco/swift-perception) require [custom setup](Customization/Perception.md).
182189

183190
### Reactive Frameworks
184191

185-
While Nodes works out-of-the-box with [Combine](https://developer.apple.com/documentation/combine), custom [configuration and setup is required](Customization/RxSwift.md) to use other reactive frameworks, such [RxSwift](https://github.com/ReactiveX/RxSwift).
192+
While Nodes is configured by default for [Combine](https://developer.apple.com/documentation/combine), other reactive frameworks such [RxSwift](https://github.com/ReactiveX/RxSwift) require [custom configuration and setup](Customization/RxSwift.md).
186193

187194
## Extras
188195

0 commit comments

Comments
 (0)