From 72122e3e435b35a1d72f256a5b6e3929cbd223f1 Mon Sep 17 00:00:00 2001 From: Krunoslav Zaher Date: Sun, 21 Aug 2016 18:40:08 +0200 Subject: [PATCH] Updates documentation for 3.0.0.alpha.1 --- Documentation/GettingStarted.md | 87 ++++++++++--------- README.md | 38 ++++---- .../Contents.swift | 4 +- .../Contents.swift | 2 +- RxCocoa/Common/DelegateProxy.swift | 2 +- RxSwift/Event.swift | 8 +- RxSwift/ObserverType.swift | 6 +- RxTests/XCTest+Rx.swift | 12 +-- Tests/PerformanceTests/main.swift | 2 +- 9 files changed, 80 insertions(+), 81 deletions(-) diff --git a/Documentation/GettingStarted.md b/Documentation/GettingStarted.md index 3f3630de..8caeeb34 100644 --- a/Documentation/GettingStarted.md +++ b/Documentation/GettingStarted.md @@ -67,32 +67,32 @@ These are called marble diagrams. There are more marble diagrams at [rxmarbles.c If we were to specify sequence grammar as a regular expression it would look like: -**Next* (Error | Completed)?** +**next* (error | completed)?** This describes the following: * **Sequences can have 0 or more elements.** -* **Once an `Error` or `Completed` event is received, the sequence cannot produce any other element.** +* **Once an `error` or `completed` event is received, the sequence cannot produce any other element.** Sequences in Rx are described by a push interface (aka callback). ```swift enum Event { - case Next(Element) // next element of a sequence - case Error(Swift.Error) // sequence failed with error - case Completed // sequence terminated successfully + case next(Element) // next element of a sequence + case error(Swift.Error) // sequence failed with error + case completed // sequence terminated successfully } class Observable { - func subscribe(observer: Observer) -> Disposable + func subscribe(_ observer: Observer) -> Disposable } protocol ObserverType { - func on(event: Event) + func on(_ event: Event) } ``` -**When a sequence sends the `Completed` or `Error` event all internal resources that compute sequence elements will be freed.** +**When a sequence sends the `completed` or `error` event all internal resources that compute sequence elements will be freed.** **To cancel production of sequence elements and free resources immediately, call `dispose` on the returned subscription.** @@ -116,7 +116,7 @@ let subscription = Observable.interval(0.3, scheduler: scheduler) print(event) } -NSThread.sleepForTimeInterval(2) +NSThread.sleep(forTimeInterval: 2.0) subscription.dispose() @@ -218,9 +218,9 @@ sequence There is also a couple of additional guarantees that all sequence producers (`Observable`s) must honor. -It doesn't matter on which thread they produce elements, but if they generate one element and send it to the observer `observer.on(.Next(nextElement))`, they can't send next element until `observer.on` method has finished execution. +It doesn't matter on which thread they produce elements, but if they generate one element and send it to the observer `observer.on(.next(nextElement))`, they can't send next element until `observer.on` method has finished execution. -Producers also cannot send terminating `.Completed` or `.Error` in case `.Next` event hasn't finished. +Producers also cannot send terminating `.completed` or `.error` in case `.next` event hasn't finished. In short, consider this example: @@ -291,8 +291,8 @@ Let's create a function which creates a sequence that returns one element upon s ```swift func myJust(element: E) -> Observable { return Observable.create { observer in - observer.on(.Next(element)) - observer.on(.Completed) + observer.on(.next(element)) + observer.on(.completed) return Disposables.create() } } @@ -325,10 +325,10 @@ Lets now create an observable that returns elements from an array. func myFrom(sequence: [E]) -> Observable { return Observable.create { observer in for element in sequence { - observer.on(.Next(element)) + observer.on(.next(element)) } - observer.on(.Completed) + observer.on(.completed) return Disposables.create() } } @@ -390,7 +390,7 @@ func myInterval(interval: NSTimeInterval) -> Observable { if cancel.isDisposed { return } - observer.on(.Next(next)) + observer.on(.next(next)) next += 1 }) dispatch_resume(timer) @@ -410,7 +410,8 @@ let subscription = counter print(n) }) -NSThread.sleepForTimeInterval(0.5) + +NSThread.sleep(forTimeInterval: 0.5) subscription.dispose() @@ -446,11 +447,11 @@ let subscription2 = counter print("Second \(n)") }) -NSThread.sleepForTimeInterval(0.5) +NSThread.sleep(forTimeInterval: 0.5) subscription1.dispose() -NSThread.sleepForTimeInterval(0.5) +NSThread.sleep(forTimeInterval: 0.5) subscription2.dispose() @@ -559,17 +560,17 @@ extension Reactive where Base: NSURLSession { return Observable.create { observer in let task = self.dataTaskWithRequest(request) { (data, response, error) in guard let response = response, data = data else { - observer.on(.Error(error ?? RxCocoaURLError.Unknown)) + observer.on(.error(error ?? RxCocoaURLError.Unknown)) return } guard let httpResponse = response as? NSHTTPURLResponse else { - observer.on(.Error(RxCocoaURLError.NonHTTPResponse(response: response))) + observer.on(.error(RxCocoaURLError.nonHTTPResponse(response: response))) return } - observer.on(.Next(data, httpResponse)) - observer.on(.Completed) + observer.on(.next(data, httpResponse)) + observer.on(.completed) } task.resume() @@ -614,13 +615,13 @@ extension ObservableType { return Observable.create { observer in let subscription = self.subscribe { e in switch e { - case .Next(let value): + case .next(let value): let result = transform(value) - observer.on(.Next(result)) - case .Error(let error): - observer.on(.Error(error)) - case .Completed: - observer.on(.Completed) + observer.on(.next(result)) + case .error(let error): + observer.on(.error(error)) + case .completed: + observer.on(.completed) } } @@ -680,7 +681,7 @@ This isn't something that should be practiced often, and is a bad code smell, bu being, UIApplication.delegate.dataSomething.attendees ) - kittens.on(.Next(kitten)) // send result back to rx + kittens.on(.next(kitten)) // send result back to rx // // Another mess // @@ -797,15 +798,15 @@ will print ``` [my probe] subscribed Subscribed -[my probe] -> Event Next(Box(0)) +[my probe] -> Event next(Box(0)) This is simply 0 -[my probe] -> Event Next(Box(1)) +[my probe] -> Event next(Box(1)) This is simply 1 -[my probe] -> Event Next(Box(2)) +[my probe] -> Event next(Box(2)) This is simply 2 -[my probe] -> Event Next(Box(3)) +[my probe] -> Event next(Box(3)) This is simply 3 -[my probe] -> Event Next(Box(4)) +[my probe] -> Event next(Box(4)) This is simply 4 [my probe] dispose Disposed @@ -821,14 +822,14 @@ extension ObservableType { let subscription = self.subscribe { e in print("event \(identifier) \(e)") switch e { - case .Next(let value): - observer.on(.Next(value)) + case .next(let value): + observer.on(.next(value)) - case .Error(let error): - observer.on(.Error(error)) + case .error(let error): + observer.on(.error(error)) - case .Completed: - observer.on(.Completed) + case .completed: + observer.on(.completed) } } return Disposables.create { @@ -1081,7 +1082,7 @@ let cancelRequest = responseJSON print(json) }) -NSThread.sleepForTimeInterval(3) +NSThread.sleep(forTimeInterval: 3.0) // if you want to cancel request after 3 seconds have passed just call cancelRequest.dispose() @@ -1093,7 +1094,7 @@ cancelRequest.dispose() In case you want a more low level access to response, you can use: ```swift -NSURLSession.sharedSession().rx.response(myNSURLRequest) +NSURLSession.shared.rx.response(myNSURLRequest) .debug("my request") // this will print out information to console .flatMap { (data: NSData!, response: NSURLResponse!) -> Observable in if let response = response as? NSHTTPURLResponse { diff --git a/README.md b/README.md index 989d15cf..1e5cf621 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,9 @@ [![Travis CI](https://travis-ci.org/ReactiveX/RxSwift.svg?branch=master)](https://travis-ci.org/ReactiveX/RxSwift) ![platforms](https://img.shields.io/badge/platforms-iOS%20%7C%20OSX%20%7C%20tvOS%20%7C%20watchOS%20%7C%20Linux%28experimental%29-333333.svg) ![pod](https://img.shields.io/cocoapods/v/RxSwift.svg) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) -Xcode 7.3 Swift 2.2 required +**Xcode 8.0 beta 6 (8S201h) required** + +**Swift 3.0** ## About Rx @@ -96,7 +98,7 @@ let searchResults = searchBar.rx.text
 searchResults
