Skip to content

Commit

Permalink
Merge pull request #7 from coffmark/feature/update-readme
Browse files Browse the repository at this point in the history
Update README.md
  • Loading branch information
coffmark authored Dec 13, 2023
2 parents d98f480 + 553021f commit a8fcb76
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,36 @@
# `@AccessAssociatedValue` Macros

<img src="./images/usage.png" >

If you expand macros, it'll look like this
```swift
@AccessAssociatedValue
enum ViewState {
case loading(isInticator: Bool)
case success(cards: [String], isIndicator: Bool)
case failed(isIndicator: Bool)
}

let viewState = ViewState.success(cards: ["Card1", "Card2"], isIndicator: false)
print(viewState.loading) // nil
print(viewState.success?.cards) // ["Card1", "Card2"]
+ var loading: (isIndicator: Bool)? {
+ guard case let .loading(isIndicator) = self else {
+ return nil
+ }
+ return (isIndicator)
+ }
+
+ var success: (cards: [String], isIndicator: Bool)? {
+ guard case let .success(cards, isIndicator) = self else {
+ return nil
+ }
+ return (cards: cards, isIndicator: isIndicator)
+ }
+
+ var failed: (isIndicator: Bool)? {
+ guard case let .failed(isIndicator) = self else {
+ return nil
+ }
+ return (isIndicator)
+ }
}
```
- Easy to access associated value
- Type safe
Expand Down
Binary file added images/usage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a8fcb76

Please sign in to comment.