Permalink
Browse files

PromiseKit 4 / Swift 3 / Xcode 8

  • Loading branch information...
mxcl committed Jul 24, 2016
1 parent a1708e5 commit 67bc256992351f3124dbcb17f1a46ea31a6a158a
Showing with 4,667 additions and 13,593 deletions.
  1. +8 −0 .github/ISSUE_TEMPLATE.md
  2. +2 −2 .gitignore
  3. +63 −0 .gitmodules
  4. +1 −1 .jazzy.yaml
  5. +8 −25 .travis.yml
  6. +1 −1 CHANGELOG.markdown
  7. +0 −4 Cartfile.private
  8. +0 −30 Categories/AVFoundation/AVAudioSession+AnyPromise.h
  9. +0 −21 Categories/AVFoundation/AVAudioSession+AnyPromise.m
  10. +0 −23 Categories/AVFoundation/AVAudioSession+Promise.swift
  11. +0 −66 Categories/Accounts/ACAccountStore+AnyPromise.h
  12. +0 −48 Categories/Accounts/ACAccountStore+AnyPromise.m
  13. +0 −53 Categories/Accounts/ACAccountStore+Promise.swift
  14. +0 −102 Categories/AddressBook/ABAddressBookRequestAccess+Promise.swift
  15. +0 −50 Categories/AssetsLibrary/ALAssetsLibrary+Promise.swift
  16. +0 −37 Categories/Bolts/BFTask+Promise.swift
  17. +0 −73 Categories/CloudKit/CKContainer+AnyPromise.h
  18. +0 −59 Categories/CloudKit/CKContainer+AnyPromise.m
  19. +0 −44 Categories/CloudKit/CKContainer+Promise.swift
  20. +0 −32 Categories/CloudKit/CKDatabase+AnyPromise.h
  21. +0 −39 Categories/CloudKit/CKDatabase+AnyPromise.m
  22. +0 −78 Categories/CloudKit/CKDatabase+Promise.swift
  23. +0 −48 Categories/CoreBluetooth/CBCentralManager+Promise.swift
  24. +0 −49 Categories/CoreLocation/CLGeocoder+AnyPromise.h
  25. +0 −48 Categories/CoreLocation/CLGeocoder+AnyPromise.m
  26. +0 −74 Categories/CoreLocation/CLGeocoder+Promise.swift
  27. +0 −46 Categories/CoreLocation/CLLocationManager+AnyPromise.h
  28. +0 −68 Categories/CoreLocation/CLLocationManager+AnyPromise.m
  29. +0 −190 Categories/CoreLocation/CLLocationManager+Promise.swift
  30. +0 −67 Categories/EventKit/EKEventStore+Promise.swift
  31. +0 −43 Categories/Foundation/NSNotificationCenter+AnyPromise.h
  32. +0 −18 Categories/Foundation/NSNotificationCenter+AnyPromise.m
  33. +0 −54 Categories/Foundation/NSNotificationCenter+Promise.swift
  34. +0 −67 Categories/Foundation/NSObject+Promise.swift
  35. +0 −49 Categories/Foundation/NSTask+AnyPromise.h
  36. +0 −41 Categories/Foundation/NSTask+AnyPromise.m
  37. +0 −93 Categories/Foundation/NSTask+Promise.swift
  38. +0 −236 Categories/Foundation/NSURLConnection+AnyPromise.h
  39. +0 −80 Categories/Foundation/NSURLConnection+AnyPromise.m
  40. +0 −79 Categories/Foundation/NSURLConnection+Promise.swift
  41. +0 −236 Categories/Foundation/NSURLSession+AnyPromise.h
  42. +0 −195 Categories/Foundation/NSURLSession+AnyPromise.m
  43. +0 −76 Categories/Foundation/NSURLSession+Promise.swift
  44. +0 −29 Categories/Foundation/afterlife.swift
  45. +0 −43 Categories/MapKit/MKDirections+AnyPromise.h
  46. +0 −37 Categories/MapKit/MKDirections+AnyPromise.m
  47. +0 −29 Categories/MapKit/MKDirections+Promise.swift
  48. +0 −23 Categories/MapKit/MKMapSnapshotter+AnyPromise.h
  49. +0 −14 Categories/MapKit/MKMapSnapshotter+AnyPromise.m
  50. +0 −24 Categories/MapKit/MKMapSnapshotter+Promise.swift
  51. +0 −80 Categories/MessageUI/MFMailComposeViewController+Promise.swift
  52. +0 −77 Categories/MessageUI/MFMessageComposeViewController+Promise.swift
  53. +0 −20 Categories/Photos/PHPhotoLibrary+Promise.swift
  54. +0 −40 Categories/QuartzCore/CALayer+AnyPromise.h
  55. +0 −39 Categories/QuartzCore/CALayer+AnyPromise.m
  56. +0 −40 Categories/Social/SLComposeViewController+Promise.swift
  57. +0 −36 Categories/Social/SLRequest+AnyPromise.h
  58. +0 −46 Categories/Social/SLRequest+AnyPromise.m
  59. +0 −22 Categories/Social/SLRequest+Promise.swift
  60. +0 −31 Categories/StoreKit/SKRequest+AnyPromise.h
  61. +0 −48 Categories/StoreKit/SKRequest+AnyPromise.m
  62. +0 −57 Categories/StoreKit/SKRequest+Promise.swift
  63. +0 −18 Categories/SystemConfiguration/SCNetworkReachability+AnyPromise.h
  64. +0 −116 Categories/SystemConfiguration/SCNetworkReachability+AnyPromise.m
  65. +0 −80 Categories/UIKit/PMKAlertController.swift
  66. +0 −42 Categories/UIKit/UIActionSheet+AnyPromise.h
  67. +0 −41 Categories/UIKit/UIActionSheet+AnyPromise.m
  68. +0 −59 Categories/UIKit/UIActionSheet+Promise.swift
  69. +0 −40 Categories/UIKit/UIAlertView+AnyPromise.h
  70. +0 −41 Categories/UIKit/UIAlertView+AnyPromise.m
  71. +0 −58 Categories/UIKit/UIAlertView+Promise.swift
  72. +0 −80 Categories/UIKit/UIView+AnyPromise.h
  73. +0 −64 Categories/UIKit/UIView+AnyPromise.m
  74. +0 −48 Categories/UIKit/UIView+Promise.swift
  75. +0 −90 Categories/UIKit/UIViewController+AnyPromise.h
  76. +0 −128 Categories/UIKit/UIViewController+AnyPromise.m
  77. +0 −169 Categories/UIKit/UIViewController+Promise.swift
  78. +0 −22 Categories/WatchConnectivity/WCSession+Promise.swift
  79. +1 −0 Extensions/AVFoundation
  80. +1 −0 Extensions/Accounts
  81. +1 −0 Extensions/AddressBook
  82. +1 −0 Extensions/Alamofire
  83. +1 −0 Extensions/AssetsLibrary
  84. +1 −0 Extensions/Bolts
  85. +1 −0 Extensions/CloudKit
  86. +1 −0 Extensions/CoreBluetooth
  87. +1 −0 Extensions/CoreLocation
  88. +1 −0 Extensions/EventKit
  89. +1 −0 Extensions/Foundation
  90. +1 −0 Extensions/MapKit
  91. +1 −0 Extensions/MessagesUI
  92. +1 −0 Extensions/OMGHTTPURLRQ
  93. +1 −0 Extensions/Photos
  94. +1 −0 Extensions/QuartzCore
  95. +1 −0 Extensions/Social
  96. +1 −0 Extensions/StoreKit
  97. +1 −0 Extensions/SystemConfiguration
  98. +1 −0 Extensions/UIKit
  99. +1 −0 Extensions/WatchConnectivity
  100. +1 −1 PromiseKit.playground/contents.xcplayground
  101. +10 −19 PromiseKit.playground/section-1.swift
  102. +0 −6 PromiseKit.playground/timeline.xctimeline
  103. +78 −73 PromiseKit.podspec
  104. +561 −2,150 PromiseKit.xcodeproj/project.pbxproj
  105. +0 −128 PromiseKit.xcodeproj/xcshareddata/xcschemes/PMKiOS.xcscheme
  106. +0 −80 PromiseKit.xcodeproj/xcshareddata/xcschemes/PMKtvOS.xcscheme
  107. +0 −80 PromiseKit.xcodeproj/xcshareddata/xcschemes/PMKwatchOS.xcscheme
  108. +31 −21 PromiseKit.xcodeproj/xcshareddata/xcschemes/{PMKOSX.xcscheme → PromiseKit.xcscheme}
  109. +0 −47 PromiseKit.xcodeproj/xcshareddata/xcschemes/xcschememanagement.plist
  110. +87 −21 README.markdown
  111. +6 −5 Sources/AnyPromise+Private.h
  112. +78 −100 Sources/AnyPromise.h
  113. +33 −71 Sources/AnyPromise.m
  114. +188 −160 Sources/AnyPromise.swift
  115. +49 −0 Sources/DispatchQueue+Promise.swift
  116. +48 −120 Sources/Error.swift
  117. +76 −0 Sources/GlobalState.m
  118. +4 −0 Sources/Info.plist
  119. +0 −16 Sources/NSError+Cancellation.h
  120. +0 −33 Sources/PMK.modulemap
  121. +4 −35 Sources/PMKCallVariadicBlock.m
  122. +41 −0 Sources/Promise+AnyPromise.swift
  123. +12 −31 Sources/Promise+Properties.swift
  124. +243 −529 Sources/Promise.swift
  125. +62 −80 Sources/PromiseKit.h
  126. +107 −51 Sources/State.swift
  127. +0 −109 Sources/URLDataPromise.swift
  128. +0 −89 Sources/Umbrella.h
  129. +80 −0 Sources/Zalgo.swift
  130. +1 −0 Sources/after.m
  131. +5 −13 Sources/after.swift
  132. +5 −5 Sources/dispatch_promise.m
  133. +0 −23 Sources/dispatch_promise.swift
  134. +6 −1 Sources/hang.m
  135. +18 −11 Sources/join.m
  136. +14 −11 Sources/join.swift
  137. +24 −11 Sources/race.swift
  138. +15 −7 Sources/when.m
  139. +59 −48 Sources/when.swift
  140. +75 −0 Sources/wrap.swift
  141. +0 −89 Tests/A+ Specs/0.0.0.swift
  142. +0 −70 Tests/A+ Specs/2.1.2.swift
  143. +0 −90 Tests/A+ Specs/2.1.3.swift
  144. +0 −176 Tests/A+ Specs/2.2.2.swift
  145. +0 −178 Tests/A+ Specs/2.2.3.swift
  146. +0 −222 Tests/A+ Specs/2.2.4.swift
  147. +0 −322 Tests/A+ Specs/2.2.6.swift
  148. +0 −50 Tests/A+ Specs/2.2.7.swift
  149. +0 −40 Tests/A+ Specs/2.3.1.swift
  150. +0 −127 Tests/A+ Specs/2.3.2.swift
  151. +0 −11 Tests/A+ Specs/2.3.3.swift
  152. +0 −30 Tests/A+ Specs/2.3.4.swift
  153. +154 −0 Tests/A+/0.0.0.swift
  154. +26 −0 Tests/A+/2.1.2.swift
  155. +34 −0 Tests/A+/2.1.3.swift
  156. +92 −0 Tests/A+/2.2.2.swift
  157. +94 −0 Tests/A+/2.2.3.swift
  158. +146 −0 Tests/A+/2.2.4.swift
  159. +266 −0 Tests/A+/2.2.6.swift
  160. +33 −0 Tests/A+/2.2.7.swift
  161. +31 −0 Tests/A+/2.3.1.swift
  162. +116 −0 Tests/A+/2.3.2.swift
  163. +26 −0 Tests/A+/2.3.4.swift
  164. +13 −0 Tests/A+/README.md
  165. +0 −53 Tests/AnyPromise.test.swift
  166. +22 −0 Tests/Bridging/BridgingTests.m
  167. +207 −0 Tests/Bridging/BridgingTests.swift
  168. +12 −0 Tests/Bridging/Infrastructure.h
  169. +27 −0 Tests/Bridging/Infrastructure.m
  170. +9 −0 Tests/Bridging/Infrastructure.swift
  171. +0 −17 Tests/Categories/TestAVFoundation.m
  172. +0 −15 Tests/Categories/TestAVFoundation.swift
  173. +0 −69 Tests/Categories/TestAccounts.swift
  174. +0 −17 Tests/Categories/TestAddressBook.swift
  175. +0 −140 Tests/Categories/TestCloudKit.swift
  176. +0 −127 Tests/Categories/TestCoreLocation.swift
  177. +0 −59 Tests/Categories/TestMapKit.swift
  178. +0 −61 Tests/Categories/TestMessageUI.m
  179. +0 −69 Tests/Categories/TestMessageUI.swift
  180. +0 −23 Tests/Categories/TestNSNotificationCenter.swift
  181. +0 −75 Tests/Categories/TestNSObject.swift
  182. +0 −41 Tests/Categories/TestNSTask.swift
  183. +0 −48 Tests/Categories/TestNSURLConnection.m
  184. +0 −25 Tests/Categories/TestNSURLConnection.swift
  185. +0 −18 Tests/Categories/TestQuartzCore.m
  186. +0 −136 Tests/Categories/TestSocial.m
  187. +0 −33 Tests/Categories/TestSocial.swift
  188. +0 −26 Tests/Categories/TestStoreKit.m
  189. +0 −44 Tests/Categories/TestStoreKit.swift
  190. +0 −87 Tests/Categories/TestUIActionSheet.m
  191. +0 −73 Tests/Categories/TestUIActionSheet.swift
  192. +0 −74 Tests/Categories/TestUIAlertView.m
  193. +0 −73 Tests/Categories/TestUIAlertView.swift
  194. +0 −56 Tests/Categories/TestUIImagePickerController.swift
  195. +0 −135 Tests/Categories/TestUIViewController.m
  196. +0 −98 Tests/Categories/TestUIViewController.swift
  197. +0 −56 Tests/Categories/TestWatchConnectivity.swift
  198. +0 −6 Tests/Categories/bridge.h
  199. +0 −33 Tests/Categories/utils.m
  200. +0 −31 Tests/Categories/utils.swift
  201. +35 −30 Tests/CorePromise/{AnyPromise.test.m → 01_AnyPromiseTests.m}
  202. +82 −0 Tests/CorePromise/01_PromiseTests.swift
  203. +149 −0 Tests/CorePromise/02_CancellationTests.swift
  204. +65 −0 Tests/CorePromise/02_DefaultDispatchQueueTests.swift
  205. +18 −28 Tests/CorePromise/{ErrorUnhandler.test.m → 02_ErrorUnhandlerTests.m}
  206. +185 −0 Tests/CorePromise/02_ErrorUnhandlerTests.swift
  207. +1 −1 Tests/CorePromise/{PMKManifold.test.m → 02_PMKManifoldTests.m}
  208. +61 −0 Tests/CorePromise/02_ZalgoTests.swift
  209. +34 −0 Tests/CorePromise/03_AfterTests.swift
  210. +3 −3 Tests/CorePromise/{hang.test.m → 03_HangTests.m}
  211. +3 −3 Tests/CorePromise/{join.test.m → 03_JoinTests.m}
  212. +55 −0 Tests/CorePromise/03_JoinTests.swift
  213. +40 −0 Tests/CorePromise/03_RaceTests.swift
  214. +59 −26 Tests/CorePromise/{whenConcurrent.test.swift → 03_WhenConcurrentTests.swift}
  215. +4 −4 Tests/CorePromise/{when.test.m → 03_WhenTests.m}
  216. +213 −0 Tests/CorePromise/03_WhenTests.swift
  217. +34 −0 Tests/CorePromise/04_VerifySubclassing.swift
  218. +77 −0 Tests/CorePromise/98_StressTests.swift
  219. +27 −0 Tests/CorePromise/99_RegressionTests.swift
  220. +0 −216 Tests/CorePromise/ErrorUnhandler.test.swift
  221. +11 −0 Tests/CorePromise/Infrastructure.h
  222. +16 −0 Tests/CorePromise/Infrastructure.m
  223. +16 −0 Tests/CorePromise/Infrastructure.swift
  224. +0 −181 Tests/CorePromise/PMKDefaultDispatchQueueTest.m
  225. +46 −151 Tests/CorePromise/PMKDefaultDispatchQueueTest.swift
  226. +0 −154 Tests/CorePromise/Promise.test.swift
  227. +0 −27 Tests/CorePromise/after.test.swift
  228. +0 −3 Tests/CorePromise/bridge.h
  229. +0 −40 Tests/CorePromise/bridging.test.m
  230. +0 −111 Tests/CorePromise/bridging.test.swift
  231. +0 −40 Tests/CorePromise/race.test.swift
  232. +0 −220 Tests/CorePromise/when.test.swift
  233. +0 −89 Tests/CorePromise/zalgo.test.swift
  234. +0 −12 Tests/Entitlements.plist
  235. +0 −17 Tests/TestEventKit.swift
  236. +0 −46 Tests/TestNSURLSession.swift
  237. BIN Tests/UITests/Default-568h@2x.png
  238. +0 −16 Tests/UITests/TestSLComposeViewController.swift
  239. +0 −48 Tests/UITests/TestUIImagePickerController.swift
  240. +0 −97 Tests/UITests/app.swift
  241. +0 −21 Tests/UITests/utils.swift
  242. +0 −125 Tests/join.test.swift
