Skip to content

Commit 534b62b

Browse files
committed
Import from @mxcl/PromiseKit
0 parents  commit 534b62b

26 files changed

+2134
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*.xcodeproj/**/xcuserdata/
2+
*.xcscmblueprint
3+
/Carthage
4+
/Cartfile.resolved
5+
/.build

.travis.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
language: objective-c
2+
osx_image: xcode8
3+
4+
env:
5+
- ACTION=test PLATFORM=iOS DESTINATION='platform=iOS Simulator,name=iPhone 6S' UUID='7FC06F6D-AF72-4B38-9A96-1F934EA2E27F'
6+
- ACTION=test PLATFORM=tvOS DESTINATION='platform=tvOS Simulator,name=Apple TV 1080p' UUID='0DF1B136-A3A7-4C51-AE6E-CFEFDF52DA24'
7+
8+
install:
9+
- carthage bootstrap --platform $PLATFORM
10+
11+
script:
12+
- if [ -n "$UUID" ]; then xcrun instruments -w "$UUID" || true; sleep 15; fi
13+
- set -o pipefail && xcodebuild -scheme PMKUIKit -sdk $SDK -destination "id=$UUID" clean build test | xcpretty

Cartfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github "mxcl/PromiseKit" ~> 4.0

Carthage.xcconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Created by Kevin Ballard on 12/14/15.
2+
// Copyright © 2015 Postmates. All rights reserved.
3+
4+
FRAMEWORK_SEARCH_PATHS[sdk=macosx*] = $(SRCROOT)/Carthage/Build/Mac/ $(inherited)
5+
FRAMEWORK_SEARCH_PATHS[sdk=iphone*] = $(SRCROOT)/Carthage/Build/iOS/ $(inherited)
6+
FRAMEWORK_SEARCH_PATHS[sdk=watch*] = $(SRCROOT)/Carthage/Build/watchOS/ $(inherited)
7+
FRAMEWORK_SEARCH_PATHS[sdk=appletv*] = $(SRCROOT)/Carthage/Build/tvOS/ $(inherited)

Info.plist

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>en</string>
7+
<key>CFBundleExecutable</key>
8+
<string>$(EXECUTABLE_NAME)</string>
9+
<key>CFBundleIdentifier</key>
10+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
11+
<key>CFBundleInfoDictionaryVersion</key>
12+
<string>6.0</string>
13+
<key>CFBundleName</key>
14+
<string>$(PRODUCT_NAME)</string>
15+
<key>CFBundlePackageType</key>
16+
<string>$(BUNDLE_PACKAGE_TYPE)</string>
17+
<key>CFBundleShortVersionString</key>
18+
<string>1.0</string>
19+
<key>CFBundleVersion</key>
20+
<string>$(CURRENT_PROJECT_VERSION)</string>
21+
<key>NSPrincipalClass</key>
22+
<string></string>
23+
</dict>
24+
</plist>

PMKUIKit.xcodeproj/project.pbxproj

Lines changed: 739 additions & 0 deletions
Large diffs are not rendered by default.

