diff --git a/README.md b/README.md index c95612d..61b09c9 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,36 @@ # `@AccessAssociatedValue` Macros + + +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 diff --git a/images/usage.png b/images/usage.png new file mode 100644 index 0000000..dbdb707 Binary files /dev/null and b/images/usage.png differ