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
Copy file name to clipboardExpand all lines: README.md
+99
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,42 @@
2
2
3
3
ImmutableSwift is a tool that generates swift model that supports immutability, coding(Coding and NSCoding), value comparions, hashing and copying. Directly inspired by [facebook/remodel](https://github.com/facebook/remodel).
@@ -31,3 +68,65 @@ To generate models for every .value files in a directory, subtitute the file pat
31
68
./ImmutableSwift Path/To/ModelDirectory/
32
69
```
33
70
71
+
## Import
72
+
ImmutableSwift assumes that every types that a model depends on reside in the same module. If a model depends on another module, simply add the required module on top of the schema. For example:
73
+
```
74
+
import PhoneNumber
75
+
Friend {
76
+
String name
77
+
Int daySinceFirstMet
78
+
PhoneNumber number
79
+
}
80
+
```
81
+
The syntax for import are the same as swift's import syntax. You can import a module with `import module`, import a submodule with `improt module.submodule` or import a specific kind of symbol with `import kind module.symbole`
82
+
83
+
## Comments
84
+
ImmutableSwift supports adding comments to the generated models.
85
+
```
86
+
import PhoneNumber
87
+
Friend {
88
+
# example comment
89
+
String name
90
+
# at the moment, ImmutableSwift only support comments inside the model bracket (between brackets)
91
+
Int daySinceFirstMet
92
+
# comment must be in its own line, and starts with a pound sign #
93
+
PhoneNumber number
94
+
}
95
+
```
96
+
97
+
## AccessControl
98
+
ImmutableSwift supports defining optional access levels for the generated model. At the moment, it only supports `public` and `internal`. This is mainly to help generate models in a module that are meant to be imported. For example:
99
+
```
100
+
public Friend {
101
+
String name
102
+
Int daySinceFirstMet
103
+
}
104
+
```
105
+
106
+
## NSCoding
107
+
In some projects, immutable data model might need to support NSCoding. To have ImmutableSwift generates associated methods that support NSCoding, include the plugin `ISCoding` in the model's schema.
108
+
```
109
+
# here, ISCoding plugin is responsible for generating the encode and init method required by NSCoding protocol
110
+
# ISCopying plugin is responsible for generating the copy method required by the NSCopying protocol
111
+
public Friend (ISCoding, ISCopying){
112
+
String name
113
+
Int daySinceFirstMet
114
+
}
115
+
```
116
+
117
+
## Plugins
118
+
Similar to [facebook/remodel](https://github.com/facebook/remodel), ImmutableSwift uses a simple plugin system. The plugin system are designed to encapsulate cohesive generation logics, and extend the functionality of the code generator. You can find a list of plugins here: https://github.com/hackthehackerman/ImmutableSwift/tree/master/Sources/ImmutableSwift/generating/plugins.
119
+
120
+
To specify plugins for a specific model, add the list after the model name. Noted that, if you don't specific a list of plugins to used, ImmutableSwift will use a default list of plugins: [ISCodable, ISHashable, ISCopying].
121
+
```
122
+
# ISCodable is responsible for generating codes for the Codable protocol
123
+
# ISHashable is responsible for generating the == and hash function for the Hashable protocol
124
+
# ISCopying plugin is responsible for generating the copy method required by the NSCopying protocol
0 commit comments