-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
VC's did/will (dis)appear #100
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// | ||
// UIViewController.swift | ||
// Rex | ||
// | ||
// Created by Rui Peres on 14/04/2016. | ||
// Copyright © 2016 Neil Pankey. All rights reserved. | ||
// | ||
|
||
import Result | ||
import ReactiveCocoa | ||
import UIKit | ||
|
||
extension UIViewController { | ||
/// Returns a `Signal`, that will be triggered | ||
/// when `self`'s `viewDidDisappear` is called | ||
public var rex_viewDidDisappearSignal: Signal<(), NoError> { | ||
return triggerForSelector(#selector(UIViewController.viewDidDisappear(_:))) | ||
} | ||
|
||
/// Returns a `Signal`, that will be triggered | ||
/// when `self`'s `viewWillDisappear` is called | ||
public var rex_viewWillDisappearSignal: Signal<(), NoError> { | ||
return triggerForSelector(#selector(UIViewController.viewWillDisappear(_:))) | ||
} | ||
|
||
/// Returns a `Signal`, that will be triggered | ||
/// when `self`'s `viewDidAppear` is called | ||
public var rex_viewDidAppearSignal: Signal<(), NoError> { | ||
return triggerForSelector(#selector(UIViewController.viewDidAppear(_:))) | ||
} | ||
|
||
/// Returns a `Signal`, that will be triggered | ||
/// when `self`'s `viewWillAppear` is called | ||
public var rex_viewWillAppearSignal: Signal<(), NoError> { | ||
return triggerForSelector(#selector(UIViewController.viewWillAppear(_:))) | ||
} | ||
|
||
private func triggerForSelector(selector: Selector) -> Signal<(), NoError> { | ||
return self | ||
.rac_signalForSelector(selector) | ||
.rex_toTriggerSignal() | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// | ||
// UIViewControllerTests.swift | ||
// Rex | ||
// | ||
// Created by Rui Peres on 16/04/2016. | ||
// Copyright © 2016 Neil Pankey. All rights reserved. | ||
// | ||
|
||
import ReactiveCocoa | ||
import UIKit | ||
import XCTest | ||
import enum Result.NoError | ||
|
||
class UIViewControllerTests: XCTestCase { | ||
|
||
weak var _viewController: UIViewController? | ||
|
||
override func tearDown() { | ||
XCTAssert(_viewController == nil, "Retain cycle detected in UIViewController properties") | ||
super.tearDown() | ||
} | ||
|
||
func testViewDidDisappear() { | ||
|
||
let expectation = self.expectationWithDescription("Expected rex_viewDidDisappearSignal to be triggered") | ||
defer { self.waitForExpectationsWithTimeout(2, handler: nil) } | ||
|
||
let viewController = UIViewController() | ||
_viewController = viewController | ||
|
||
viewController.rex_viewDidDisappearSignal.observeNext { | ||
expectation.fulfill() | ||
} | ||
|
||
viewController.viewDidDisappear(true) | ||
} | ||
|
||
func testViewWillDisappear() { | ||
|
||
let expectation = self.expectationWithDescription("Expected rex_viewWillDisappearSignal to be triggered") | ||
defer { self.waitForExpectationsWithTimeout(2, handler: nil) } | ||
|
||
let viewController = UIViewController() | ||
_viewController = viewController | ||
|
||
viewController.rex_viewWillDisappearSignal.observeNext { | ||
expectation.fulfill() | ||
} | ||
|
||
viewController.viewWillDisappear(true) | ||
} | ||
|
||
func testViewDidAppear() { | ||
|
||
let expectation = self.expectationWithDescription("Expected rex_viewDidAppearSignal to be triggered") | ||
defer { self.waitForExpectationsWithTimeout(2, handler: nil) } | ||
|
||
let viewController = UIViewController() | ||
_viewController = viewController | ||
|
||
viewController.rex_viewDidAppearSignal.observeNext { | ||
expectation.fulfill() | ||
} | ||
|
||
viewController.viewDidAppear(true) | ||
} | ||
|
||
func testViewWillAppear() { | ||
|
||
let expectation = self.expectationWithDescription("Expected rex_viewWillAppearSignal to be triggered") | ||
defer { self.waitForExpectationsWithTimeout(2, handler: nil) } | ||
|
||
let viewController = UIViewController() | ||
_viewController = viewController | ||
|
||
viewController.rex_viewWillAppearSignal.observeNext { | ||
expectation.fulfill() | ||
} | ||
|
||
viewController.viewWillAppear(true) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should
triggerForSelector
be inside extension ofNSObject
(orUIResponder
) ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@335g Looking at
UIResponder
documentation, I don't think so. I might be missing something.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now, It might be good in this 👍