File tree 7 files changed +121
-34
lines changed
7 files changed +121
-34
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,8 @@ DerivedData
16
16
* .hmap
17
17
* .ipa
18
18
* .xcuserstate
19
+ .DS_Store
20
+ Podfile.lock
19
21
20
22
# CocoaPods
21
23
#
Load Diff Large diffs are not rendered by default.
Original file line number Diff line number Diff line change
1
+ //
2
+ // HelperTests.swift
3
+ // BAPromise
4
+ //
5
+ // Created by Taichi Matsumoto on 12/28/16.
6
+ // Copyright © 2016 Ben Allison. All rights reserved.
7
+ //
8
+
9
+ import XCTest
10
+ import BAPromise
11
+
12
+ class HelperTests : XCTestCase {
13
+
14
+ override func setUp( ) {
15
+ super. setUp ( )
16
+ }
17
+
18
+ override func tearDown( ) {
19
+ super. tearDown ( )
20
+ }
21
+
22
+ func testFulfillWithFactoryMethod( ) {
23
+ let expectation = XCTestExpectation ( )
24
+
25
+ BAPromiseClient < NSString > . promise ( { fulfill, reject in
26
+ fulfill ( " Success " as NSString )
27
+ } ) . then { value in
28
+ expectation. fulfill ( )
29
+ } . rejected { error in
30
+ XCTFail ( " the promise should never be rejected " )
31
+ }
32
+ }
33
+
34
+ func testRejectWithFactoryMethod( ) {
35
+ let expectation = XCTestExpectation ( )
36
+
37
+ BAPromiseClient < NSString > . promise ( { fulfill, reject in
38
+ reject ( NSError ( domain: " promise test " , code: 0 , userInfo: nil ) )
39
+ } ) . then { value in
40
+ XCTFail ( " the promise should never be fulfilled " )
41
+ } . rejected { error in
42
+ expectation. fulfill ( )
43
+ }
44
+ }
45
+ }
Original file line number Diff line number Diff line change @@ -87,6 +87,10 @@ typedef dispatch_block_t BAPromiseFinallyBlock;
87
87
+(instancetype )fulfilledPromise : (T)obj ;
88
88
+(instancetype )rejectedPromise : (NSError *)error ;
89
89
90
+ // Unfortunate signature thanks to objc fukcing block syntax.
91
+ // This method takes one block "resolver" as a parameter, which takes two blocks "fulfill" and "reject".
92
+ +(nonnull instancetype )promiseWithResolver : (void (^ __nonnull)(void (^ __nonnull fulfill)(__nonnull T), void (^ __nonnull reject)(NSError * __nonnull)))resolver NS_SWIFT_NAME(promise(_:));
93
+
90
94
/* helper methods to streamline syntax for nil objects*/
91
95
-(void )fulfill ;
92
96
-(void )reject ;
Original file line number Diff line number Diff line change @@ -520,6 +520,18 @@ +(BAPromiseClient *)rejectedPromise:(NSError *)error
520
520
return promise;
521
521
}
522
522
523
+ +(instancetype )promiseWithResolver : (void (^)(void (^fulfill)(id ), void (^reject)(NSError *)))resolver
524
+ {
525
+ BAPromiseClient *promise = [[BAPromiseClient alloc ] init ];
526
+ resolver (^(id obj) {
527
+ [promise fulfillWithObject: obj];
528
+ },
529
+ ^(NSError *error) {
530
+ [promise rejectWithError: error];
531
+ });
532
+ return promise;
533
+ }
534
+
523
535
-(void )fulfillWithObject : (id )obj
524
536
{
525
537
if ([obj isKindOfClass: [BAPromise class ]]) {
Original file line number Diff line number Diff line change
1
+ //
2
+ // Use this file to import your target's public headers that you would like to expose to Swift.
3
+ //
4
+
Original file line number Diff line number Diff line change 1
1
xcodeproj 'BAPromise'
2
+ use_frameworks!
2
3
3
4
target 'iOS' do
4
- platform :ios , '8.0'
5
- target 'iOSTests' do
6
- pod "OCMock"
7
- end
5
+ platform :ios , '8.0'
6
+ pod "BAPromise" , :path => "."
7
+ target 'iOSTests' do
8
+ pod "OCMock"
9
+ end
8
10
end
9
11
10
12
target 'OS X' do
You can’t perform that action at this time.
0 commit comments