PMKUIKit.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded</key>
6+
<false/>
7+
</dict>
8+
</plist>
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "0800"
4+
version = "1.3">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "NO">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "YES"
13+
buildForArchiving = "YES"
14+
buildForAnalyzing = "YES">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "63C7FFA61D5BEE09003BAE60"
18+
BuildableName = "PMKUIKit.framework"
19+
BlueprintName = "PMKUIKit"
20+
ReferencedContainer = "container:PMKUIKit.xcodeproj">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
<BuildActionEntry
24+
buildForTesting = "YES"
25+
buildForRunning = "NO"
26+
buildForProfiling = "NO"
27+
buildForArchiving = "NO"
28+
buildForAnalyzing = "NO">
29+
<BuildableReference
30+
BuildableIdentifier = "primary"
31+
BlueprintIdentifier = "63C7FFF11D5C020D003BAE60"
32+
BuildableName = "PMKUITests.xctest"
33+
BlueprintName = "PMKUITests"
34+
ReferencedContainer = "container:PMKUIKit.xcodeproj">
35+
</BuildableReference>
36+
</BuildActionEntry>
37+
</BuildActionEntries>
38+
</BuildAction>
39+
<TestAction
40+
buildConfiguration = "Debug"
41+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
42+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
43+
shouldUseLaunchSchemeArgsEnv = "YES">
44+
<Testables>
45+
<TestableReference
46+
skipped = "NO">
47+
<BuildableReference
48+
BuildableIdentifier = "primary"
49+
BlueprintIdentifier = "63C7FFF11D5C020D003BAE60"
50+
BuildableName = "PMKUITests.xctest"
51+
BlueprintName = "PMKUITests"
52+
ReferencedContainer = "container:PMKUIKit.xcodeproj">
53+
</BuildableReference>
54+
</TestableReference>
55+
<TestableReference
56+
skipped = "NO">
57+
<BuildableReference
58+
BuildableIdentifier = "primary"
59+
BlueprintIdentifier = "630B2DFF1D5D0AF500DC10E9"
60+
BuildableName = "PMKUIUITests.xctest"
61+
BlueprintName = "PMKUIUITests"
62+
ReferencedContainer = "container:PMKUIKit.xcodeproj">
63+
</BuildableReference>
64+
<SkippedTests>
65+
<Test
66+
Identifier = "UIImagePickerControllerTests/test_fulfills_with_edited_image()">
67+
</Test>
68+
</SkippedTests>
69+
</TestableReference>
70+
</Testables>
71+
<MacroExpansion>
72+
<BuildableReference
73+
BuildableIdentifier = "primary"
74+
BlueprintIdentifier = "63C7FFA61D5BEE09003BAE60"
75+
BuildableName = "PMKUIKit.framework"
76+
BlueprintName = "PMKUIKit"
77+
ReferencedContainer = "container:PMKUIKit.xcodeproj">
78+
</BuildableReference>
79+
</MacroExpansion>
80+
<AdditionalOptions>
81+
</AdditionalOptions>
82+
</TestAction>
83+
<LaunchAction
84+
buildConfiguration = "Debug"
85+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
86+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
87+
launchStyle = "0"
88+
useCustomWorkingDirectory = "NO"
89+
ignoresPersistentStateOnLaunch = "NO"
90+
debugDocumentVersioning = "YES"
91+
debugServiceExtension = "internal"
92+
allowLocationSimulation = "YES">
93+
<MacroExpansion>
94+
<BuildableReference
95+
BuildableIdentifier = "primary"
96+
BlueprintIdentifier = "63C7FFA61D5BEE09003BAE60"
97+
BuildableName = "PMKUIKit.framework"
98+
BlueprintName = "PMKUIKit"
99+
ReferencedContainer = "container:PMKUIKit.xcodeproj">
100+
</BuildableReference>
101+
</MacroExpansion>
102+
<AdditionalOptions>
103+
</AdditionalOptions>
104+
</LaunchAction>
105+
<ProfileAction
106+
buildConfiguration = "Release"
107+
shouldUseLaunchSchemeArgsEnv = "YES"
108+
savedToolIdentifier = ""
109+
useCustomWorkingDirectory = "NO"
110+
debugDocumentVersioning = "YES">
111+
<MacroExpansion>
112+
<BuildableReference
113+
BuildableIdentifier = "primary"
114+
BlueprintIdentifier = "63C7FFA61D5BEE09003BAE60"
115+
BuildableName = "PMKUIKit.framework"
116+
BlueprintName = "PMKUIKit"
117+
ReferencedContainer = "container:PMKUIKit.xcodeproj">
118+
</BuildableReference>
119+
</MacroExpansion>
120+
</ProfileAction>
121+
<AnalyzeAction
122+
buildConfiguration = "Debug">
123+
</AnalyzeAction>
124+
<ArchiveAction
125+
buildConfiguration = "Release"
126+
revealArchiveInOrganizer = "YES">
127+
</ArchiveAction>
128+
</Scheme>

README.markdown

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# PromiseKit UIKit Extensions ![Build Status]
2+
3+
This project adds promises to Apple’s UIKit framework.
4+
5+
## CococaPods
6+
7+
```ruby
8+
pod "PromiseKit/UIKit" ~> 4.0
9+
```
10+
11+
The extensions are built into `PromiseKit.framework` thus nothing else is needed.
12+
13+
## Carthage
14+
15+
```ruby
16+
github "PromiseKit/UIKit" ~> 1.0
17+
```
18+
19+
The extensions are built into their own framework:
20+
21+
```swift
22+
// swift
23+
import PromiseKit
24+
import PMKUIKit
25+
```
26+
27+
```objc
28+
// objc
29+
@import PromiseKit;
30+
@import PMKUIKit;
31+
```
32+
33+
34+
[Build Status]: https://travis-ci.org/PromiseKit/UIKit.svg?branch=master

