@@ -16,8 +16,9 @@ public struct UniStateValue<Value> {
1616 public typealias SelfKeyPath = ReferenceWritableKeyPath < UniState , Self >
1717
1818 private let keyPath : ValueKeyPath
19- private let onSet : ( ( UniState , Value ) -> Void ) ?
19+ private let onSet : ( @ MainActor ( UniState , Value ) -> Void ) ?
2020
21+ @MainActor
2122 public static subscript(
2223 _enclosingInstance instance: UniState ,
2324 wrapped wrappedKeyPath: ValueKeyPath ,
@@ -39,7 +40,7 @@ public struct UniStateValue<Value> {
3940 set { fatalError ( ) }
4041 }
4142
42- init ( _ keyPath: ValueKeyPath , onSet: ( ( UniState , Value ) -> Void ) ? = nil ) {
43+ init ( _ keyPath: ValueKeyPath , onSet: ( @ MainActor ( UniState , Value ) -> Void ) ? = nil ) {
4344 self . keyPath = keyPath
4445 self . onSet = onSet
4546 }
@@ -49,14 +50,14 @@ public struct UniStateValue<Value> {
4950
5051extension UniStateValue where Value == Bool {
5152 init ( _ keyPath: ValueKeyPath , persist: UserDefaults . Key < Bool > ? = nil , bridge: UniBridge . BoolType ) {
52- self . init ( keyPath) { _, newValue in
53+ self . init ( keyPath) { @ MainActor _, newValue in
5354 if let key = persist { UserDefaults . standard. set ( newValue, for: key) }
5455 UniBridge . shared. boolMapper. setValue ( bridge, newValue)
5556 }
5657 }
5758
5859 init ( _ keyPath: ValueKeyPath , persistAsInt: UserDefaults . Key < Int > , trueValue: Int = 1 , bridge: UniBridge . BoolType ) {
59- self . init ( keyPath) { _, newValue in
60+ self . init ( keyPath) { @ MainActor _, newValue in
6061 UserDefaults . standard. set ( newValue ? trueValue : 0 , for: persistAsInt)
6162 UniBridge . shared. boolMapper. setValue ( bridge, newValue)
6263 }
@@ -67,14 +68,14 @@ extension UniStateValue where Value == Bool {
6768
6869extension UniStateValue where Value == CGFloat {
6970 init ( _ keyPath: ValueKeyPath , persist: UserDefaults . Key < Double > ? = nil , bridge: UniBridge . FloatType ) {
70- self . init ( keyPath) { _, newValue in
71+ self . init ( keyPath) { @ MainActor _, newValue in
7172 if let key = persist { UserDefaults . standard. set ( Double ( newValue) , for: key) }
7273 UniBridge . shared. floatMapper. setValue ( bridge, newValue)
7374 }
7475 }
7576
7677 init ( _ keyPath: ValueKeyPath , bridge: UniBridge . FloatType ) {
77- self . init ( keyPath) { _, newValue in
78+ self . init ( keyPath) { @ MainActor _, newValue in
7879 UniBridge . shared. floatMapper. setValue ( bridge, newValue)
7980 }
8081 }
@@ -84,14 +85,14 @@ extension UniStateValue where Value == CGFloat {
8485
8586extension UniStateValue where Value == Int32 {
8687 init ( _ keyPath: ValueKeyPath , persist: UserDefaults . Key < Int > ? = nil , bridge: UniBridge . IntType ) {
87- self . init ( keyPath) { _, newValue in
88+ self . init ( keyPath) { @ MainActor _, newValue in
8889 if let key = persist { UserDefaults . standard. set ( Int ( newValue) , for: key) }
8990 UniBridge . shared. intMapper. setValue ( bridge, newValue)
9091 }
9192 }
9293
9394 init ( _ keyPath: ValueKeyPath , bridge: UniBridge . IntType ) {
94- self . init ( keyPath) { _, newValue in
95+ self . init ( keyPath) { @ MainActor _, newValue in
9596 UniBridge . shared. intMapper. setValue ( bridge, newValue)
9697 }
9798 }
@@ -101,7 +102,7 @@ extension UniStateValue where Value == Int32 {
101102
102103extension UniStateValue where Value == String {
103104 init ( _ keyPath: ValueKeyPath , persist: UserDefaults . Key < String > ? = nil , bridge: UniBridge . StringType ) {
104- self . init ( keyPath) { _, newValue in
105+ self . init ( keyPath) { @ MainActor _, newValue in
105106 if let key = persist { UserDefaults . standard. set ( newValue, for: key) }
106107 UniBridge . shared. stringMapper. setValue ( bridge, newValue)
107108 }
@@ -112,7 +113,7 @@ extension UniStateValue where Value == String {
112113
113114extension UniStateValue where Value == Color {
114115 init ( _ keyPath: ValueKeyPath , persist: UserDefaults . Key < String > ? = nil , bridge: UniBridge . StructType ) {
115- self . init ( keyPath) { _, newValue in
116+ self . init ( keyPath) { @ MainActor _, newValue in
116117 if let key = persist, let hex = newValue. hexRGBAString {
117118 UserDefaults . standard. set ( hex, for: key)
118119 }
@@ -121,7 +122,7 @@ extension UniStateValue where Value == Color {
121122 }
122123
123124 init ( _ keyPath: ValueKeyPath , bridge: UniBridge . StructType ) {
124- self . init ( keyPath) { _, newValue in
125+ self . init ( keyPath) { @ MainActor _, newValue in
125126 UniBridge . shared. structMapper. binding ( bridge) . wrappedValue = newValue
126127 }
127128 }
0 commit comments