Skip to content

Commit 10c7c51

Browse files
committed
Remove variable string assignment from public interface
It's unclear how to write assignments that work on all String things, even on let Var(...), without compile ambiguity
1 parent af2d732 commit 10c7c51

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

Code/Public/Variable/Variable+String.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
// MARK: - Concatenating
22

3-
infix operator +=: AssignmentPrecedence
4-
5-
public func +=<S1: StringValue, S2: StringValue>(str1: inout S1, str2: S2)
6-
{
7-
str1.string = str1.string + str2.string
8-
}
9-
103
infix operator +: AdditionPrecedence
114

125
public func +<S1: StringValue, S2: StringValue>(str1: S1, str2: S2) -> String

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ SwiftObserver is just about 1200 lines of production code, but it also approache
2222
* [Introduction](#introduction)
2323
* [Memory Management](#memory-management)
2424
* [Variables](#variables)
25-
* [Set Variable Values](#set-variable-values)
25+
* [Use Variable Values](#use-variable-values)
2626
* [Observe Variables](#observe-variables)
2727
* [Variables are Codable](#variables-are-codable)
2828
* [Mappings](#mappings)
@@ -177,7 +177,7 @@ The three above mentioned functions are all you need for safe memory management.
177177

178178
A `Var<Value>` has a property `value: Value`. If `Value` conforms to `Equatable` or `Comparable`, the whole `Var<Value>` will also conform to the respective protocol.
179179

180-
## Set Variable Values
180+
## Use Variable Values
181181

182182
You can set `value` directly, via initializer and via the `<-` operator:
183183

@@ -199,15 +199,15 @@ If `Value` is either `Int`, `Float` or `Double`:
199199
3. ```swift
200200
let numVar = Var<Int?>() // numVar.value == nil
201201
print(numVar.int) // 0
202-
numVar <- Var(3) + 2 // numVar.value == 5
203-
numVar.int += 5 // numVar.value == 10
202+
numVar.int += 5 // numVar.value == 5
203+
numVar <- Var(1) + 2 // numVar.value == 3
204204
```
205205

206206
### String Values
207207

208208
1. Every `Var<String>`, `Var<String?>`, `Var<String>?` and `Var<String?>?` has a `var string: String` which is non-optional and interprets `nil` values as `""`.
209209
2. Representing its `string` property, every `Var<String>` and `Var<String?>` conforms to `BidirectionalCollection`, `Collection` and `Sequence`.
210-
3. You can apply concatenation operators `+` and `+=` to all pairs of `String`, `String?`, `Var<String>`, `Var<String?>`, `Var<String>?` and `Var<String?>?`.
210+
3. You can apply concatenation operator `+` to all pairs of `String`, `String?`, `Var<String>`, `Var<String?>`, `Var<String>?` and `Var<String?>?`.
211211

212212
## Observe Variables
213213

Tests/SwiftObserverTests/SwiftObserverTests.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ import Foundation
44

55
class SwiftObserverTests: XCTestCase
66
{
7+
func testStringProperty()
8+
{
9+
let text = Var("")
10+
11+
text.string += "append"
12+
13+
XCTAssertEqual("append", text.value)
14+
15+
}
16+
717
func testWeakMappingSource()
818
{
919
let toString = Weak(Var<Int?>()).new().unwrap(0).map { "\($0)" }

0 commit comments

Comments
 (0)