Sources/PMKAlertController.swift

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import UIKit
2+
#if !COCOAPODS
3+
import PromiseKit
4+
#endif
5+
6+
//TODO tests
7+
//TODO NSCoding
8+
9+
/**
10+
A “promisable” UIAlertController.
11+
12+
UIAlertController is not a suitable API for an extension; it has closure
13+
handlers on its main API for each button and an extension would have to
14+
either replace all these when the controller is presented or force you to
15+
use an extended addAction method, which would be easy to forget part of
16+
the time. Hence we provide a facade pattern that can be promised.
17+
18+
let alert = PMKAlertController("OHAI")
19+
let sup = alert.addActionWithTitle("SUP")
20+
let bye = alert.addActionWithTitle("BYE")
21+
promiseViewController(alert).then { action in
22+
switch action {
23+
case is sup:
24+
//…
25+
case is bye:
26+
//…
27+
}
28+
}
29+
*/
30+
public class PMKAlertController {
31+
/// The title of the alert.
32+
public var title: String? { return UIAlertController.title }
33+
/// Descriptive text that provides more details about the reason for the alert.
34+
public var message: String? { return UIAlertController.message }
35+
/// The style of the alert controller.
36+
public var preferredStyle: UIAlertControllerStyle { return UIAlertController.preferredStyle }
37+
/// The actions that the user can take in response to the alert or action sheet.
38+
public var actions: [UIAlertAction] { return UIAlertController.actions }
39+
/// The array of text fields displayed by the alert.
40+
public var textFields: [UITextField]? { return UIAlertController.textFields }
41+
42+
#if !os(tvOS)
43+
/// The nearest popover presentation controller that is managing the current view controller.
44+
public var popoverPresentationController: UIPopoverPresentationController? { return UIAlertController.popoverPresentationController }
45+
#endif
46+
47+
/// Creates and returns a view controller for displaying an alert to the user.
48+
public required init(title: String?, message: String? = nil, preferredStyle: UIAlertControllerStyle = .alert) {
49+
UIAlertController = UIKit.UIAlertController(title: title, message: message, preferredStyle: preferredStyle)
50+
}
51+
52+
/// Attaches an action title to the alert or action sheet.
53+
public func addActionWithTitle(title: String, style: UIAlertActionStyle = .default) -> UIAlertAction {
54+
let action = UIAlertAction(title: title, style: style) { action in
55+
if style != .cancel {
56+
self.fulfill(action)
57+
} else {
58+
self.reject(Error.cancelled)
59+
}
60+
}
61+
UIAlertController.addAction(action)
62+
return action
63+
}
64+
65+
/// Adds a text field to an alert.
66+
public func addTextFieldWithConfigurationHandler(configurationHandler: ((UITextField) -> Void)?) {
67+
UIAlertController.addTextField(configurationHandler: configurationHandler)
68+
}
69+
70+
fileprivate let UIAlertController: UIKit.UIAlertController
71+
fileprivate let (promise, fulfill, reject) = Promise<UIAlertAction>.pending()
72+
fileprivate var retainCycle: PMKAlertController?
73+
74+
/// Errors that represent PMKAlertController failures
75+
public enum Error: CancellableError {
76+
/// The user cancelled the PMKAlertController.
77+
case cancelled
78+
79+
/// - Returns: true
80+
public var isCancelled: Bool {
81+
return self == .cancelled
82+
}
83+
}
84+
}
85+
86+
extension UIViewController {
87+
/// Presents the PMKAlertController, resolving with the user action.
88+
public func promise(_ vc: PMKAlertController, animated: Bool = true, completion: (() -> Void)? = nil) -> Promise<UIAlertAction> {
89+
vc.retainCycle = vc
90+
present(vc.UIAlertController, animated: animated, completion: completion)
91+
_ = vc.promise.always { _ -> Void in
92+
vc.retainCycle = nil
93+
}
94+
return vc.promise
95+
}
96+
}

Sources/PMKUIKit.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#import "UIView+AnyPromise.h"
2+
#import "UIViewController+AnyPromise.h"

0 commit comments

Comments
 (0)