-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #121 from eofs/feature/uikit-uiprogressview
Added rex_progress to UIProgressView
- Loading branch information
Showing
3 changed files
with
78 additions
and
2 deletions.
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,19 @@ | ||
// | ||
// UIProgressView.swift | ||
// Rex | ||
// | ||
// Created by Tomi Pajunen on 04/05/16. | ||
// Copyright © 2016 Neil Pankey. All rights reserved. | ||
// | ||
|
||
import ReactiveCocoa | ||
import UIKit | ||
|
||
extension UIProgressView { | ||
/// Wraps a progressView's `progress` value in a bindable property. | ||
public var rex_progress: MutableProperty<Float> { | ||
return associatedProperty(self, key: &progressKey, initial: { $0.progress }, setter: { $0.progress = $1 }) | ||
} | ||
} | ||
|
||
private var progressKey: UInt8 = 0 |
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,45 @@ | ||
// | ||
// UIProgressViewTests.swift | ||
// Rex | ||
// | ||
// Created by Tomi Pajunen on 04/05/16. | ||
// Copyright © 2016 Neil Pankey. All rights reserved. | ||
// | ||
|
||
import ReactiveCocoa | ||
import UIKit | ||
import XCTest | ||
import enum Result.NoError | ||
|
||
class UIProgressViewTests: XCTestCase { | ||
weak var _progressView: UIProgressView? | ||
|
||
override func tearDown() { | ||
XCTAssert(_progressView == nil, "Retain cycle detected in UIProgressView properties") | ||
super.tearDown() | ||
} | ||
|
||
func testProgressPropertyDoesntCreateRetainCycle() { | ||
let progressView = UIProgressView(frame: CGRectZero) | ||
_progressView = progressView | ||
|
||
progressView.rex_progress <~ SignalProducer(value: 0.5) | ||
XCTAssert(_progressView?.progress == 0.5) | ||
} | ||
|
||
func testProgressProperty() { | ||
let firstChange: Float = 0.5 | ||
let secondChange: Float = 0.0 | ||
|
||
let progressView = UIProgressView(frame: CGRectZero) | ||
progressView.progress = 1.0 | ||
|
||
let (pipeSignal, observer) = Signal<Float, NoError>.pipe() | ||
progressView.rex_progress <~ SignalProducer(signal: pipeSignal) | ||
|
||
observer.sendNext(firstChange) | ||
XCTAssertEqual(progressView.progress, firstChange) | ||
observer.sendNext(secondChange) | ||
XCTAssertEqual(progressView.progress, secondChange) | ||
} | ||
} |