final class ViewModel {
enum Error {
case usernameNonAlphanumeric
case usernameMismatch
}
// Normal validation
let username = ValidatingProperty<String, Error>("") { input, error in
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
import XCTest | |
import ReactiveSwift | |
import Result | |
class PerformanceTests: XCTestCase { | |
let iterations = 50_000 | |
func testStackBlowing() { | |
func nest(_ signal: Signal<(), NoError>) -> Signal<(), NoError> { | |
let (never, o) = type(of: signal).pipe() |
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
import XCTest | |
import ReactiveSwift | |
import Result | |
class Test: XCTestCase { | |
func testPerformanceExample() { | |
let (signal, observer) = Signal<Int, NoError>.pipe() | |
let transformed = signal |
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
@testable import ReactiveSwift | |
import XCTest | |
class AtomicTests: XCTestCase { | |
let iterations = 10000000 | |
func test() { | |
var info = mach_timebase_info() | |
mach_timebase_info(&info) |
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
let info = mach_timebase_info_t.allocate(capacity: 1) | |
mach_timebase_info(info) | |
var avg: Double = 0 | |
let lock: UnsafeMutableRawPointer! | |
if #available(macOS 10.12, iOS 10.0, *), true { | |
let lock1 = os_unfair_lock_t.allocate(capacity: 1) | |
lock1.initialize(to: os_unfair_lock()) | |
lock = UnsafeMutableRawPointer(lock1) |
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
// Assuming we have this state: | |
courseId | |
// Assuming we have these view related stuff: | |
refreshButton | |
courseCodeLabel | |
courseTitleLabel | |
sectionsAdapter // ArrayAdapter | |
sectionSpinner |
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
let username = MutableProperty("") | |
let mutableView = username | |
.validate { $0.characters.count >= 3 ? .success() : .failure(FormError("At least three characters.")) } | |
.validate { !$0.characters.contains("@") ? .success() : .failure(FormError("Contains invalid characters.")) } | |
.map(forward: { $0.isEmpty ? "" : "\($0)@reactiveswift" }, | |
attemptBackward: { Result($0.stripSuffix("@reactiveswift"), failWith: FormError("Missing `@reactiveswift` suffix.")) }) | |
mutableView.validations.observeValues { print("error: \($0.error?.reason ?? "NoError")") } |
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
/*: | |
> # IMPORTANT: To use `ReactiveSwift.playground`, please: | |
1. Retrieve the project dependencies using one of the following terminal commands from the ReactiveSwift project root directory: | |
- `git submodule update --init` | |
**OR**, if you have [Carthage](https://github.com/Carthage/Carthage) installed | |
- `carthage checkout --no-use-binaries` | |
1. Open `ReactiveSwift.xcworkspace` | |
1. Build `Result-Mac` scheme | |
1. Build `ReactiveSwift-macOS` scheme |
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
/*: | |
> # IMPORTANT: To use `ReactiveSwift.playground`, please: | |
1. Retrieve the project dependencies using one of the following terminal commands from the ReactiveSwift project root directory: | |
- `git submodule update --init` | |
**OR**, if you have [Carthage](https://github.com/Carthage/Carthage) installed | |
- `carthage checkout --no-use-binaries` | |
1. Open `ReactiveSwift.xcworkspace` | |
1. Build `Result-Mac` scheme | |
1. Build `ReactiveSwift-macOS` scheme |
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
infix operator <~ | |
//func <~<T: Target, S: Source>(left: T, right: S) { | |
// print("Free Function") | |
//} | |
//func <~<S: Source>(left: BindingTarget, right: S) { | |
// print("Free Function 2") | |
//} |