8000 Added UIKit extensions by avalanched · Pull Request #54 · RACCommunity/Rex · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Added UIKit extensions #54

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

Merged
merged 5 commits into from
Oct 21, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Rex.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

/* Begin PBXBuildFile section */
4238D5961B4D5950008534C0 /* NSTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4238D5951B4D5950008534C0 /* NSTextField.swift */; };
8289A2E11BD7EF1F0097FB60 /* UIImageViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8289A2E01BD7EF1F0097FB60 /* UIImageViewTests.swift */; settings = {ASSET_TAGS = (); }; };
8289A2E31BD7EF740097FB60 /* UIImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8289A2E21BD7EF740097FB60 /* UIImageView.swift */; settings = {ASSET_TAGS = (); }; };
8289A2E51BD7F6DD0097FB60 /* UIView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8289A2E41BD7F6DD0097FB60 /* UIView.swift */; settings = {ASSET_TAGS = (); }; };
8289A2E81BD7F7900097FB60 /* UIViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8289A2E61BD7F7730097FB60 /* UIViewTests.swift */; settings = {ASSET_TAGS = (); }; };
8295FD871B87309F007C9000 /* UIControlTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8295FD851B873081007C9000 /* UIControlTests.swift */; };
8295FD8A1B87352D007C9000 /* UIButtonTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8295FD881B873490007C9000 /* UIButtonTests.swift */; };
8295FD8D1B87374A007C9000 /* UIBarButtonItemTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8295FD8B1B873748007C9000 /* UIBarButtonItemTests.swift */; };
Expand Down Expand Up @@ -98,6 +102,10 @@
4238D5951B4D5950008534C0 /* NSTextField.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = NSTextField.swift; path = AppKit/NSTextField.swift; sourceTree = "<group>"; };
5173EBC51B625A2600C9B48E /* UIBarItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIBarItem.swift; sourceTree = "<group>"; };
5173EBC71B625A6800C9B48E /* UIBarButtonItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIBarButtonItem.swift; sourceTree = "<group>"; };
8289A2E01BD7EF1F0097FB60 /* UIImageViewTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIImageViewTests.swift; sourceTree = "<group>"; };
8289A2E21BD7EF740097FB60 /* UIImageView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIImageView.swift; sourceTree = "<group>"; };
8289A2E41BD7F6DD0097FB60 /* UIView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIView.swift; sourceTree = "<group>"; };
8289A2E61BD7F7730097FB60 /* UIViewTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIViewTests.swift; sourceTree = "<group>"; };
8295FD851B873081007C9000 /* UIControlTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIControlTests.swift; sourceTree = "<group>"; };
8295FD881B873490007C9000 /* UIButtonTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIButtonTests.swift; sourceTree = "<group>"; };
8295FD8B1B873748007C9000 /* UIBarButtonItemTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIBarButtonItemTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -268,6 +276,8 @@
D86FFBDC1B34B691001A89B3 /* UIButton.swift */,
D86FFBD41B34B0FE001A89B3 /* UIControl.swift */,
D86FFBD71B34B242001A89B3 /* UILabel.swift */,
8289A2E21BD7EF740097FB60 /* UIImageView.swift */,
8289A2E41BD7F6DD0097FB60 /* UIView.swift */,
);
path = UIKit;
sourceTree = "<group>";
Expand All @@ -279,6 +289,8 @@
8295FD881B873490007C9000 /* UIButtonTests.swift */,
8295FD851B873081007C9000 /* UIControlTests.swift */,
D8F073141B861B3A0047D546 /* UILabelTests.swift */,
8289A2E01BD7EF1F0097FB60 /* UIImageViewTests.swift */,
8289A2E61BD7F7730097FB60 /* UIViewTests.swift */,
);
path = UIKit;
sourceTree = "<group>";
Expand Down Expand Up @@ -505,12 +517,14 @@
D86FFBD81B34B242001A89B3 /* UILabel.swift in Sources */,
D86FFBDB1B34B3F0001A89B3 /* Action.swift in Sources */,
D86FFBD21B34AD7A001A89B3 /* Association.swift in Sources */,
8289A2E31BD7EF740097FB60 /* UIImageView.swift in Sources */,
D8F0973E1B17F30D002E15BA /* NSUserDefaults.swift in Sources */,
D834572D1AFEE45B0070616A /* Signal.swift in Sources */,
D8E4A6211B7BBB2100EAD8A8 /* UIBarItem.swift in Sources */,
D8E4A6201B7BBB1600EAD8A8 /* UIBarButtonItem.swift in Sources */,
D8F097451B17F3C8002E15BA /* NSObject.swift in Sources */,
D834572E1AFEE45B0070616A /* SignalProducer.swift in Sources */,
8289A2E51BD7F6DD0097FB60 /* UIView.swift in Sources */,
D86FFBD61B34B116001A89B3 /* UIControl.swift in Sources */,
D8F0973F1B17F31E002E15BA /* NSData.swift in Sources */,
D86FFBDD1B34B691001A89B3 /* UIButton.swift in Sources */,
Expand All @@ -521,7 +535,9 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
8289A2E11BD7EF1F0097FB60 /* UIImageViewTests.swift in Sources */,
D8F0974B1B17F5E2002E15BA /* NSObjectTests.swift in Sources */,
8289A2E81BD7F7900097FB60 /* UIViewTests.swift in Sources */,
D8F073161B863CE70047D546 /* UILabelTests.swift in Sources */,
8295FD8A1B87352D007C9000 /* UIButtonTests.swift in Sources */,
D83457301AFEE45E0070616A /* SignalProducerTests.swift in Sources */,
Expand Down
12 changes: 12 additions & 0 deletions Source/UIKit/UIControl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ extension UIControl {
public var rex_enabled: MutableProperty<Bool> {
return rex_valueProperty(&enabled, { [weak self] in self?.enabled ?? true }, { [weak self] in self?.enabled = $0 })
}

/// Wraps a control's `selected` state in a bindable property.
public var rex_selected: MutableProperty<Bool> {
return rex_valueProperty(&selected, { [weak self] in self?.selected ?? false }, { [weak self] in self?.selected = $0 })
}

/// Wraps a control's `highlighted` state in a bindable property.
public var rex_highlighted: MutableProperty<Bool> {
return rex_valueProperty(&highlighted, { [weak self] in self?.highlighted ?? false }, { [weak self] in self?.highlighted = $0 })
}
}

