Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Observable-Swift/Protocols.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public protocol OwnableObservable: AnyObservable {

}

// observable <- value
// (observable <- value) or (observable.value <- observable.value)
infix operator <-

// value = observable^
Expand Down Expand Up @@ -117,6 +117,11 @@ public func += <T> (event: EventReference<ValueChange<T>>, handler: @escaping (T
return event.add({ handler($0.newValue) })
}

// for observable values on observable values
public func <- <T : WritableObservable & UnownableObservable> (x: inout T, y: T) {
x.value = y.value
}

// for observable values on variables
public func <- <T : WritableObservable & UnownableObservable> (x: inout T, y: T.ValueType) {
x.value = y
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ x.afterChange += { println("Changed x from \($0) to \($1)") }
// change the value, prints "Changed x from 0 to 42"
x <- 42
// alternativelyL x ^= 42, without operators: x.value = 42


var y = Observable(0)

// Copy the value from one observable to another one, prints "Changed x from 42 to 0"
x <- y
```

You can, of course, have observable properties in a `class` or a `struct`:
Expand Down