Latest 0.1
Homepage https://github.com/RedHandTech/SwiftObserve
License MIT
Platforms ios 10.2, osx 10.12, watchos 3.1, tvos 10.1
Authors

Observation framework for properties in Swift

Welcome to SwiftObserve!

SwiftObserve provides property observation in Swift. It is ispired by Reactive X.

Installation

Installation is available via Cocoapods, Carthage or the Swift Package Manager

Cocoapods

  • Add the following to your Podfile:
    pod install 'SwiftObserve', '~> 0.1'

Carthage

  • Add the following to your Cartfile:
    github "RedHandTech/SwiftObserve"

Swift Package Manager

  • Add the url to your Package.swift file e.g.:
    
    import PackageDescription

let package = Package(
name: "MyProject",
targets: [],
dependencies: [
.Package(url: "https://github.com/RedHandTech/SwiftObserve.git", majorVersion: 0, minorVersion: 1),
]
)


### Liscence
* MIT ([see here...](LISCENCE.txt))

### Usage

#### Values

* The `Value` class wraps values and provides the starting place for observation. You can observe a value like so:

```swift
let aValue: Value<Int> = Value(value: 10)
aValue.observe {
    print("Changed value to: ($0)")
}
aValue.value = 2

Output is: Changed value to 2

Filtering

  • You can filter a value based on some arbitrary conditions like so:
let aValue: Value<Int> = Value(value: 10)
aValue.onWhere { $0 != 3 }.observe {
    print("Called: ($0)")
}
aValue.value = 3
aValue.value = 2

Output is: Changed value to 2

Mapping

  • You can map a value like so:
let aValue: Value<Int> = Value(value: 10)
aValue.map { "Hello, World! ($0)" }.observe {
    print($0)
}
aValue.value = 2

Output is: Hello, World! 2

Chaining

  • You can chain events together like so:
let aValue: Value<Int> = Value(value: 10)
aValue.onWhere { $0 != 2 }.map { String($0) }.onWhere { $0 != "3" }.observe {
    print($0)
}
aValue.value = 2
aValue.value = 3
aValue.value = 4

Output is: 4

Latest podspec

{
    "name": "SwiftObserve",
    "version": "0.1",
    "summary": "A value observation framework for Swift.",
    "description": "SwiftObserve provides property observation for Swift.nIt allows you to wrap values and observe changes to the values over time.nIt also provides a poweful and easy to use filtering and mapping system.",
    "homepage": "https://github.com/RedHandTech/SwiftObserve",
    "license": {
        "type": "MIT",
        "file": "LISCENCE.txt"
    },
    "authors": {
        "Rob Sanders": "[email protected]"
    },
    "platforms": {
        "ios": "10.2",
        "osx": "10.12",
        "watchos": "3.1",
        "tvos": "10.1"
    },
    "source": {
        "git": "https://github.com/RedHandTech/SwiftObserve.git",
        "tag": "0.1"
    },
    "source_files": "Sources/*.swift",
    "pushed_with_swift_version": "3.0.2"
}

Pin It on Pinterest

Share This