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.
6
6
@@ -12,47 +12,69 @@ Swift Declarative Configuration (SDC, for short) is a tiny library, that enables
KeyPath functional wrappers, one is generalized and the other is for enums. [CasePath is a dependency](https://github.com/pointfreeco/swift-case-paths).
15
+
KeyPath functional wrappers, one is generalized and the other is for enums. _[CasePath is a dependency](https://github.com/pointfreeco/swift-case-paths)_.
Funtional configurator for anything, enables you to specify modification of an object and to apply the modification later.
20
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.
25
+
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.
Maybe it worth to make another abstraction over configurator for UI setup, but for example I'll be using pure version.
35
+
```swift
36
+
classImageViewController: UIViewController {
37
+
let imageView =UIImageView()
38
+
39
+
overridefuncloadView() {
40
+
self.view= imageView
41
+
}
42
+
43
+
overridefuncviewDidLoad() {
44
+
super.viewDidLoad()
45
+
imageView.contentMode= .scaleAspectFit
46
+
imageView.backgroundColor= .black
47
+
imageView.layer.masksToBounds=true
48
+
imageView.layer.cornerRadius=10
49
+
}
50
+
}
51
+
```
52
+
53
+
### UIKit & FunctionalConfigurator
34
54
35
55
```swift
36
56
importFunctionalConfigurator
37
57
38
58
classImageViewController: UIViewController {
39
-
enumStyleSheet {
40
-
staticlet imageView = Configurator<UIImageView>
41
-
.contentMode(.scaleAspectFit)
42
-
.backgroundColor(.black)
43
-
.layer.masksToBounds(true)
44
-
.layer.cornerRadius(10)
45
-
}
46
59
47
-
let imageView =UIImageView(config: StyleSheet.imageView)
60
+
let imageView =UIImageView { $0
61
+
.contentMode(.scaleAspectFit)
62
+
.backgroundColor(.black)
63
+
.layer.masksToBounds(true)
64
+
.layer.cornerRadius(10)
65
+
}
48
66
49
67
overridefuncloadView() {
50
68
self.view= imageView
51
69
}
70
+
52
71
}
53
72
```
54
73
74
+
**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.
75
+
55
76
### UIKit & FunctionalBuilder
77
+
56
78
```swift
57
79
importFunctionalBuilder
58
80
@@ -70,40 +92,51 @@ class ImageViewController: UIViewController {
70
92
}
71
93
```
72
94
73
-
### Modification
95
+
Note: This way is recommended too, and it is more **safe**, because it modifies existing objects.
96
+
97
+
### Other usecases
98
+
99
+
#### Builder
100
+
101
+
Customize any object by passing initial value to a builder
74
102
75
103
```swift
76
-
importFunctionalModification
104
+
let object =Builder(Object())
105
+
.property.subproperty(value)
106
+
.build() // Returns modified object
107
+
```
77
108
78
-
structMyModel {
79
-
var value1 =0
80
-
init() {}
81
-
}
109
+
For classes you can avoid returning a value by calling `apply` method, instead of `build`
82
110
83
-
let model_0 =MyModel()
84
-
let model_1 =modification(of: model_0) { $0.value=1 }
111
+
```swift
112
+
let _class =_Class()
113
+
Builder(_class)
114
+
.property.subproperty(value)
115
+
.apply() // Returns Void
116
+
```
85
117
86
-
importUIKit
118
+
Conform your own types to `BuilderProvider` protocol to access builder property.
// Now you can access `location.builder.latitude(0).build()`
97
126
```
98
127
128
+
#### Configurator
129
+
130
+
> README PLACEHOLDER (Not yet written 😅)
131
+
99
132
## Installation
100
133
101
134
### Basic
102
135
103
136
You can add DeclarativeConfiguration to an Xcode project by adding it as a package dependency.
104
137
105
138
1. From the **File** menu, select **Swift Packages › Add Package Dependency…**
106
-
2. Enter "https://github.com/makeupstudio/swift-declarative-configuration" into the package repository URL text field
139
+
2. Enter [`"https://github.com/makeupstudio/swift-declarative-configuration"`](https://github.com/makeupstudio/swift-declarative-configuration) into the package repository URL text field
107
140
3. Choose products you need to link them to your project.
108
141
109
142
### Recommended
@@ -113,7 +146,7 @@ If you use SwiftPM for your project, you can add DeclarativeConfiguration to you
0 commit comments