You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Swift Declarative Configuration (SDC, for short) is a tiny library, that enables you to configure your objects in a declarative, consistent and understandable way, with ergonomics in mind. It can be used to configure any objects on any platform, including server-side-swift.
Provides modification functions for copying and modifying immutable stuff. It is useful for self-configuring objects like builder, when modifying methods should return modified `self`.
11
+
Functional configurator for anything, enables you to specify modification of an object and to apply the modification later. Primary way of declaring configurations for your objects.
Functional configurator for anything, enables you to specify modification of an object and to apply the modification later.
20
-
21
-
Also contains self-implementing protocols (`ConfigInitializable`, `CustomConfigurable`) to enable you add custom configuration support for your types (`NSObject` already conforms to it for you).
Functional builder for anything, enables you to modify object instances in a declarative way. Also contains `BuilderProvider` protocol with a computed `builder` property and implements that protocol on `NSObject` type.
Functional closures allow you to setup functional handlers & datasources, the API may seem a bit strange at the first look, so feel free to ask or discuss anything [here](https://github.com/MakeupStudio/swift-declarative-configuration/issues/1).
Functional builder for anything, enables you to modify object instances in a declarative way. Also contains `BuilderProvider` protocol with a computed `builder` property and implements that protocol on `NSObject` type.vBuilder-style way of declaring configurations for your objects. Suitable for instantiated objects.
34
16
35
17
## Basic Usage
36
18
@@ -55,15 +37,16 @@ class ImageViewController: UIViewController {
55
37
}
56
38
```
57
39
58
-
### FunctionalConfigurator
40
+
### Configurator
59
41
60
-
> **Note:** This way is **recommended**, but remember, that custom types **MUST** implement initializer with no parameters even if the superclass already has it or you will get a crash otherwise.
42
+
> [!NOTE]
43
+
> _This way is **recommended**._
61
44
62
45
```swift
63
-
importFunctionalConfigurator
46
+
importDeclarativeConfiguration
64
47
65
48
classImageViewController: UIViewController {
66
-
let imageView =UIImageView { $0
49
+
let imageView =UIImageView() { $0
67
50
.contentMode(.scaleAspectFit)
68
51
.backgroundColor(.black)
69
52
.layer.scope { $0
@@ -78,12 +61,10 @@ class ImageViewController: UIViewController {
78
61
}
79
62
```
80
63
81
-
### FunctionalBuilder
82
-
83
-
> **Note:** This way is recommended too, and it is more **safe**, because it modifies existing objects.
64
+
### Builder
84
65
85
66
```swift
86
-
importFunctionalBuilder
67
+
importDeclarativeConfiguration
87
68
88
69
classImageViewController: UIViewController {
89
70
let imageView =UIImageView().builder
@@ -104,6 +85,8 @@ class ImageViewController: UIViewController {
104
85
-`reduce(_:with:)`:
105
86
106
87
```swift
88
+
importDeclarativeConfiguration
89
+
107
90
structCounterState {
108
91
var value: Int=0
109
92
}
@@ -119,6 +102,9 @@ class ImageViewController: UIViewController {
119
102
120
103
### FunctionalClosures
121
104
105
+
> [!WARNING]
106
+
> _Deprecated_
107
+
122
108
### No SDC
123
109
124
110
**Declaration**
@@ -221,8 +207,6 @@ If your deployment target is iOS 17+ (or other platform with a corresponding ver
221
207
222
208
### More
223
209
224
-
#### Builder
225
-
226
210
Customize any object by passing initial value to a builder
227
211
228
212
```swift
@@ -248,6 +232,26 @@ let object = Object { $0
248
232
}
249
233
```
250
234
235
+
or batch-scoping
236
+
237
+
```swift
238
+
let object =Object { $0
239
+
.property.scope { $0
240
+
.subproperty1(value)
241
+
.subproperty2(value)
242
+
}
243
+
}
244
+
```
245
+
246
+
```swift
247
+
let object =Object { $0
248
+
.property.ifLetScope { $0// if property is optional
249
+
.subproperty1(value)
250
+
.subproperty2(value)
251
+
}
252
+
}
253
+
```
254
+
251
255
Conform your own types to `BuilderProvider` protocol to access builder property.
// Now you can access `location.builder.latitude(0).build()`
259
263
```
260
264
261
-
#### Configurator
262
-
263
-
> **Note:** Your NSObject classes **must** implement `init()` to use Configurators. It's a little trade-off for the convenience it brings to your codebase, see [tests](./Tests/DeclarativeConfigurationTests/ConfiguratorTests.swift) for an example.
264
-
265
-
#### DataSource
266
-
267
-
`OptionalDataSource` and `DataSource` types are very similar to the `Handler`, but if `Handler<Input>` is kinda `OptionalDataSource<Input, Void>`, the second one may have different types of an output. Usage is similar, different types are provided just for better semantics.
268
-
269
-
If your deployment target is iOS 17+ (or other platform with a corresponding version) you can use beta variadic generic `_DataSource` type
270
-
271
265
## Installation
272
266
273
267
### Basic
@@ -284,8 +278,8 @@ If you use SwiftPM for your project structure, add DeclarativeConfiguration to y
0 commit comments