@@ -0,0 +1,8 @@
* PromiseKit version:
* Xcode version:
* Installation method:
- [ ] CocoaPods
- [ ] Carthage
- [ ] Other (please specify)
> Please format your code in triple backticks and delete this line before submitting your ticket.
View
@@ -1,4 +1,4 @@
*.xcodeproj/**/xcuserdata/
*.xcscmblueprint
/Carthage
/Cartfile.resolved
/Build
*.xcodeproj/xcuserdata/
View
@@ -0,0 +1,63 @@
[submodule "Extensions/Foundation"]
path = Extensions/Foundation
url = https://github.com/PromiseKit/Foundation.git
[submodule "Extensions/UIKit"]
path = Extensions/UIKit
url = https://github.com/PromiseKit/UIKit.git
[submodule "Extensions/Accounts"]
path = Extensions/Accounts
url = https://github.com/PromiseKit/Accounts.git
[submodule "Extensions/MessagesUI"]
path = Extensions/MessagesUI
url = https://github.com/PromiseKit/MessagesUI.git
[submodule "Extensions/WatchConnectivity"]
path = Extensions/WatchConnectivity
url = https://github.com/PromiseKit/WatchConnectivity.git
[submodule "Extensions/Photos"]
path = Extensions/Photos
url = https://github.com/PromiseKit/Photos.git
[submodule "Extensions/MapKit"]
path = Extensions/MapKit
url = https://github.com/PromiseKit/MapKit.git
[submodule "Extensions/CloudKit"]
path = Extensions/CloudKit
url = https://github.com/PromiseKit/CloudKit.git
[submodule "Extensions/AddressBook"]
path = Extensions/AddressBook
url = https://github.com/PromiseKit/AddressBook.git
[submodule "Extensions/AssetsLibrary"]
path = Extensions/AssetsLibrary
url = https://github.com/PromiseKit/AssetsLibrary.git
[submodule "Extensions/CoreLocation"]
path = Extensions/CoreLocation
url = https://github.com/PromiseKit/CoreLocation.git
[submodule "Extensions/QuartzCore"]
path = Extensions/QuartzCore
url = https://github.com/PromiseKit/QuartzCore.git
[submodule "Extensions/Social"]
path = Extensions/Social
url = https://github.com/PromiseKit/Social.git
[submodule "Extensions/StoreKit"]
path = Extensions/StoreKit
url = https://github.com/PromiseKit/StoreKit.git
[submodule "Extensions/Bolts"]
path = Extensions/Bolts
url = https://github.com/PromiseKit/Bolts.git
[submodule "Extensions/CoreBluetooth"]
path = Extensions/CoreBluetooth
url = https://github.com/PromiseKit/CoreBluetooth.git
[submodule "Extensions/EventKit"]
path = Extensions/EventKit
url = https://github.com/PromiseKit/EventKit.git
[submodule "Extensions/SystemConfiguration"]
path = Extensions/SystemConfiguration
url = https://github.com/PromiseKit/SystemConfiguration
[submodule "Extensions/Alamofire"]
path = Extensions/Alamofire
url = https://github.com/PromiseKit/Alamofire
[submodule "Extensions/OMGHTTPURLRQ"]
path = Extensions/OMGHTTPURLRQ
url = https://github.com/PromiseKit/OMGHTTPURLRQ
[submodule "Extensions/AVFoundation"]
path = Extensions/AVFoundation
url = https://github.com/PromiseKit/AVFoundation
View
@@ -1,6 +1,6 @@
module: PromiseKit
author: Max Howell
author_url: http://mcl.github.io
author_url: http://mxcl.github.io
github_url: https://github.com/mxcl/PromiseKit
exclude:
- README.markdown
View
@@ -1,29 +1,12 @@
language: objective-c
xcode_project: PromiseKit.xcodeproj
xcode_scheme: [PMKiOS, PMKOSX]
xcode_sdk: [iphonesimulator9.3, macosx10.11]
osx_image: xcode7.3
osx_image: xcode8
install:
- "gem install travis-xcodebuild"
- "carthage bootstrap --platform Mac,iOS"
env:
- iOS= DST='platform=iOS Simulator,name=iPhone 6S' UUID='7FC06F6D-AF72-4B38-9A96-1F934EA2E27F' ACTION=test
- tvOS= DST='platform=tvOS Simulator,name=Apple TV 1080p' UUID='0DF1B136-A3A7-4C51-AE6E-CFEFDF52DA24' ACTION=test
- macOS= DST='platform=OS X' ACTION=test
- watchOS= DST='platform=watchOS Simulator,name=Apple Watch - 38mm' ACTION=build
script:
- travis-xcodebuild
matrix:
exclude:
- xcode_scheme: PMKOSX
xcode_sdk: iphonesimulator9.3
- xcode_scheme: PMKiOS
xcode_sdk: macosx10.11
branches:
only:
- master
- swift-2.2-minimal-changes
- swift-2.0-minimal-changes
- legacy-1.x
after_success:
- bash <(curl -s https://codecov.io/bash)
- if [ -n "$UUID" ]; then xcrun instruments -w "$UUID" || true; sleep 15; fi
- set -o pipefail && xcodebuild -scheme PromiseKit -destination "$DST" $ACTION | xcpretty
View
@@ -1,6 +1,6 @@
# [4.0.0](https://github.com/mxcl/PromiseKit/releases/tag/4.0.0)
* Unreleased support for Swift 3.0
* [PromiseKit 4 announcement post](http://promisekit.org/news/2016/09/PromiseKit-4.0-Released/).
# [3.4.3](https://github.com/mxcl/PromiseKit/releases/tag/3.4.3) Aug 7th, 2016
View
@@ -1,4 +0,0 @@
github "AliSoftware/OHHTTPStubs" == 5.1.0
github "robb/Stubbilino" == 0.2.1
github "BoltsFramework/Bolts-iOS" == 1.8.4
github "mxcl/OMGHTTPURLRQ" ~> 3.2.0
@@ -1,30 +0,0 @@
//
// AVFoundation+AnyPromise.h
//
// Created by Matthew Loseke on 6/21/14.
//
#import <AVFoundation/AVAudioSession.h>
#import <PromiseKit/AnyPromise.h>
/**
To import the `AVAudioSession` category:
use_frameworks!
pod "PromiseKit/AVFoundation"
And then in your sources:
#import <PromiseKit/PromiseKit.h>
*/
@interface AVAudioSession (PromiseKit)
/**
Wraps `-requestRecordPermission:`, thens the `BOOL granted` parameter
passed to the wrapped completion block. This promise cannot fail.
@see requestRecordPermission:
*/
- (AnyPromise *)requestRecordPermission;
@end
@@ -1,21 +0,0 @@
//
// AVAudioSession+PromiseKit.m
//
// Created by Matthew Loseke on 6/21/14.
//
#import "AVAudioSession+AnyPromise.h"
#import <Foundation/Foundation.h>
@implementation AVAudioSession (PromiseKit)
- (AnyPromise *)requestRecordPermission {
return [AnyPromise promiseWithResolverBlock:^(PMKResolver resolve) {
[[AVAudioSession sharedInstance] requestRecordPermission:^(BOOL granted) {
resolve(@(granted));
}];
}];
}
@end
@@ -1,23 +0,0 @@
import AVFoundation
import Foundation
#if !COCOAPODS
import PromiseKit
#endif
/**
To import the `AVAudioSession` category:
use_frameworks!
pod "PromiseKit/AVFoundation"
And then in your sources:
import PromiseKit
*/
extension AVAudioSession {
public func requestRecordPermission() -> Promise<Bool> {
return Promise { fulfill, _ in
requestRecordPermission(fulfill)
}
}
}
@@ -1,66 +0,0 @@
//
// Created by merowing on 09/05/2014.
//
//
//
#import <PromiseKit/AnyPromise.h>
#import <Accounts/ACAccountStore.h>
/**
To import the `ACAccountStore` category:
use_frameworks!
pod "PromiseKit/Accounts"
And then in your sources:
#import <PromiseKit/PromiseKit.h>
*/
@interface ACAccountStore (PromiseKit)
/**
Obtains permission to access protected user properties.
@param accountType The account type.
@param options Can be nil.
@return A promise that resolves when the requested permissions have been
successfully obtained. The promise thens all accounts of the specified
type.
@see requestAccessToAccountsWithType:options:completion:
*/
- (AnyPromise *)requestAccessToAccountsWithType:(ACAccountType *)type options:(NSDictionary *)options;
/**
Renews account credentials when the credentials are no longer valid.
@param account The account to renew credentials.
@return A promise that thens the `ACAccountCredentialRenewResult`.
*/
- (AnyPromise *)renewCredentialsForAccount:(ACAccount *)account;
/**
Saves an account to the Accounts database.
@param account The account to save.
@return A promise that resolves when the account has been successfully
saved.
*/
- (AnyPromise *)saveAccount:(ACAccount *)account;
/**
Removes an account from the account store.
@param account The account to remove.
@return A promise that resolves when the account has been successfully
removed.
*/
- (AnyPromise *)removeAccount:(ACAccount *)account;
@end
@@ -1,48 +0,0 @@
#import "ACAccountStore+AnyPromise.h"
#import <PromiseKit/PromiseKit.h>
@implementation ACAccountStore (PromiseKit)
- (AnyPromise *)requestAccessToAccountsWithType:(ACAccountType *)type options:(NSDictionary *)options {
return [AnyPromise promiseWithResolverBlock:^(PMKResolver resolve) {
[self requestAccessToAccountsWithType:type options:options completion:^(BOOL granted, NSError *error) {
if (granted) {
resolve([self accountsWithAccountType:type]);
} else if (error) {
resolve(error);
} else {
error = [NSError errorWithDomain:PMKErrorDomain code:PMKAccessDeniedError userInfo:@{
NSLocalizedDescriptionKey: @"Access to the requested social service has been denied. Please enable access in your device settings."
}];
resolve(error);
}
}];
}];
}
- (AnyPromise *)renewCredentialsForAccount:(ACAccount *)account {
return [AnyPromise promiseWithResolverBlock:^(PMKResolver resolve) {
[self renewCredentialsForAccount:account completion:^(ACAccountCredentialRenewResult renewResult, NSError *error) {
resolve(error ?: @(renewResult));
}];
}];
}
- (AnyPromise *)saveAccount:(ACAccount *)account {
return [AnyPromise promiseWithResolverBlock:^(PMKResolver resolve) {
[self saveAccount:account withCompletionHandler:^(BOOL success, NSError *error) {
resolve(error);
}];
}];
}
- (AnyPromise *)removeAccount:(ACAccount *)account {
return [AnyPromise promiseWithResolverBlock:^(PMKResolver resolve) {
[self removeAccount:account withCompletionHandler:^(BOOL success, NSError *error) {
resolve(error);
}];
}];
}
@end
@@ -1,53 +0,0 @@
import Accounts
#if !COCOAPODS
import PromiseKit
#endif
/**
To import the `ACAccountStore` category:
use_frameworks!
pod "PromiseKit/ACAccountStore"
And then in your sources:
import PromiseKit
*/
extension ACAccountStore {
public func renewCredentialsForAccount(account: ACAccount) -> Promise<ACAccountCredentialRenewResult> {
return Promise { renewCredentialsForAccount(account, completion: $0) }
}
public func requestAccessToAccountsWithType(type: ACAccountType, options: [String: AnyObject]? = nil) -> Promise<Void> {
return Promise<Void> { fulfill, reject in
requestAccessToAccountsWithType(type, options: options, completion: { granted, error in
if granted {
fulfill()
} else if error != nil {
reject(error)
} else {
reject(Error.AccessDenied)
}
})
}
}
public func saveAccount(account: ACAccount) -> Promise<Void> {
return Promise<Bool> { saveAccount(account, withCompletionHandler: $0) }.asVoid()
}
public func removeAccount(account: ACAccount) -> Promise<Void> {
return Promise<Bool> { removeAccount(account, withCompletionHandler: $0) }.asVoid()
}
public enum Error: ErrorType {
case AccessDenied
public var localizedDescription: String {
switch self {
case .AccessDenied:
return "Access to the requested social service has been denied. Please enable access in your device settings."
}
}
}
}
Oops, something went wrong.

0 comments on commit 67bc256

Please sign in to comment.