# @WrappedStore property wrapper to get rid of boilerplate

**URL:** <https://forums.swift.org/t/wrappedstore-property-wrapper-to-get-rid-of-boilerplate/49058>\
**Category:** Swift Composable Architecture\
**Tags:** propertywrapper\
**Created:** [May 31, 2021, 1:32am UTC](https://forums.swift.org/t/wrappedstore-property-wrapper-to-get-rid-of-boilerplate/49058 "2021-05-31T01:32:46Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![nikitamounier](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/nikitamounier/32/24825_2.png) [@nikitamounier](https://forums.swift.org/u/nikitamounier)\
**Post date:** [May 31, 2021, 1:15pm UTC](https://forums.swift.org/t/wrappedstore-property-wrapper-to-get-rid-of-boilerplate/49058/4 "2021-05-31T13:15:22Z")

</div>

> [@mbrandonw](#):
>
> With the way `@WrappedStore` is designed now you would always observe all state in the store every time you use it in a view

AFAIU, `@WrappedStore` behaves the exact same way as using a `store` property and an `@ObservedObject var viewStore`.  
`DynamicProperty` works in the same way as `View` in that it only triggers a reload when either a value type property is mutated, or it receives an `objectWillChange` signal – there's no way for it to know that a reference type was mutated otherwise.

I tested the view reload count using both methods – you can find the [gist with the code here](https://gist.github.com/nikitamounier/cbea8cde0193285ad32939837edac3da).

 ![Simulator Screen Shot - iPhone 12 - 2021-05-31 at 12.57.35](https://global.discourse-cdn.com/swift/original/3X/6/3/6319b864c90db6720e43ec204887ca6d5d86dcc9.png)

This is when using `@WrappedStore`:

 ![Screenshot 2021-05-31 at 12.58.46](https://global.discourse-cdn.com/swift/original/3X/7/f/7f92646577f04baee677c597ae372e3cb41521f4.jpeg)

And this is when using the `store` property / `@ObservedObject var viewStore`:

 ![Screenshot 2021-05-31 at 13.04.30](https://global.discourse-cdn.com/swift/original/3X/c/c/cc81f1a77178a44f126ba436d2e6cf1fbede456d.jpeg)

So, `@WrappedStore` is equivalent when you're just scoping the store down each view.

I agree, though, that right now we can't observe only a certain `ViewState` when using `@WrappedStore`, although I'm working on it right now.

Firstly, it would have to be a new property wrapper, since it introduces a third generic type for the new local state, and I wouldn't want to force the user of `@WrappedStore` to specify a third generic type which would be equivalent to the first. Let's call this property wrapper `@WrappedStoreLocal`.

The main issue is that is needs to phases of initialisation: one where the user passes in the closure/keypath which would convert parent state into the local state, and another where the caller passes in the store. This is simply not possible right now with property wrappers – [here's a gist](https://gist.github.com/nikitamounier/9ebfbbb2ff6a1362d889156472cd47d0) with my best try at an implementation of `@WrappedStoreLocal`.

I'd love to hear any solutions for this!

---

_[View the full topic](https://forums.swift.org/t/wrappedstore-property-wrapper-to-get-rid-of-boilerplate/49058)._
