-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Zachary Smith
committed
Apr 23, 2015
1 parent
a8e8f9b
commit 6a513d9
Showing
28 changed files
with
425 additions
and
196 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Xcode | ||
# | ||
build/ | ||
*.pbxuser | ||
!default.pbxuser | ||
*.mode1v3 | ||
!default.mode1v3 | ||
*.mode2v3 | ||
!default.mode2v3 | ||
*.perspectivev3 | ||
!default.perspectivev3 | ||
xcuserdata | ||
*.xccheckout | ||
*.moved-aside | ||
DerivedData | ||
*.hmap | ||
*.ipa | ||
*.xcuserstate | ||
.DS_Store | ||
|
||
*.xcworkspace | ||
Podfile.lock | ||
|
||
|
||
# CocoaPods | ||
# | ||
# We recommend against adding the Pods directory to your .gitignore. However | ||
# you should judge for yourself, the pros and cons are mentioned at: | ||
# http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control | ||
# | ||
Pods/ |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1 +1 @@ | ||
github "zacharyclaysmith/AwfulBinding" | ||
github "zacharyclaysmith/SwiftBinding" |
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,3 @@ | ||
source 'https://github.com/CocoaPods/Specs.git' | ||
use_frameworks! | ||
pod 'SwiftBinding' |
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 |
---|---|---|
@@ -1,121 +1,164 @@ | ||
# AwfulBindingUI | ||
A library of simple UI components built around the AwfulBinding library. | ||
# SwiftBindingUI | ||
A library of simple UI components built around the SwiftBinding library. | ||
|
||
## Installation | ||
|
||
1. Carthage | ||
* Add `github "zacharyclaysmith/AwfulBindingUI"` to your Cartfile | ||
* Run `carthage update` | ||
* Add `github "zacharyclaysmith/SwiftBindingUI"` to your Cartfile | ||
* Run `carthage update` | ||
2. CocoaPods | ||
*Not yet supported* | ||
* pod 'SwiftBindingUI' | ||
3. Manual Installation | ||
Just pull down the repo and build it, then include the framework in your project. | ||
* Just pull down the repo and build it, then include the framework in your project. | ||
|
||
## Goals/Philosophy | ||
Generally, as a long-time MVC (aka MVVM, MV*, etc.) advocate, Apple's delegate pattern hurts my heart (and my sanity). Here's a brief summary on why I started this framework and goals I try to work towards when modifying it: | ||
|
||
1. Reactive UI beats Imperative UI | ||
* I want my elements to decide what to do based on their data...manually grabbing UI elements and modifying them is effective but not at all sustainable. | ||
2. Ease the inconsistencies between base UIKit elements. | ||
* Apple's built in UI elements are ridiculously inconsistent...Compare BindableTextField and BindableTextView's implementations to get a good idea. | ||
|
||
## Usage | ||
|
||
### BindableTextField | ||
Generally known as the king of any binding framework, I've tried to make this guy as simple to use as possible. | ||
|
||
Bindable Properties: | ||
* textBinding: a `BindableValue<String>` that is 2-way bound to the `text` property. | ||
* hiddenBinding: a `BindableValue<Bool>` that is bound to the `hidden` property. | ||
|
||
``` | ||
import AwfulBinding | ||
import AwfulBindingUI | ||
import SwiftBinding | ||
import SwiftBindingUI | ||
public class SomeViewController:UIViewController{ | ||
private var _text = BindableValue<String>(initialValue:"Hello") | ||
private let _text = BindableValue(value:"Hello") | ||
@IBOutlet weak var textField:BindableTextField! //NOTE: tied to a storyboard element of type BindableTextField. | ||
@IBOutlet weak var textField:BindableTextField! //NOTE: This is tied to a storyboard/xib element of type BindableTextField. | ||
override public viewDidLoad(){ | ||
super.viewDidLoad() | ||
textField.bindableValue = _text //EFFECT: textField's text is now set to "Hello" | ||
textField.textBinding = _text //EFFECT: textField's text is now set to "Hello" | ||
_text = "Test" //EFFECT textField's teext is now "Test" | ||
_text.value = "Test" //EFFECT textField's text is now "Test" | ||
//UI EFFECT: changes to the textField in the UI will update the value of _text | ||
} | ||
} | ||
``` | ||
|
||
### BindableTextView | ||
This works almost identically to the BindableTextField | ||
This works almost identically to the BindableTextField. | ||
|
||
Bindable Properties: | ||
* textBinding: a `BindableValue<String>` that is 2-way bound to the `text` property. | ||
* hiddenBinding: a `BindableValue<Bool>` that is bound to the `hidden` property. | ||
|
||
``` | ||
import AwfulBinding | ||
import AwfulBindingUI | ||
import SwiftBinding | ||
import SwiftBindingUI | ||
public class SomeViewController:UIViewController{ | ||
private var _text = BindableValue<String>(initialValue:"Hello") | ||
private var _text = BindableValue(value:"Hello") | ||
@IBOutlet weak var textView:BindableTextView! //NOTE: tied to a storyboard element of type BindableTextView. | ||
override public viewDidLoad(){ | ||
super.viewDidLoad() | ||
textView.bindableValue = _text //EFFECT: textView's text is now set to "Hello" | ||
textField.textBinding = _text //EFFECT: textField's text is now set to "Hello" | ||
_text = "Test" //EFFECT textField's teext is now "Test" | ||
_text.value = "Test" //EFFECT textField's text is now "Test" | ||
//UI EFFECT: changes to the textField in the UI will update the value of _text | ||
} | ||
} | ||
``` | ||
|
||
### BindableImageView | ||
|
||
``` | ||
import AwfulBinding | ||
import AwfulBindingUI | ||
Bindable Properties: | ||
* imageBinding: a `BindableValue<UIImage?>` that is bound to the `image` property. | ||
* hiddenBinding: a `BindableValue<Bool>` that is bound to the `hidden` property. | ||
|
||
public class SomeViewController:UIViewController{ | ||
private var _text = BindableValue<String>(initialValue:"Hello") | ||
Other Properties: | ||
* nilImage: an optional `UIImage?` that is used whenever the value property of `imageBinding` is nil. | ||
|
||
@IBOutlet weak var textView:BindableTextView! //NOTE: tied to a storyboard element of type BindableTextView. | ||
### BindableLabel | ||
|
||
override public viewDidLoad(){ | ||
super.viewDidLoad() | ||
Bindable Properties: | ||
* textBinding: a `BindableValue<String>` that is bound to the `text` property. | ||
* hiddenBinding: a `BindableValue<Bool>` that is bound to the `hidden` property. | ||
|
||
textView.bindableValue = _text //EFFECT: textView's text is now set to "Hello" | ||
### BindableView | ||
|
||
_text = "Test" //EFFECT textField's teext is now "Test" | ||
} | ||
} | ||
``` | ||
Bindable Properties: | ||
* hiddenBinding: a `BindableValue<Bool>` that is bound to the `hidden` property. | ||
|
||
### BindableTableView | ||
NOTE: BindableTableView doesn't currently support sectioned data (i.e. the section count is hardcoded to 1)...this is planned for later. | ||
### BindableSwitch | ||
|
||
``` | ||
import AwfulBinding | ||
import AwfulBindingUI | ||
Bindable Properties: | ||
* onBinding: a `BindableValue<Bool>` that is 2-way bound to the `on` property. | ||
* hiddenBinding: a `BindableValue<Bool>` that is bound to the `hidden` property. | ||
|
||
public class SomeViewController:UIViewController{ | ||
private var _data = BindableArray<String>(initialValue:["Item 1", "Item 2", "Item 3"]) | ||
@IBOutlet weak var tableView:BindableTableView! //NOTE: tied to a storyboard element of type BindableTableView | ||
override public viewDidLoad(){ | ||
super.viewDidLoad() | ||
### BindableButton | ||
|
||
tableView.cellForRowAtIndexPath = cellCreator | ||
tableView.bindableArray = _data | ||
} | ||
Bindable Properties: | ||
* `enabledBinding:BindableValue<Bool>` - 2-way bound to the `enabled` property. | ||
* `hiddenBinding:BindableValue<Bool>` - bound to the `hidden` property. | ||
* `textBinding:`BindableValue<String>` - bound to the title of the button (uses the recommended `setTitle` method). NOTE: At this time, this only applies to the "Normal" state, but will be expanded as the demand arises. | ||
* `imageBinding:BindableValue<UIImage?>` - bound to the image of the button (uses the recommended `setImage` method). NOTE: At this time, this only applies to the "Normal" state, but will be expanded as the demand arises. | ||
|
||
private func cellCreator(indexPath:NSIndexPath) -> UITableViewCell{ | ||
let cell = tableView.dequeueCellForIdentifier("SomeCellIdentifier", indexPath:indexPath) | ||
### BindableSearchBar | ||
Note that this implements its own UISearchBarDelegate, and overwriting the delegate property will break some aspects of its behavior. | ||
|
||
let dataElement = _data[indexPath.row] | ||
Bindable Properties: | ||
* `textBinding: BindableValue<String>` | ||
* `hiddenBinding:BindableValue<Bool>` - bound to the `hidden` property. | ||
|
||
cell.textLabel.text = dataElement | ||
Other Properties: | ||
* `onBeginEditing: (() -> Void)?` | ||
* `onEndEditing: (() -> Void)?` | ||
* `onSearchButtonClick: (() -> Void)?` | ||
* `onCancelButtonClick: (() -> Void)?` | ||
|
||
return cell | ||
} | ||
} | ||
``` | ||
### BindableTableView | ||
Note that this implements itself as its own `UITableViewDataSource` and `UITableViewDelegate`, and overwriting the `datasource` or `delegate` property will break some (most) aspects of its behavior. | ||
|
||
### BindableCollectionView | ||
TODO: very much a work in progress | ||
TODO: more documentation and examples | ||
|
||
``` | ||
TODO | ||
``` | ||
Bindable Properties: | ||
* `sections: BindableArray<PBindableTableSection>` - This is a collection of table sections. | ||
* `singleSection:PBindableTableSection` - This is a convenience property that exposes the `sections` property as if it were a single section. I find I use this most often, as my tables are rarely sectioned in practice. | ||
* `hiddenBinding:BindableValue<Bool>` - bound to the `hidden` property. | ||
|
||
### BindableButton | ||
Other Properties: | ||
* `reloadOnSelect:Bool` | ||
* `onSelect:((section:PBindableTableSection, index:Int) -> Void)?` | ||
* `defaultCellCreator:((sectionIndex:Int, index:Int) -> UITableViewCell)` | ||
* `viewForHeaderInSection:((sectionIndex:Int) -> UIView)?` | ||
* `viewForFooterInSection:((sectionIndex:Int) -> UIView)?` | ||
* `deleteHandler:((indexPath:NSIndexPath) -> Void)?` | ||
|
||
``` | ||
TODO | ||
``` | ||
### BindableCollectionView | ||
Note that this implements itself as its own `UICollectionViewDataSource` and `UICollectionViewDelegate`, and overwriting the `datasource` or `delegate` property will break some (most) aspects of its behavior. | ||
|
||
TODO: very much a work in progress | ||
TODO: more documentation and examples | ||
|
||
Bindable Properties: | ||
* `sections: BindableArray<PBindableTableSection>` - This is a collection of table sections. | ||
* `singleSection:PBindableTableSection` - This is a convenience property that exposes the `sections` property as if it were a single section. I find I use this most often, as my tables are rarely sectioned in practice. | ||
* `hiddenBinding:BindableValue<Bool>` - bound to the `hidden` property. | ||
* `showFooterBinding:BindableValue<Bool>` | ||
|
||
Other Properties: | ||
* `reloadOnSelect:Bool` | ||
* `onSelect:((section:PBindableTableSection, index:Int) -> Void)?` | ||
* `defaultCellCreator:((sectionIndex:Int, index:Int) -> UITableViewCell)` | ||
* `viewForHeaderInSection:((sectionIndex:Int) -> UIView)?` | ||
* `viewForFooterInSection:((sectionIndex:Int) -> UIView)?` | ||
* `deleteHandler:((indexPath:NSIndexPath) -> Void)?` |
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,22 @@ | ||
Pod::Spec.new do |s| | ||
|
||
s.name = "SwiftBindingUI" | ||
s.version = "1.0.0" | ||
s.summary = "A library of simple UI components built around the SwiftBinding library." | ||
|
||
s.description = <<-DESC | ||
A library of the basic iOS UI components with added "binding" functionality built around the SwiftBinding library. | ||
DESC | ||
|
||
s.homepage = "https://github.com/zacharyclaysmith/SwiftBindingUI" | ||
s.license = { :type => "MIT", :file => "LICENSE.md" } | ||
s.author = { "Zachary Clay Smith" => "[email protected]" } | ||
s.platform = :ios | ||
s.ios.deployment_target = "8.0" | ||
|
||
s.source = { :git => "https://github.com/zacharyclaysmith/SwiftBindingUI.git", :tag => s.version } | ||
s.source_files = "SwiftBindingUI/**/*.swift" | ||
s.dependency 'SwiftBinding' | ||
s.requires_arc = true | ||
|
||
end |
Oops, something went wrong.