-    .bindTo(tableView.rx.itemsWithCellIdentifier("Cell")) {
+    .bindTo(tableView.rx.items(cellIdentifier: "Cell")) {
         (index, repository: Repository, cell) in
         cell.textLabel?.text = repository.name
         cell.detailTextLabel?.text = repository.url
@@ -118,38 +120,36 @@ Open Rx.xcworkspace, choose `RxExample` and hit run. This method will build ever
 
 ### [CocoaPods](https://guides.cocoapods.org/using/using-cocoapods.html)
 
-**:warning: IMPORTANT! For tvOS support, CocoaPods `0.39` is required. :warning:**
-
 ```
 # Podfile
 use_frameworks!
 
 target 'YOUR_TARGET_NAME' do
-    pod 'RxSwift',    '~> 2.0'
-    pod 'RxCocoa',    '~> 2.0'
+    pod 'RxSwift',    '~> 3.0.0.alpha.1'
+    pod 'RxCocoa',    '~> 3.0.0.alpha.1'
 end
 
 # RxTests and RxBlocking make the most sense in the context of unit/integration tests
 target 'YOUR_TESTING_TARGET' do
-    pod 'RxBlocking', '~> 2.0'
-    pod 'RxTests',    '~> 2.0'
+    pod 'RxBlocking', '~> 3.0.0.alpha.1'
+    pod 'RxTests',    '~> 3.0.0.alpha.1'
 end
 ```
 
 Replace `YOUR_TARGET_NAME` and then, in the `Podfile` directory, type:
 
-**:warning: If you want to use CocoaPods with Xcode 8.0 beta and Swift 2.3, you might need to add the following
+**:warning: If you want to use CocoaPods with Xcode 8.0 beta and Swift 3.0, you might need to add the following
 lines to your podfile: :warning:**
 
 ```
-  post_install do |installer|
-	  installer.pods_project.targets.each do |target|
-	    target.build_configurations.each do |config|
-	      config.build_settings['SWIFT_VERSION'] = '2.3'
-	      config.build_settings['MACOSX_DEPLOYMENT_TARGET'] = '10.10'
-	    end
-	  end
-	end
+post_install do |installer|
+  installer.pods_project.targets.each do |target|
+    target.build_configurations.each do |config|
+      config.build_settings['SWIFT_VERSION'] = '3.0'
+      config.build_settings['MACOSX_DEPLOYMENT_TARGET'] = '10.10'
+    end
+  end
+end
 ```
 
 ```
@@ -158,12 +158,10 @@ $ pod install
 
 ### [Carthage](https://github.com/Carthage/Carthage)
 
-**Xcode 7.1 required**
-
 Add this to `Cartfile`
 
 ```
-github "ReactiveX/RxSwift" ~> 2.0
+github "ReactiveX/RxSwift" ~> 3.0.0.alpha.1
 ```
 
 ```
diff --git a/Rx.playground/Pages/Introduction.xcplaygroundpage/Contents.swift b/Rx.playground/Pages/Introduction.xcplaygroundpage/Contents.swift
index 80f529e7..cfb84480 100644
--- a/Rx.playground/Pages/Introduction.xcplaygroundpage/Contents.swift
+++ b/Rx.playground/Pages/Introduction.xcplaygroundpage/Contents.swift
@@ -32,11 +32,11 @@ All of these various systems makes our code needlessly complex. Wouldn't it be b
  * `ObservableType.subscribe(_:)` takes an observer (`ObserverType`) parameter, which will be subscribed to automatically receive sequence events and elements emitted by the `Observable`, instead of manually calling `next()` on the returned generator.
  */
 /*:
- If an `Observable` emits a Next event (`Event.Next(Element)`), it can continue to emit more events. However, if the `Observable` emits either an Error event (`Event.Error(ErrorType)`) or a Completed event (`Event.Completed`), the `Observable` sequence cannot emit additional events to the subscriber.
+ If an `Observable` emits a next event (`Event.next(Element)`), it can continue to emit more events. However, if the `Observable` emits either an error event (`Event.error(ErrorType)`) or a completed event (`Event.completed`), the `Observable` sequence cannot emit additional events to the subscriber.
 
  Sequence grammar explains this more concisely:
 
- `Next* (Error | Completed)?`
+ `next* (error | completed)?`
 
  And this can also be explained more visually using diagrams:
 
diff --git a/Rx.playground/Pages/Working_with_Subjects.xcplaygroundpage/Contents.swift b/Rx.playground/Pages/Working_with_Subjects.xcplaygroundpage/Contents.swift
index b61ffd75..6ed869c6 100644
--- a/Rx.playground/Pages/Working_with_Subjects.xcplaygroundpage/Contents.swift
+++ b/Rx.playground/Pages/Working_with_Subjects.xcplaygroundpage/Contents.swift
@@ -47,7 +47,7 @@ example("PublishSubject") {
     subject.onNext("🅱️")
 }
 /*:
- > This example also introduces using the `onNext(_:)` convenience method, equivalent to `on(.Next(_:)`, which causes a new Next event to be emitted to subscribers with the provided `element`. There are also `onError(_:)` and `onCompleted()` convenience methods, equivalent to `on(.Error(_:))` and `on(.Completed)`, respectively.
+ > This example also introduces using the `onNext(_:)` convenience method, equivalent to `on(.next(_:)`, which causes a new Next event to be emitted to subscribers with the provided `element`. There are also `onError(_:)` and `onCompleted()` convenience methods, equivalent to `on(.error(_:))` and `on(.completed)`, respectively.
  ----
  ## ReplaySubject
  Broadcasts new events to all subscribers, and the specified `bufferSize` number of previous events to new subscribers.
diff --git a/RxCocoa/Common/DelegateProxy.swift b/RxCocoa/Common/DelegateProxy.swift
index 9e311c08..dc888bbd 100644
--- a/RxCocoa/Common/DelegateProxy.swift
+++ b/RxCocoa/Common/DelegateProxy.swift
@@ -66,7 +66,7 @@ open class DelegateProxy : _RXDelegateProxy {
          let internalSubject = PublishSubject
      
          public func requiredDelegateMethod(scrollView: UIScrollView, arg1: CGPoint) -> Bool {
-             internalSubject.on(.Next(arg1))
+             internalSubject.on(.next(arg1))
              return self._forwardToDelegate?.requiredDelegateMethod?(scrollView, arg1: arg1) ?? defaultReturnValue
          }
      
diff --git a/RxSwift/Event.swift b/RxSwift/Event.swift
index 1852a091..5fcf8f29 100644
--- a/RxSwift/Event.swift
+++ b/RxSwift/Event.swift
@@ -12,7 +12,7 @@ import Foundation
 Represents a sequence event.
 
 Sequence grammar:
-Next\* (Error | Completed)
+next\* (error | completed)
 */
 public enum Event {
     /// Next element is produced.
@@ -30,11 +30,11 @@ extension Event : CustomDebugStringConvertible {
     public var debugDescription: String {
         switch self {
         case .next(let value):
-            return "Next(\(value))"
+            return "next(\(value))"
         case .error(let error):
-            return "Error(\(error))"
+            return "error(\(error))"
         case .completed:
-            return "Completed"
+            return "completed"
         }
     }
 }
diff --git a/RxSwift/ObserverType.swift b/RxSwift/ObserverType.swift
index 45a8a3ee..b604e636 100644
--- a/RxSwift/ObserverType.swift
+++ b/RxSwift/ObserverType.swift
@@ -31,7 +31,7 @@ Convenience API extensions to provide alternate next, error, completed events
 public extension ObserverType {
     
     /**
-    Convenience method equivalent to `on(.Next(element: E))`
+    Convenience method equivalent to `on(.next(element: E))`
     
     - parameter element: Next element to send to observer(s)
     */
@@ -40,14 +40,14 @@ public extension ObserverType {
     }
     
     /**
-    Convenience method equivalent to `on(.Completed)`
+    Convenience method equivalent to `on(.completed)`
     */
     final func onCompleted() {
         on(.completed)
     }
     
     /**
-    Convenience method equivalent to `on(.Error(error: Swift.Error))`
+    Convenience method equivalent to `on(.error(Swift.Error))`
     - parameter error: Swift.Error to send to observer(s)
     */
     final func onError(_ error: Swift.Error) {
diff --git a/RxTests/XCTest+Rx.swift b/RxTests/XCTest+Rx.swift
index 7f4ba48c..24599a7a 100644
--- a/RxTests/XCTest+Rx.swift
+++ b/RxTests/XCTest+Rx.swift
@@ -15,9 +15,9 @@ require specifying `self.*`, they are made global.
 */
 //extension XCTestCase {
     /**
-    Factory method for an `.Next` event recorded at a given time with a given value.
+    Factory method for an `.next` event recorded at a given time with a given value.
 
-     - parameter time: Recorded virtual time the `.Next` event occurs.
+     - parameter time: Recorded virtual time the `.next` event occurs.
      - parameter element: Next sequence element.
      - returns: Recorded event in time.
     */
@@ -26,9 +26,9 @@ require specifying `self.*`, they are made global.
     }
 
     /**
-    Factory method for an `.Completed` event recorded at a given time.
+    Factory method for an `.completed` event recorded at a given time.
 
-     - parameter time: Recorded virtual time the `.Completed` event occurs.
+     - parameter time: Recorded virtual time the `.completed` event occurs.
      - parameter type: Sequence elements type.
      - returns: Recorded event in time.
     */
@@ -37,9 +37,9 @@ require specifying `self.*`, they are made global.
     }
 
     /**
-    Factory method for an `.Error` event recorded at a given time with a given error.
+    Factory method for an `.error` event recorded at a given time with a given error.
 
-     - parameter time: Recorded virtual time the `.Completed` event occurs.
+     - parameter time: Recorded virtual time the `.completed` event occurs.
     */
     public func error(_ time: TestTime, _ error: Swift.Error, _ type: T.Type = T.self) -> Recorded> {
         return Recorded(time: time, event: .error(error))
diff --git a/Tests/PerformanceTests/main.swift b/Tests/PerformanceTests/main.swift
index dee24852..9cd09b13 100644
--- a/Tests/PerformanceTests/main.swift
+++ b/Tests/PerformanceTests/main.swift
@@ -28,7 +28,7 @@ compareTwoImplementations(benchmarkTime: true, benchmarkMemory: false, first: {
         _ = publishSubject //.asDriver(onErrorJustReturn: -1)
     /*create { (o: AnyObserver) in
             for i in 0..<100 {
-                o.on(.Next(i))
+                o.on(.next(i))
             }
             return Disposables.create()
         }*/