-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- UIBarButtonItem - Documentation typos
- Loading branch information
Showing
86 changed files
with
1,762 additions
and
100 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,30 @@ | ||
The following rules generally apply for PRs and code changes: | ||
|
||
**Submit Pull Requests to the `develop` branch** | ||
|
||
This is where all experimental and other beta-ish features will go. | ||
`develop` will collect many new features until a release is planned. At a point where a stable release is ready, | ||
`develop` branch will then be merged into `master` and a release tag will be generated for the general public. | ||
|
||
**Markdown documentation and header-level comment changes need to run Jazzy** | ||
|
||
If making a change to the documentation or changes inside of method/property quick look comments, | ||
[Jazzy](https://github.com/realm/jazzy) needs to be run. Please install Jazzy and run the following | ||
Terminal command from the Supporting/jazzy directory: | ||
|
||
`./generate_docs.sh` | ||
|
||
**Blend with existing patterns** | ||
|
||
If, for instance, you are contributing by adding another | ||
[Closure API](https://github.com/vhesener/Closures/issues?q=is%3Aissue+is%3Aopen+label%3A%22Closure+API+Request%22) | ||
and that API has a precedent for implementation, it is best to mimic the existing precedent's pattern. | ||
If however, you think both the new API and it's counterparts could use improvements, let's definitely | ||
discuss how to update all of the existing APIs as well. | ||
|
||
Let's take a simple example of adding a new API for a delegate protocol. The following is almost universal: | ||
|
||
- [x] Use the Delegate/Delegator wrapper mechanism used by other delegate APIs | ||
- [x] Unit tests to make sure all delegate methods are covered | ||
- [x] Documentation on any public initializers, methods, or properties | ||
- [x] Playground example showing how to use it, along with explanations |
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 @@ | ||
4.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,23 @@ | ||
{ | ||
"name": "Closures", | ||
"version": "0.3", | ||
"summary": "Swifty closures for UIKit and Foundation", | ||
"homepage": "https://github.com/vhesener/Closures", | ||
"screenshots": [ | ||
"https://raw.githubusercontent.com/vhesener/Closures/assets/assets/playground_general.gif", | ||
"https://raw.githubusercontent.com/vhesener/Closures/assets/assets/reference_large.png" | ||
], | ||
"license": "MIT", | ||
"authors": "Vinnie Hesener", | ||
"platforms": { | ||
"ios": "9.0" | ||
}, | ||
"source": { | ||
"git": "https://github.com/vhesener/Closures.git", | ||
"tag": "v0.3" | ||
}, | ||
"swift_version": "4.0", | ||
"source_files": "Xcode/Closures/Source", | ||
"documentation_url": "https://vhesener.github.io/Closures/", | ||
"description": "Closures is an iOS Framework that adds closure handlers to many of the popular\nUIKit and Foundation classes. Although this framework is a substitute for \nsome Cocoa Touch design patterns, such as Delegation and Data Sources, and \nTarget-Action, the authors make no claim regarding which is a better way to \naccomplish the same type of task. Most of the time it is a matter of style, \npreference, or convenience that will determine if any of these closure extensions \nare beneficial.\n\nWhether you’re a functional purist, dislike a particular API, or simply just \nwant to organize your code a little bit, you might enjoy using this library." | ||
} |
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,23 @@ | ||
`Closures` framework adds closures for `UIBarButtonItem` tap events, usually | ||
found in a UINavigationBar. | ||
|
||
All initializers that support the target-action pattern now have an equivalent | ||
initialier that contains a `handler` parameter. | ||
|
||
```swift | ||
navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Left item", style: .plain) { | ||
// left bar button item tapped | ||
} | ||
``` | ||
|
||
To add the closure handler to an existing `UIBarButtonItem`, simply call the | ||
`onTap(handler:)` method. For instance, if you created your button | ||
in a storyboard, you could call the following in your `viewDidLoad` method. | ||
|
||
```swift | ||
let myRightBarButton = navigationItem.rightBarButtonItem! | ||
myRightBarButton.onTap { | ||
// right bar button item tapped | ||
} | ||
``` | ||
|
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,7 @@ | ||
jazzy --config jazzy.yml; | ||
|
||
## Have to create this exception in order to have underscores in a class name | ||
## display in the github documentation generator | ||
echo "include: | ||
- \"_5FKeyValueCodingAndObserving.html\" | ||
" > ../../docs/_config.yml |
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
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,118 @@ | ||
/** | ||
The MIT License (MIT) | ||
Copyright (c) 2017 Vincent Hesener | ||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and | ||
associated documentation files (the "Software"), to deal in the Software without restriction, | ||
including without limitation the rights to use, copy, modify, merge, publish, distribute, | ||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software | ||
is furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all copies or | ||
substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT | ||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
import UIKit | ||
|
||
/// :nodoc: | ||
private let jzyBug = 0 // Prevent the license header from showing up in Jazzy Docs for UICollectionView | ||
|
||
public extension UIBarButtonItem { | ||
/** | ||
A convenience initializer for a UIBarButtonItem so that the tap event can | ||
be handled with a closure. This is equivalent of using the init(image:style:target:action:) | ||
initializer. | ||
* parameter image: The image to use for the button | ||
* parameter style: The `UIBarButtonItemStyle` of the button | ||
* parameter handler: The closure that is called when the button is tapped | ||
*/ | ||
public convenience init(image: UIImage?, style: UIBarButtonItemStyle, handler: @escaping () -> Void) { | ||
self.init(image: image, style: style, target: nil, action: nil) | ||
onTap(handler: handler) | ||
} | ||
|
||
/** | ||
A convenience initializer for a UIBarButtonItem so that the tap event can | ||
be handled with a closure. This is equivalent of using the init(image:landscapeImagePhone:style:target:action:) | ||
initializer. | ||
* parameter image: The image to use for the button | ||
* parameter landscapeImagePhone: The image to use for the compressed landscape bar item | ||
* parameter style: The `UIBarButtonItemStyle` of the button | ||
* parameter handler: The closure that is called when the button is tapped | ||
*/ | ||
@available(iOS 5.0, *) | ||
public convenience init(image: UIImage?, landscapeImagePhone: UIImage?, style: UIBarButtonItemStyle, handler: @escaping () -> Void) { | ||
self.init(image: image, landscapeImagePhone: landscapeImagePhone, style: style, target: nil, action: nil) | ||
onTap(handler: handler) | ||
} | ||
|
||
/** | ||
A convenience initializer for a UIBarButtonItem so that the tap event can | ||
be handled with a closure. This is equivalent of using the init(title:style:target:action:) | ||
initializer. | ||
* parameter title: The text to use for the button | ||
* parameter style: The `UIBarButtonItemStyle` of the button | ||
* parameter handler: The closure that is called when the button is tapped | ||
*/ | ||
public convenience init(title: String?, style: UIBarButtonItemStyle, handler: @escaping () -> Void) { | ||
self.init(title: title, style: style, target: nil, action: nil) | ||
onTap(handler: handler) | ||
} | ||
|
||
/** | ||
A convenience initializer for a UIBarButtonItem so that the tap event can | ||
be handled with a closure. This is equivalent of using the init(barButtonSystemItem:target:action:) | ||
initializer. | ||
* parameter barButtonSystemItem: The `UIBarButtonSystemItem` to be used for the button | ||
* parameter handler: The closure that is called when the button is tapped | ||
*/ | ||
public convenience init(barButtonSystemItem systemItem: UIBarButtonSystemItem, handler: @escaping () -> Void) { | ||
self.init(barButtonSystemItem: systemItem, target: nil, action: nil) | ||
onTap(handler: handler) | ||
} | ||
|
||
/** | ||
This method is a convenience method to add a closure handler to a `UIBarButtonItem`. | ||
Use this method if you are creating a `UIBarButtonItem` using an initializer | ||
other than the convience ones provide, or if the item was created by a | ||
Storyboard or xib. | ||
* * * * | ||
#### An example that adds a closure handler to an existing `UIBarButtonItem`: | ||
```swift | ||
myBarButtonItem.onTap { | ||
// bar button tapped code | ||
} | ||
``` | ||
* parameter handler: The closure that will be called when the tap is recognized. | ||
*/ | ||
public func onTap(handler: @escaping () -> Void) { | ||
target = self | ||
action = #selector(UIBarButtonItem.buttonTapped) | ||
NotificationCenter.selfObserve(name: .barButtonItemTapped, target: self) { button, userInfo in | ||
handler() | ||
} | ||
} | ||
} | ||
|
||
fileprivate extension UIBarButtonItem { | ||
@objc func buttonTapped() { | ||
NotificationCenter.closures.post(name: .barButtonItemTapped, object: self) | ||
} | ||
} | ||
|
||
fileprivate extension Notification.Name { | ||
static let barButtonItemTapped = Notification.Name("UIBarButtonItem.tapped") | ||
} |
Oops, something went wrong.