Skip to content

Commit 97f0582

Browse files
authored
Merge pull request #2194 from woocommerce/update/docs-coding-guidelines
Docs: Add Coding Guidelines about Structs vs Classes
2 parents 56cadad + f5258ff commit 97f0582

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

docs/README.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
# WooCommerce for iOS
22

3-
## Getting Started
4-
5-
- [Coding Style Guide](coding-style-guide.md)
6-
73
## Architecture
84

95
- [Architecture](ARCHITECTURE.md)
106
- [Networking](NETWORKING.md)
117
- [Storage](STORAGE.md)
128
- [Yosemite](YOSEMITE.md)
9+
10+
## Coding Guidelines
11+
12+
### Coding Style
13+
14+
The guidelines for how Swift should be written and formatted can be found in the [Coding Style Guide](coding-style-guide.md).
15+
16+
### Choosing Between Structures and Classes
17+
18+
In addition to the [Apple guidelines](https://developer.apple.com/documentation/swift/choosing_between_structures_and_classes), we generally prefer to use `struct` for:
19+
20+
- Value types like the [Networking Models](../../../Networking/Networking/Model)
21+
- Stateless helpers
22+
23+
But consider using `class` instead if:
24+
25+
- You need to manage mutable states. Especially if there are more than a few `mutating` functions, the `struct` becomes harder to reason about.
26+
- You have to set a `struct` property declaration as `var` because it has a `mutating` function. In this case, a constant (`let`) `class` property may be easier to reason about.

0 commit comments

Comments
 (0)