-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix the API error "can't mutate self is immutable" for BindKeyed in S…
…wiftUI view (#31) Since `KeyedValueBinding` was a variable on the wrapper and wrapper was a variable on view that is structure — semantically we were mutating self. I moved it to the wrapper itself, and projectedValue now returns the wrapper, and added a subscript that is non mutating semantically.
- Loading branch information
1 parent
6a21824
commit fdae42e
Showing
8 changed files
with
127 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the Decide package open source project | ||
// | ||
// Copyright (c) 2020-2023 Maxim Bazarov and the Decide package | ||
// open source project authors | ||
// Licensed under MIT | ||
// | ||
// See LICENSE.txt for license information | ||
// | ||
// SPDX-License-Identifier: MIT | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
import SwiftUI | ||
import Decide | ||
import XCTest | ||
import DecideTesting | ||
|
||
@MainActor final class SwiftUI_Tests: XCTestCase { | ||
|
||
final class State: KeyedState<Int> { | ||
@Property var str = "str-default" | ||
@Mutable @Property var strMutable = "strMutable-default" | ||
} | ||
|
||
struct ViewUnderTest: View { | ||
@BindKeyed(\State.$strMutable) var strMutable | ||
@ObserveKeyed(\State.$str) var str | ||
@ObserveKeyed(\State.$strMutable) var strMutableObserved | ||
|
||
var body: some View { | ||
TextField("", text: strMutable[1]) | ||
Text(str[1]) | ||
Text(strMutableObserved[1]) | ||
} | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters