From e19af2f5d0212de78db35ffb5ea9b0cec6bdc010 Mon Sep 17 00:00:00 2001 From: Krunoslav Zaher Date: Sat, 25 Apr 2015 19:39:47 +0200 Subject: [PATCH] Adds Github view controller. --- RxExample/RxExample.xcodeproj/project.pbxproj | 4 ++ .../GitHubSignup/GitHubAPI/GitHubAPI.swift | 30 +++++++++ .../Views/GitHubSignupViewController.swift | 22 ++++++- .../Views/WikipediaSearchViewController.swift | 17 +---- RxExample/RxExample/ViewController.swift | 28 +++++++++ RxExample/RxExample/Views/Main.storyboard | 62 ++++++++++++++++++- 6 files changed, 146 insertions(+), 17 deletions(-) create mode 100644 RxExample/RxExample/ViewController.swift diff --git a/RxExample/RxExample.xcodeproj/project.pbxproj b/RxExample/RxExample.xcodeproj/project.pbxproj index 1c351f1e..221ca39b 100644 --- a/RxExample/RxExample.xcodeproj/project.pbxproj +++ b/RxExample/RxExample.xcodeproj/project.pbxproj @@ -29,6 +29,7 @@ C8813DAA1AD2EBF30072A050 /* RootViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8813DA91AD2EBF30072A050 /* RootViewController.swift */; }; C890A6581AEBD26B00AFF7E6 /* GitHubSignupViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C890A6571AEBD26B00AFF7E6 /* GitHubSignupViewController.swift */; }; C890A65A1AEBD28A00AFF7E6 /* GitHubAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = C890A6591AEBD28A00AFF7E6 /* GitHubAPI.swift */; }; + C890A65D1AEC084100AFF7E6 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C890A65C1AEC084100AFF7E6 /* ViewController.swift */; }; C8A56BCB1AD744E600B4673B /* RxSwift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C8A56BCA1AD744E600B4673B /* RxSwift.framework */; }; C8A56BCC1AD744E600B4673B /* RxSwift.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = C8A56BCA1AD744E600B4673B /* RxSwift.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; C8F57F441AD02DBE006B8702 /* RxCocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C8F57F431AD02DBE006B8702 /* RxCocoa.framework */; }; @@ -87,6 +88,7 @@ C8813DA91AD2EBF30072A050 /* RootViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RootViewController.swift; sourceTree = ""; }; C890A6571AEBD26B00AFF7E6 /* GitHubSignupViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GitHubSignupViewController.swift; sourceTree = ""; }; C890A6591AEBD28A00AFF7E6 /* GitHubAPI.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GitHubAPI.swift; sourceTree = ""; }; + C890A65C1AEC084100AFF7E6 /* ViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; C8A56BCA1AD744E600B4673B /* RxSwift.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = RxSwift.framework; sourceTree = BUILT_PRODUCTS_DIR; }; C8F57F431AD02DBE006B8702 /* RxCocoa.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = RxCocoa.framework; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ @@ -135,6 +137,7 @@ isa = PBXGroup; children = ( C86E2F2E1AE5A0CA00C31024 /* Examples */, + C890A65C1AEC084100AFF7E6 /* ViewController.swift */, C833670E1AD029AE00C668A7 /* AppDelegate.swift */, C833670F1AD029AE00C668A7 /* Example.swift */, C83367101AD029AE00C668A7 /* Services */, @@ -377,6 +380,7 @@ C86E2F421AE5A0CA00C31024 /* WikipediaSearchCell.swift in Sources */, C890A65A1AEBD28A00AFF7E6 /* GitHubAPI.swift in Sources */, C83367231AD029AE00C668A7 /* Example.swift in Sources */, + C890A65D1AEC084100AFF7E6 /* ViewController.swift in Sources */, C890A6581AEBD26B00AFF7E6 /* GitHubSignupViewController.swift in Sources */, C83367311AD029AE00C668A7 /* Wireframe.swift in Sources */, C8813DAA1AD2EBF30072A050 /* RootViewController.swift in Sources */, diff --git a/RxExample/RxExample/Examples/GitHubSignup/GitHubAPI/GitHubAPI.swift b/RxExample/RxExample/Examples/GitHubSignup/GitHubAPI/GitHubAPI.swift index d84b7bd1..df845e56 100644 --- a/RxExample/RxExample/Examples/GitHubSignup/GitHubAPI/GitHubAPI.swift +++ b/RxExample/RxExample/Examples/GitHubSignup/GitHubAPI/GitHubAPI.swift @@ -7,3 +7,33 @@ // import Foundation +import RxSwift + +class GitHubAPI { + let dataScheduler: ImmediateScheduler + let URLSession: NSURLSession + + init(dataScheduler: ImmediateScheduler, URLSession: NSURLSession) { + self.dataScheduler = dataScheduler + self.URLSession = URLSession + } + + func usernameAvailable(username: String) -> Observable { + // this is ofc just mock, but good enough + let URL = NSURL(string: "https://github.com/\(username)")! + let request = NSURLRequest(URL: URL) + return self.URLSession.rx_request(request) >- map { (maybeData, maybeResponse) in + if let response = maybeResponse as? NSHTTPURLResponse { + return response.statusCode == 404 + } + else { + return false + } + } + } + + func signup(username: String, password: String) -> Observable { + // this is also just a mock + return returnElement(()) >- throttle(0.700, MainScheduler.sharedInstance) + } +} \ No newline at end of file diff --git a/RxExample/RxExample/Examples/GitHubSignup/Views/GitHubSignupViewController.swift b/RxExample/RxExample/Examples/GitHubSignup/Views/GitHubSignupViewController.swift index a3fa9314..687f403d 100644 --- a/RxExample/RxExample/Examples/GitHubSignup/Views/GitHubSignupViewController.swift +++ b/RxExample/RxExample/Examples/GitHubSignup/Views/GitHubSignupViewController.swift @@ -8,7 +8,27 @@ import Foundation import UIKit +import RxSwift +import RxCocoa -class GitHubSignupViewController : UIViewController { +class GitHubSignupViewController : ViewController { + weak var username: UITextField! + weak var password: UITextField! + weak var repeatedPassword: UITextField! + weak var signup: UIButton! + var disposeBag = DisposeBag() + + var $ = ( + API: GitHubAPI( + dataScheduler: MainScheduler.sharedInstance, + URLSession: NSURLSession.sharedSession() + ) + ) + + override func viewDidLoad() { + super.viewDidLoad() + + + } } \ No newline at end of file diff --git a/RxExample/RxExample/Examples/WikipediaImageSearch/Views/WikipediaSearchViewController.swift b/RxExample/RxExample/Examples/WikipediaImageSearch/Views/WikipediaSearchViewController.swift index 6ba8fca8..1db3f014 100644 --- a/RxExample/RxExample/Examples/WikipediaImageSearch/Views/WikipediaSearchViewController.swift +++ b/RxExample/RxExample/Examples/WikipediaImageSearch/Views/WikipediaSearchViewController.swift @@ -10,25 +10,19 @@ import UIKit import RxSwift import RxCocoa -public class WikipediaSearchViewController: UIViewController { +class WikipediaSearchViewController: ViewController { private let disposeBag: DisposeBag = DisposeBag() private var viewModel: SearchViewModel? = nil - override public func awakeFromNib() { + override func awakeFromNib() { super.awakeFromNib() } // lifecycle - override public func viewDidLoad() { + override func viewDidLoad() { super.viewDidLoad() -#if DEBUG - if resourceCount != 1 { - println("Number of resources = \(resourceCount)") - assert(resourceCount == 1) - } -#endif let operationQueue = NSOperationQueue() operationQueue.maxConcurrentOperationCount = 2 operationQueue.qualityOfService = NSQualityOfService.UserInitiated @@ -92,9 +86,4 @@ public class WikipediaSearchViewController: UIViewController { // } } - deinit { -#if DEBUG - println("View controller disposed with \(resourceCount) resournces") -#endif - } } diff --git a/RxExample/RxExample/ViewController.swift b/RxExample/RxExample/ViewController.swift new file mode 100644 index 00000000..2e92ef27 --- /dev/null +++ b/RxExample/RxExample/ViewController.swift @@ -0,0 +1,28 @@ +// +// ViewController.swift +// RxExample +// +// Created by Krunoslav Zaher on 4/25/15. +// Copyright (c) 2015 Krunoslav Zaher. All rights reserved. +// + +import Foundation +import UIKit +import RxSwift + +class ViewController: UIViewController { + override func viewDidLoad() { +#if DEBUG + if resourceCount != 1 { + println("Number of resources = \(resourceCount)") + assert(resourceCount == 1) + } +#endif + } + + deinit { +#if DEBUG + println("View controller disposed with \(resourceCount) resournces") +#endif + } +} \ No newline at end of file diff --git a/RxExample/RxExample/Views/Main.storyboard b/RxExample/RxExample/Views/Main.storyboard index d3b45306..80dd27cd 100644 --- a/RxExample/RxExample/Views/Main.storyboard +++ b/RxExample/RxExample/Views/Main.storyboard @@ -33,6 +33,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + @@ -52,7 +98,7 @@ - + @@ -63,13 +109,19 @@ + - + @@ -80,6 +132,12 @@ +