private var enabled: UInt8 = 0
private var selected: UInt8 = 0
private var highlighted: UInt8 = 0
25 changes: 25 additions & 0 deletions Source/UIKit/UIImageView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// UIImageView.swift
// Rex
//
// Created by Andy Jacobs on 21/10/15.
// Copyright © 2015 Neil Pankey. All rights reserved.
//

import ReactiveCocoa
import UIKit

extension UIImageView {
/// Wraps a imageView's `image` value in a bindable property.
public var rex_image: MutableProperty<UIImage?> {
return rex_valueProperty(&image, { [weak self] in self?.image }, { [weak self] in self?.image = $0 })
}

/// Wraps a imageView's `highlightedImage` value in a bindable property.
public var rex_highlightedImage: MutableProperty<UIImage?> {
return rex_valueProperty(&highlightedImage, { [weak self] in self?.highlightedImage }, { [weak self] in self?.highlightedImage = $0 })
}
}

private var image: UInt8 = 0
private var highlightedImage: UInt8 = 0
25 changes: 25 additions & 0 deletions Source/UIKit/UIView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// UIView.swift
// Rex
//
// Created by Andy Jacobs on 21/10/15.
// Copyright © 2015 Neil Pankey. All rights reserved.
//

import ReactiveCocoa
import UIKit

extension UIView {
/// Wraps a view's `alpha` value in a bindable property.
public var rex_alpha: MutableProperty<CGFloat> {
return rex_valueProperty(&alpha, { [weak self] in self?.alpha ?? 1.0 }, { [weak self] in self?.alpha = $0 })
}

/// Wraps a view's `hidden` state in a bindable property.
public var rex_hidden: MutableProperty<Bool> {
return rex_valueProperty(&hidden, { [weak self] in self?.hidden ?? false }, { [weak self] in self?.hidden = $0 })
}
}

private var alpha: UInt8 = 0
private var hidden: UInt8 = 0 8000
16 changes: 16 additions & 0 deletions Tests/UIKit/UIControlTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,20 @@ class UIControlTests: XCTestCase {
control.rex_enabled <~ SignalProducer(value: false)
XCTAssert(_control?.enabled == false)
}

func testSelectedPropertyDoesntCreateRetainCycle() {
let control = UIControl(frame: CGRectZero)
_control = control

control.rex_selected <~ SignalProducer(value: true)
XCTAssert(_control?.selected == true)
}

func testHighlightedPropertyDoesntCreateRetainCycle() {
let control = UIControl(frame: CGRectZero)
_control = control

control.rex_highlighted <~ SignalProducer(value: true)
XCTAssert(_control?.highlighted == true)
}
}
41 changes: 41 additions & 0 deletions Tests/UIKit/UIImageViewTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// UIImageViewTests.swift
// Rex
//
// Created by Andy Jacobs on 21/10/15.
// Copyright © 2015 Neil Pankey. All rights reserved.
//

import ReactiveCocoa
import UIKit
import XCTest

class UIImageViewTests: XCTestCase {

weak var _imageView: UIImageView?

override func tearDown() {
XCTAssert(_imageView == nil, "Retain cycle detected in UIImageView properties")
super.tearDown()
}

func testImagePropertyDoesntCreateRetainCycle() {
let imageView = UIImageView(frame: CGRectZero)
_imageView = imageView

let image = UIImage()

imageView.rex_image <~ SignalProducer(value: image)
XCTAssert(_imageView?.image == image)
}

func testHighlightedImagePropertyDoesntCreateRetainCycle() {
let imageView = UIImageView(frame: CGRectZero)
_imageView = imageView

let image = UIImage()

imageView.rex_highlightedImage <~ SignalProducer(value: image)
XCTAssert(_imageView?.highlightedImage == image)
}
}
37 changes: 37 additions & 0 deletions Tests/UIKit/UIViewTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// UIViewTests.swift
// Rex
//
// Created by Andy Jacobs on 21/10/15.
// Copyright © 2015 Neil Pankey. All rights reserved.
//

import ReactiveCocoa
import UIKit
import XCTest

class UIViewTests: XCTestCase {

weak var _view: UIView?

override func tearDown() {
XCTAssert(_view == nil, "Retain cycle detected in UIView properties")
super.tearDown()
}

func testAlphaPropertyDoesntCreateRetainCycle() {
let view = UIView(frame: CGRectZero)
_view = view

view.rex_alpha <~ SignalProducer(value: 0.5)
XCTAssert(_view?.alpha == 0.5)
}

func testHiddenPropertyDoesntCreateRetainCycle() {
let view = UIView(frame: CGRectZero)
_view = view

view.rex_hidden <~ SignalProducer(value: true)
XCTAssert(_view?.hidden == true)
}
}
0