├── .gitignore
├── Example
└── BFTaskPromiseExample
│ ├── BFTaskPromiseExample
│ ├── en.lproj
│ │ └── InfoPlist.strings
│ ├── BFTaskPromiseExample-Prefix.pch
│ ├── Images.xcassets
│ │ ├── AppIcon.appiconset
│ │ │ └── Contents.json
│ │ └── LaunchImage.launchimage
│ │ │ └── Contents.json
│ ├── BFTaskPromiseExample-Info.plist
│ ├── SampleViewController.h
│ ├── AppDelegate.h
│ ├── main.m
│ ├── SampleViewController.m
│ └── AppDelegate.m
│ ├── BFTaskPromiseExampleTests
│ ├── en.lproj
│ │ └── InfoPlist.strings
│ ├── BFTaskPromiseExampleTests-Info.plist
│ ├── XCTestExpectation+Xcode5
│ │ ├── LICENSE
│ │ ├── XCTestExpectation+OHRetroCompat.h
│ │ └── XCTestExpectation+OHRetroCompat.m
│ ├── BFTaskPromiseCppTests.mm
│ └── BFTaskPromiseExampleTests.m
│ ├── Gemfile
│ ├── BFTaskPromiseExample.xcworkspace
│ ├── contents.xcworkspacedata
│ └── xcshareddata
│ │ └── IDEWorkspaceChecks.plist
│ ├── BFTaskPromiseExample.xcodeproj
│ ├── project.xcworkspace
│ │ └── contents.xcworkspacedata
│ ├── xcshareddata
│ │ └── xcschemes
│ │ │ └── BFTaskPromiseExample.xcscheme
│ └── project.pbxproj
│ ├── Podfile
│ ├── Podfile.lock
│ ├── Rakefile
│ └── Gemfile.lock
├── .travis.yml
├── LICENSE
├── BFTaskPromise.podspec
├── Classes
├── BFTask+PromiseLike.h
└── BFTask+PromiseLike.m
└── Readme.md
/.gitignore:
--------------------------------------------------------------------------------
1 | *.xccheckout
2 | xcuserdata/
3 | Pods/
4 | build/
5 | vendor/
6 | .bundle/
7 |
--------------------------------------------------------------------------------
/Example/BFTaskPromiseExample/BFTaskPromiseExample/en.lproj/InfoPlist.strings:
--------------------------------------------------------------------------------
1 | /* Localized versions of Info.plist keys */
2 |
3 |
--------------------------------------------------------------------------------
/Example/BFTaskPromiseExample/BFTaskPromiseExampleTests/en.lproj/InfoPlist.strings:
--------------------------------------------------------------------------------
1 | /* Localized versions of Info.plist keys */
2 |
3 |
--------------------------------------------------------------------------------
/Example/BFTaskPromiseExample/Gemfile:
--------------------------------------------------------------------------------
1 | source 'https://rubygems.org'
2 |
3 | gem 'rake'
4 | gem 'cocoapods'
5 | gem 'xcpretty'
6 | gem 'xcjobs'
7 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: objective-c
2 | osx_image: xcode9.4
3 | install:
4 | - cd Example/BFTaskPromiseExample
5 | - bundle install --path=vendor/bundle --binstubs=vendor/bin
6 | - pod install
7 | script:
8 | - bundle exec rake test coverage:coveralls
9 |
--------------------------------------------------------------------------------
/Example/BFTaskPromiseExample/BFTaskPromiseExample.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/Example/BFTaskPromiseExample/BFTaskPromiseExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Example/BFTaskPromiseExample/BFTaskPromiseExample.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Example/BFTaskPromiseExample/BFTaskPromiseExample/BFTaskPromiseExample-Prefix.pch:
--------------------------------------------------------------------------------
1 | //
2 | // Prefix header
3 | //
4 | // The contents of this file are implicitly included at the beginning of every source file.
5 | //
6 |
7 | #import
8 |
9 | #ifndef __IPHONE_3_0
10 | #warning "This project uses features only available in iOS SDK 3.0 and later."
11 | #endif
12 |
13 | #ifdef __OBJC__
14 | #import
15 | #import
16 | #endif
17 |
--------------------------------------------------------------------------------
/Example/BFTaskPromiseExample/Podfile:
--------------------------------------------------------------------------------
1 | # Uncomment this line to define a global platform for your project
2 | platform :ios, '9.0'
3 |
4 | pod 'BFTaskPromise', :path => '../../'
5 |
6 | target 'BFTaskPromiseExample' do
7 | # Uncomment this line if you're using Swift or would like to use dynamic frameworks
8 | # use_frameworks!
9 |
10 | # Pods for BFTaskPromiseExample
11 |
12 | target 'BFTaskPromiseExampleTests' do
13 | inherit! :search_paths
14 | # Pods for testing
15 | end
16 |
17 | end
18 |
--------------------------------------------------------------------------------
/Example/BFTaskPromiseExample/BFTaskPromiseExample/Images.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "size" : "29x29",
6 | "scale" : "2x"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "size" : "40x40",
11 | "scale" : "2x"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "size" : "60x60",
16 | "scale" : "2x"
17 | }
18 | ],
19 | "info" : {
20 | "version" : 1,
21 | "author" : "xcode"
22 | }
23 | }
--------------------------------------------------------------------------------
/Example/BFTaskPromiseExample/Podfile.lock:
--------------------------------------------------------------------------------
1 | PODS:
2 | - BFTaskPromise (2.2.0):
3 | - Bolts/Tasks (~> 1.9)
4 | - Bolts/Tasks (1.9.1)
5 |
6 | DEPENDENCIES:
7 | - BFTaskPromise (from `../../`)
8 |
9 | SPEC REPOS:
10 | trunk:
11 | - Bolts
12 |
13 | EXTERNAL SOURCES:
14 | BFTaskPromise:
15 | :path: "../../"
16 |
17 | SPEC CHECKSUMS:
18 | BFTaskPromise: 8dbdebc01a17a0da23419878877e7367d5239053
19 | Bolts: 8c1e8aab2f603387b8b9924f57d1d64f43d3ffdc
20 |
21 | PODFILE CHECKSUM: 766aba33bf5f3c2865bd3deee8d01a724f21c23d
22 |
23 | COCOAPODS: 1.10.1
24 |
--------------------------------------------------------------------------------
/Example/BFTaskPromiseExample/Rakefile:
--------------------------------------------------------------------------------
1 | require 'xcjobs'
2 |
3 | XCJobs::Test.new('test') do |t|
4 | t.build_dir = 'build'
5 | t.workspace = 'BFTaskPromiseExample'
6 | t.scheme = 'BFTaskPromiseExample'
7 | t.configuration = 'Release'
8 | t.add_destination('platform=iOS Simulator,name=iPhone X,OS=11.4')
9 | t.formatter = 'xcpretty -c'
10 | t.coverage = true
11 | end
12 |
13 | XCJobs::Coverage::Coveralls.new() do |t|
14 | t.add_extension('.m')
15 | t.add_exclude('Example/BFTaskPromiseExample/BFTaskPromiseExample')
16 | t.add_exclude('Example/BFTaskPromiseExample/BFTaskPromiseExampleTests')
17 | end
18 |
--------------------------------------------------------------------------------
/Example/BFTaskPromiseExample/BFTaskPromiseExample/Images.xcassets/LaunchImage.launchimage/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "orientation" : "portrait",
5 | "idiom" : "iphone",
6 | "extent" : "full-screen",
7 | "minimum-system-version" : "7.0",
8 | "scale" : "2x"
9 | },
10 | {
11 | "orientation" : "portrait",
12 | "idiom" : "iphone",
13 | "subtype" : "retina4",
14 | "extent" : "full-screen",
15 | "minimum-system-version" : "7.0",
16 | "scale" : "2x"
17 | }
18 | ],
19 | "info" : {
20 | "version" : 1,
21 | "author" : "xcode"
22 | }
23 | }
--------------------------------------------------------------------------------
/Example/BFTaskPromiseExample/BFTaskPromiseExampleTests/BFTaskPromiseExampleTests-Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | ${EXECUTABLE_NAME}
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundlePackageType
14 | BNDL
15 | CFBundleShortVersionString
16 | 1.0
17 | CFBundleSignature
18 | ????
19 | CFBundleVersion
20 | 1
21 |
22 |
23 |
--------------------------------------------------------------------------------
/Example/BFTaskPromiseExample/BFTaskPromiseExampleTests/XCTestExpectation+Xcode5/LICENSE:
--------------------------------------------------------------------------------
1 | - MIT LICENSE -
2 |
3 | Copyright (c) 2012 Olivier Halligon
4 |
5 | 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:
6 |
7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8 |
9 | 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.
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | BFTaskPromise (The MIT License)
2 |
3 |
4 | Copyright (c) 2014-2016 Hironori Ichimiya
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining
7 | a copy of this software and associated documentation files (the
8 | "Software"), to deal in the Software without restriction, including
9 | without limitation the rights to use, copy, modify, merge, publish,
10 | distribute, sublicense, and/or sell copies of the Software, and to
11 | permit persons to whom the Software is furnished to do so, subject to
12 | the following conditions:
13 |
14 | The above copyright notice and this permission notice shall be included
15 | in all copies or substantial portions of the Software.
16 |
17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 |
--------------------------------------------------------------------------------
/BFTaskPromise.podspec:
--------------------------------------------------------------------------------
1 | Pod::Spec.new do |s|
2 | s.name = "BFTaskPromise"
3 | s.version = "2.2.0"
4 | s.summary = "An Objective-C category for BFTask class in Bolts-iOS."
5 |
6 | s.description = <<-DESC
7 | An Objective-C category for BFTask class in Bolts-iOS.
8 |
9 | With this category, you can:
10 |
11 | * chain tasks with dot-notation as JavaScript Promise-like syntax. (no more counting brackets!)
12 | * write a catch block which will be called in error case only.
13 | * write a finally block which will not change the result value unless the block fails.
14 | DESC
15 |
16 | s.homepage = "https://github.com/hironytic/BFTaskPromise"
17 | s.license = { :type => "MIT", :file => "LICENSE" }
18 | s.author = { "Hironori Ichimiya" => "hiron@hironytic.com" }
19 |
20 | s.platform = :ios, "5.0"
21 | s.source = { :git => "https://github.com/hironytic/BFTaskPromise.git", :tag => "v#{s.version}" }
22 | s.source_files = "Classes/*.{h,m}"
23 |
24 | s.requires_arc = true
25 |
26 | s.dependency 'Bolts/Tasks', '~> 1.9'
27 | end
28 |
--------------------------------------------------------------------------------
/Example/BFTaskPromiseExample/BFTaskPromiseExample/BFTaskPromiseExample-Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleDisplayName
8 | ${PRODUCT_NAME}
9 | CFBundleExecutable
10 | ${EXECUTABLE_NAME}
11 | CFBundleIdentifier
12 | $(PRODUCT_BUNDLE_IDENTIFIER)
13 | CFBundleInfoDictionaryVersion
14 | 6.0
15 | CFBundleName
16 | ${PRODUCT_NAME}
17 | CFBundlePackageType
18 | APPL
19 | CFBundleShortVersionString
20 | 1.0
21 | CFBundleSignature
22 | ????
23 | CFBundleVersion
24 | 1.0
25 | LSRequiresIPhoneOS
26 |
27 | UIRequiredDeviceCapabilities
28 |
29 | armv7
30 |
31 | UISupportedInterfaceOrientations
32 |
33 | UIInterfaceOrientationPortrait
34 | UIInterfaceOrientationLandscapeLeft
35 | UIInterfaceOrientationLandscapeRight
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/Example/BFTaskPromiseExample/BFTaskPromiseExample/SampleViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // SampleViewController.h
3 | // BFTaskPromiseExample
4 | //
5 | // Copyright (c) 2015,2016 Hironori Ichimiya
6 | //
7 | // Permission is hereby granted, free of charge, to any person obtaining
8 | // a copy of this software and associated documentation files (the
9 | // "Software"), to deal in the Software without restriction, including
10 | // without limitation the rights to use, copy, modify, merge, publish,
11 | // distribute, sublicense, and/or sell copies of the Software, and to
12 | // permit persons to whom the Software is furnished to do so, subject to
13 | // the following conditions:
14 | // The above copyright notice and this permission notice shall be included
15 | // in all copies or substantial portions of the Software.
16 | //
17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 | // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | //
25 |
26 | #import
27 |
28 | @interface SampleViewController : UIViewController
29 |
30 | @end
31 |
--------------------------------------------------------------------------------
/Example/BFTaskPromiseExample/BFTaskPromiseExample/AppDelegate.h:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.h
3 | // BFTaskPromiseExample
4 | //
5 | // Copyright (c) 2014-2016 Hironori Ichimiya
6 | //
7 | // Permission is hereby granted, free of charge, to any person obtaining
8 | // a copy of this software and associated documentation files (the
9 | // "Software"), to deal in the Software without restriction, including
10 | // without limitation the rights to use, copy, modify, merge, publish,
11 | // distribute, sublicense, and/or sell copies of the Software, and to
12 | // permit persons to whom the Software is furnished to do so, subject to
13 | // the following conditions:
14 | // The above copyright notice and this permission notice shall be included
15 | // in all copies or substantial portions of the Software.
16 | //
17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 | // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | //
25 |
26 | #import
27 |
28 | @interface AppDelegate : UIResponder
29 |
30 | @property (strong, nonatomic) UIWindow *window;
31 |
32 | @end
33 |
--------------------------------------------------------------------------------
/Example/BFTaskPromiseExample/BFTaskPromiseExample/main.m:
--------------------------------------------------------------------------------
1 | //
2 | // main.m
3 | // BFTaskPromiseExample
4 | //
5 | // Copyright (c) 2014-2016 Hironori Ichimiya
6 | //
7 | // Permission is hereby granted, free of charge, to any person obtaining
8 | // a copy of this software and associated documentation files (the
9 | // "Software"), to deal in the Software without restriction, including
10 | // without limitation the rights to use, copy, modify, merge, publish,
11 | // distribute, sublicense, and/or sell copies of the Software, and to
12 | // permit persons to whom the Software is furnished to do so, subject to
13 | // the following conditions:
14 | // The above copyright notice and this permission notice shall be included
15 | // in all copies or substantial portions of the Software.
16 | //
17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 | // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | //
25 |
26 | #import
27 |
28 | #import "AppDelegate.h"
29 |
30 | int main(int argc, char * argv[])
31 | {
32 | @autoreleasepool {
33 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/Example/BFTaskPromiseExample/BFTaskPromiseExampleTests/BFTaskPromiseCppTests.mm:
--------------------------------------------------------------------------------
1 | //
2 | // BFTaskPromiseCppTests.mm
3 | // BFTaskPromiseExampleTests
4 | //
5 | // Copyright (c) 2015,2016 Hironori Ichimiya
6 | //
7 | // Permission is hereby granted, free of charge, to any person obtaining
8 | // a copy of this software and associated documentation files (the
9 | // "Software"), to deal in the Software without restriction, including
10 | // without limitation the rights to use, copy, modify, merge, publish,
11 | // distribute, sublicense, and/or sell copies of the Software, and to
12 | // permit persons to whom the Software is furnished to do so, subject to
13 | // the following conditions:
14 | // The above copyright notice and this permission notice shall be included
15 | // in all copies or substantial portions of the Software.
16 | //
17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 | // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | //
25 |
26 | #import
27 | #import
28 | #import "BFTask+PromiseLike.h"
29 |
30 | #define MY_ERROR_DOMAIN @"MyErrorDomain"
31 |
32 | @interface BFTaskPromiseCppTests : XCTestCase
33 |
34 | @end
35 |
36 | @implementation BFTaskPromiseCppTests
37 |
38 | - (void)setUp {
39 | [super setUp];
40 | // Put setup code here. This method is called before the invocation of each test method in the class.
41 | }
42 |
43 | - (void)tearDown {
44 | // Put teardown code here. This method is called after the invocation of each test method in the class.
45 | [super tearDown];
46 | }
47 |
48 | - (void)testCatchWithShouldRunWhenError {
49 | XCTestExpectation *expectation = [self expectationWithDescription:@"finish task"];
50 | [BFTask taskWithError:[NSError errorWithDomain:MY_ERROR_DOMAIN code:0 userInfo:nil]].catchWith( ^id (NSError *error) {
51 | XCTAssertEqualObjects([error domain], MY_ERROR_DOMAIN, "error should be passed.");
52 | [expectation fulfill];
53 | return nil;
54 | });
55 | [self waitForExpectationsWithTimeout:5.0 handler:nil];
56 | }
57 |
58 | @end
59 |
--------------------------------------------------------------------------------
/Classes/BFTask+PromiseLike.h:
--------------------------------------------------------------------------------
1 | //
2 | // BFTask+PromiseLike.h
3 | // BFTaskPromise
4 | //
5 | // Copyright (c) 2014-2016 Hironori Ichimiya
6 | //
7 | // Permission is hereby granted, free of charge, to any person obtaining
8 | // a copy of this software and associated documentation files (the
9 | // "Software"), to deal in the Software without restriction, including
10 | // without limitation the rights to use, copy, modify, merge, publish,
11 | // distribute, sublicense, and/or sell copies of the Software, and to
12 | // permit persons to whom the Software is furnished to do so, subject to
13 | // the following conditions:
14 | // The above copyright notice and this permission notice shall be included
15 | // in all copies or substantial portions of the Software.
16 | //
17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 | // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | //
25 |
26 | #import
27 |
28 | extern NSString *const BFPTaskErrorDomain;
29 | extern NSString *const BFPUnderlyingExceptionKey;
30 | typedef NS_ENUM(NSInteger, BFPTaskErrorCode) {
31 | BFPTaskErrorException = 1,
32 | };
33 |
34 | typedef id (^BFPSuccessResultBlock)(id result);
35 | typedef id (^BFPErrorResultBlock)(NSError *error);
36 | typedef BFTask *(^BFPFinallyBlock)(void);
37 |
38 | @interface BFTask (PromiseLike)
39 |
40 | - (BFTask *)thenWithExecutor:(BFExecutor *)executor withBlock:(BFPSuccessResultBlock)block;
41 | - (BFTask *)catchWithExecutor:(BFExecutor *)executor withBlock:(BFPErrorResultBlock)block;
42 | - (BFTask *)finallyWithExecutor:(BFExecutor *)executor withBlock:(BFPFinallyBlock)block;
43 |
44 |
45 | - (BFTask *(^)(BFContinuationBlock))continueWith;
46 | - (BFTask *(^)(BFPSuccessResultBlock))then;
47 | - (BFTask *(^)(BFPErrorResultBlock))catch;
48 | - (BFTask *(^)(BFPErrorResultBlock))catchWith; // for Objective-C++
49 | - (BFTask *(^)(BFPFinallyBlock))finally;
50 |
51 | - (BFTask *(^)(BFExecutor *, BFContinuationBlock))continueOn;
52 | - (BFTask *(^)(BFExecutor *, BFPSuccessResultBlock))thenOn;
53 | - (BFTask *(^)(BFExecutor *, BFPErrorResultBlock))catchOn;
54 | - (BFTask *(^)(BFExecutor *, BFPFinallyBlock))finallyOn;
55 |
56 | - (BFTask *(^)(BFContinuationBlock))continueOnMain;
57 | - (BFTask *(^)(BFPSuccessResultBlock))thenOnMain;
58 | - (BFTask *(^)(BFPErrorResultBlock))catchOnMain;
59 | - (BFTask *(^)(BFPFinallyBlock))finallyOnMain;
60 |
61 | @end
62 |
--------------------------------------------------------------------------------
/Example/BFTaskPromiseExample/Gemfile.lock:
--------------------------------------------------------------------------------
1 | GEM
2 | remote: https://rubygems.org/
3 | specs:
4 | CFPropertyList (3.0.3)
5 | activesupport (5.2.6)
6 | concurrent-ruby (~> 1.0, >= 1.0.2)
7 | i18n (>= 0.7, < 2)
8 | minitest (~> 5.1)
9 | tzinfo (~> 1.1)
10 | addressable (2.7.0)
11 | public_suffix (>= 2.0.2, < 5.0)
12 | algoliasearch (1.27.5)
13 | httpclient (~> 2.8, >= 2.8.3)
14 | json (>= 1.5.1)
15 | atomos (0.1.3)
16 | claide (1.0.3)
17 | cocoapods (1.10.1)
18 | addressable (~> 2.6)
19 | claide (>= 1.0.2, < 2.0)
20 | cocoapods-core (= 1.10.1)
21 | cocoapods-deintegrate (>= 1.0.3, < 2.0)
22 | cocoapods-downloader (>= 1.4.0, < 2.0)
23 | cocoapods-plugins (>= 1.0.0, < 2.0)
24 | cocoapods-search (>= 1.0.0, < 2.0)
25 | cocoapods-trunk (>= 1.4.0, < 2.0)
26 | cocoapods-try (>= 1.1.0, < 2.0)
27 | colored2 (~> 3.1)
28 | escape (~> 0.0.4)
29 | fourflusher (>= 2.3.0, < 3.0)
30 | gh_inspector (~> 1.0)
31 | molinillo (~> 0.6.6)
32 | nap (~> 1.0)
33 | ruby-macho (~> 1.4)
34 | xcodeproj (>= 1.19.0, < 2.0)
35 | cocoapods-core (1.10.1)
36 | activesupport (> 5.0, < 6)
37 | addressable (~> 2.6)
38 | algoliasearch (~> 1.0)
39 | concurrent-ruby (~> 1.1)
40 | fuzzy_match (~> 2.0.4)
41 | nap (~> 1.0)
42 | netrc (~> 0.11)
43 | public_suffix
44 | typhoeus (~> 1.0)
45 | cocoapods-deintegrate (1.0.4)
46 | cocoapods-downloader (1.4.0)
47 | cocoapods-plugins (1.0.0)
48 | nap
49 | cocoapods-search (1.0.0)
50 | cocoapods-trunk (1.5.0)
51 | nap (>= 0.8, < 2.0)
52 | netrc (~> 0.11)
53 | cocoapods-try (1.2.0)
54 | colored2 (3.1.2)
55 | concurrent-ruby (1.1.8)
56 | escape (0.0.4)
57 | ethon (0.14.0)
58 | ffi (>= 1.15.0)
59 | ffi (1.15.0)
60 | fourflusher (2.3.1)
61 | fuzzy_match (2.0.4)
62 | gh_inspector (1.1.3)
63 | httpclient (2.8.3)
64 | i18n (1.8.10)
65 | concurrent-ruby (~> 1.0)
66 | json (2.5.1)
67 | minitest (5.14.4)
68 | molinillo (0.6.6)
69 | nanaimo (0.3.0)
70 | nap (1.1.0)
71 | netrc (0.11.0)
72 | public_suffix (4.0.6)
73 | rake (13.0.3)
74 | rouge (2.0.7)
75 | ruby-macho (1.4.0)
76 | thread_safe (0.3.6)
77 | typhoeus (1.4.0)
78 | ethon (>= 0.9.0)
79 | tzinfo (1.2.9)
80 | thread_safe (~> 0.1)
81 | xcjobs (0.10.0)
82 | xcodeproj (1.19.0)
83 | CFPropertyList (>= 2.3.3, < 4.0)
84 | atomos (~> 0.1.3)
85 | claide (>= 1.0.2, < 2.0)
86 | colored2 (~> 3.1)
87 | nanaimo (~> 0.3.0)
88 | xcpretty (0.3.0)
89 | rouge (~> 2.0.7)
90 |
91 | PLATFORMS
92 | ruby
93 |
94 | DEPENDENCIES
95 | cocoapods
96 | rake
97 | xcjobs
98 | xcpretty
99 |
100 | BUNDLED WITH
101 | 1.17.2
102 |
--------------------------------------------------------------------------------
/Example/BFTaskPromiseExample/BFTaskPromiseExample/SampleViewController.m:
--------------------------------------------------------------------------------
1 | //
2 | // SampleViewController.m
3 | // BFTaskPromiseExample
4 | //
5 | // Copyright (c) 2015,2016 Hironori Ichimiya
6 | //
7 | // Permission is hereby granted, free of charge, to any person obtaining
8 | // a copy of this software and associated documentation files (the
9 | // "Software"), to deal in the Software without restriction, including
10 | // without limitation the rights to use, copy, modify, merge, publish,
11 | // distribute, sublicense, and/or sell copies of the Software, and to
12 | // permit persons to whom the Software is furnished to do so, subject to
13 | // the following conditions:
14 | // The above copyright notice and this permission notice shall be included
15 | // in all copies or substantial portions of the Software.
16 | //
17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 | // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | //
25 |
26 | #import "SampleViewController.h"
27 | #import "Bolts.h"
28 | #import "BFTask+PromiseLike.h"
29 |
30 | @interface SampleViewController ()
31 |
32 | @end
33 |
34 | @implementation SampleViewController
35 |
36 | - (void)viewDidLoad {
37 | [super viewDidLoad];
38 |
39 | UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
40 | [button setTitle:@"Button" forState:UIControlStateNormal];
41 | [button setFrame:CGRectMake(8, 32, 120, 32)];
42 | [button addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
43 | [self.view addSubview:button];
44 | }
45 |
46 | - (void)buttonTapped:(id)sender {
47 | [self countUsersAsync].continueWith(^id (BFTask *task) {
48 | // this block is called regardless of the success or failure
49 | NSNumber *count = task.result;
50 | if ([count intValue] <= 0) {
51 | return [BFTask taskWithError:[NSError errorWithDomain:@"MyDomain"
52 | code:-1
53 | userInfo:nil]];
54 | } else {
55 | return [self makeTotalUserStringAsync:count];
56 | }
57 | }).then(^id (NSString *totalUserString) {
58 | // this block is skipped when the previous task is failed.
59 | [self showMessage:totalUserString];
60 | return nil;
61 | }).catch(^id (NSError *error) {
62 | // this block is called in error case.
63 | [self showErrorMessage:error];
64 | return nil;
65 | }).finally(^BFTask * (){
66 | [self updateList];
67 | return nil;
68 | });
69 | }
70 |
71 | - (BFTask *)countUsersAsync {
72 | return [BFTask taskWithResult:@10];
73 | }
74 |
75 | - (BFTask *)makeTotalUserStringAsync:(NSNumber *)count {
76 | return [BFTask taskWithResult:[NSString stringWithFormat:@"Total User: %@", count]];
77 | }
78 |
79 | - (void)showMessage:(NSString *)string {
80 | NSLog(@"message: %@", string);
81 | }
82 |
83 | - (void)showErrorMessage:(NSError *)error {
84 | NSLog(@"error: %@", error);
85 | }
86 |
87 | - (void)updateList {
88 | NSLog(@"list updated");
89 | }
90 |
91 | @end
92 |
--------------------------------------------------------------------------------
/Example/BFTaskPromiseExample/BFTaskPromiseExample/AppDelegate.m:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.m
3 | // BFTaskPromiseExample
4 | //
5 | // Copyright (c) 2014-2016 Hironori Ichimiya
6 | //
7 | // Permission is hereby granted, free of charge, to any person obtaining
8 | // a copy of this software and associated documentation files (the
9 | // "Software"), to deal in the Software without restriction, including
10 | // without limitation the rights to use, copy, modify, merge, publish,
11 | // distribute, sublicense, and/or sell copies of the Software, and to
12 | // permit persons to whom the Software is furnished to do so, subject to
13 | // the following conditions:
14 | // The above copyright notice and this permission notice shall be included
15 | // in all copies or substantial portions of the Software.
16 | //
17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 | // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | //
25 |
26 | #import "AppDelegate.h"
27 | #import "SampleViewController.h"
28 |
29 | @implementation AppDelegate
30 |
31 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
32 | {
33 | self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
34 | // Override point for customization after application launch.
35 | self.window.rootViewController = [[SampleViewController alloc] init];
36 | self.window.backgroundColor = [UIColor whiteColor];
37 | [self.window makeKeyAndVisible];
38 | return YES;
39 | }
40 |
41 | - (void)applicationWillResignActive:(UIApplication *)application
42 | {
43 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
44 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
45 | }
46 |
47 | - (void)applicationDidEnterBackground:(UIApplication *)application
48 | {
49 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
50 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
51 | }
52 |
53 | - (void)applicationWillEnterForeground:(UIApplication *)application
54 | {
55 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
56 | }
57 |
58 | - (void)applicationDidBecomeActive:(UIApplication *)application
59 | {
60 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
61 | }
62 |
63 | - (void)applicationWillTerminate:(UIApplication *)application
64 | {
65 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
66 | }
67 |
68 | @end
69 |
--------------------------------------------------------------------------------
/Readme.md:
--------------------------------------------------------------------------------
1 | BFTaskPromise
2 | =============
3 | [](https://travis-ci.org/hironytic/BFTaskPromise)
4 | [](https://coveralls.io/r/hironytic/BFTaskPromise?branch=master)
5 |
6 | ## About
7 |
8 | An Objective-C category for BFTask class in [Bolts-ObjC](https://github.com/BoltsFramework/Bolts-ObjC).
9 |
10 | With this category, you can:
11 |
12 | * chain tasks with dot-notation as JavaScript Promise-like syntax. (no more counting brackets!)
13 | * write a catch block which will be called in error case only.
14 | * write a finally block which won't change the result value unless the block fails.
15 |
16 | ### Example
17 |
18 | ```objc
19 | [self countUsersAsync].continueWith(^id (BFTask *task) {
20 | // this block is called regardless of the success or failure
21 | NSNumber *count = task.result;
22 | if ([count intValue] <= 0) {
23 | return [BFTask taskWithError:[NSError errorWithDomain:@"MyDomain"
24 | code:-1
25 | userInfo:nil]];
26 | } else {
27 | return [self makeTotalUserStringAsync:count];
28 | }
29 | }).then(^id (NSString *totalUserString) {
30 | // this block is skipped when the previous task is failed.
31 | [self showMessage:totalUserString];
32 | return nil;
33 | }).catch(^id (NSError *error) {
34 | // this block is called in error case.
35 | [self showErrorMessage:error];
36 | return nil;
37 | }).finally(^BFTask * (){
38 | [self updateList];
39 | return nil;
40 | });
41 | ```
42 |
43 | ### Executors
44 |
45 | If you want to specify the executor, use `continueOn`, `thenOn`, `catchOn` and `finallyOn`.
46 | You can also use `continueOnMain`, `thenOnMain`, `catchOnMain` and `finallyOnMain`, they use `mainThreadExecutor`.
47 |
48 | ```objc
49 | [User findAllAsync].catchOn([BFExecutor mainThreadExecutor], ^id (NSError *error) {
50 | [self showAlert:error];
51 | });
52 |
53 | // same as above
54 | [User findAllAsync].catchOnMain(^id (NSError *error) {
55 | [self showAlert:error];
56 | });
57 | ```
58 |
59 | ### Not a Promise
60 |
61 | To be exact, Bolts' task is not a Promise. So this is not a Promise too.
62 | The purpose of this project is to make task-chains much readable.
63 |
64 | ### Hate Dot-Notation?
65 |
66 | If you don't think dot-notation is preferable but do want `catch` and/or `finally`, you can still use `catchWithExecutor:withBlock:` and `finallyWithExecutor:withBlock:`. They are normal methods.
67 |
68 | To tell the truth, I hate dot-notation for methods basically. I want to use it for only properties. I prefer to use bracket-notation for usual methods.
69 | But the task-chaining is a special case for me. It's unusual. I feel the task-chaining is not a nested method call, but a flow control.
70 |
71 |
72 | ## Install
73 |
74 | ### Using CocoaPods
75 |
76 | Write the following line to your Podfile:
77 |
78 | ```
79 | pod 'BFTaskPromise', '~> 2.0'
80 | ```
81 | ### Manually
82 |
83 | Add `BFTask+PromiseLike.h` and `BFTask+PromiseLike.m` in `Classes` folder to your project.
84 |
85 |
86 | ## Migrating from 1.x to 2.0
87 |
88 | The parameter of the block passed to `then`/`catch` is changed in 2.0.
89 | A `then`-block takes a result value and a `catch`-block takes an error value.
90 |
91 | In prior to 2.0, the block parameter of both `then` and `catch` was a `BFTask` value.
92 | So if you have a code for 1.X like:
93 |
94 | ```objc
95 | [foo loadAsync].then(^id (BFTask *task) {
96 | bar.title = (NSString *)task.result;
97 | }
98 | ```
99 |
100 | you must rewrite it to:
101 |
102 | ```objc
103 | [foo loadAsync].then(^id (NSString *result) {
104 | bar.title = result;
105 | }
106 | ```
107 |
108 |
109 | ## License
110 |
111 | The MIT License.
112 |
--------------------------------------------------------------------------------
/Example/BFTaskPromiseExample/BFTaskPromiseExample.xcodeproj/xcshareddata/xcschemes/BFTaskPromiseExample.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
33 |
39 |
40 |
41 |
42 |
43 |
49 |
50 |
51 |
52 |
53 |
54 |
64 |
66 |
72 |
73 |
74 |
75 |
76 |
77 |
83 |
85 |
91 |
92 |
93 |
94 |
96 |
97 |
100 |
101 |
102 |
--------------------------------------------------------------------------------
/Example/BFTaskPromiseExample/BFTaskPromiseExampleTests/XCTestExpectation+Xcode5/XCTestExpectation+OHRetroCompat.h:
--------------------------------------------------------------------------------
1 | /***********************************************************************************
2 | *
3 | * Copyright (c) 2012 Olivier Halligon
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy
6 | * of this software and associated documentation files (the "Software"), to deal
7 | * in the Software without restriction, including without limitation the rights
8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | * copies of the Software, and to permit persons to whom the Software is
10 | * furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in
13 | * all copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | * THE SOFTWARE.
22 | *
23 | ***********************************************************************************/
24 |
25 |
26 | /*----------------------------------------------------------------------------------
27 | * NOTE
28 | *
29 | * This file mirror the new XCTestExpectation API from Xcode 6's XCTest framework
30 | * (at least part of it) so that we can use the same API in older Xcode versions
31 | ----------------------------------------------------------------------------------*/
32 |
33 |
34 | #if (defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED < 80000) \
35 | || (defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && __MAC_OS_X_VERSION_MAX_ALLOWED < 101000)
36 |
37 | #define XCTestExpectation_OHRetroCompat_BETTER_FAILURE_LOCATIONS 1
38 |
39 | #import
40 |
41 | ///////////////////////////////////////////////////////////////////////////////////
42 |
43 | @interface XCTestExpectation : NSObject
44 |
45 | /*!
46 | * @method -fulfill
47 | *
48 | * @discussion
49 | * Call -fulfill to mark an expectation as having been met. It's an error to call
50 | * -fulfill on an expectation that has already been fulfilled or when the test case
51 | * that vended the expectation has already completed.
52 | */
53 | -(void)fulfill;
54 |
55 | @end
56 |
57 | /////////////////////////////////////////////////////////
58 |
59 | @interface XCTestCaseAsync : XCTestCase
60 |
61 | /*!
62 | * @method +expectationWithDescription:
63 | *
64 | * @param description
65 | * This string will be displayed in the test log to help diagnose failures.
66 | *
67 | * @discussion
68 | * Creates and returns an expectation associated with the test case.
69 | */
70 | - (XCTestExpectation *)expectationWithDescription:(NSString *)description;
71 |
72 | /*!
73 | * @typedef XCWaitCompletionHandler
74 | * A block to be invoked when a call to -waitForExpectationsWithTimeout:handler: times out or has
75 | * had all associated expectations fulfilled.
76 | *
77 | * @param error
78 | * If the wait timed out or a failure was raised while waiting, the error's code
79 | * will specify the type of failure. Otherwise error will be nil.
80 | */
81 | typedef void (^XCWaitCompletionHandler)(NSError *error);
82 |
83 | /*!
84 | * @method -waitForExpectationsWithTimeout:handler:
85 | *
86 | * @param timeout
87 | * The amount of time within which all expectations must be fulfilled.
88 | *
89 | * @param handlerOrNil
90 | * If provided, the handler will be invoked both on timeout or fulfillment of all
91 | * expectations. Timeout is always treated as a test failure.
92 | *
93 | * @discussion
94 | * -waitForExpectationsWithTimeout:handler: creates a point of synchronization in the flow of a
95 | * test. Only one -waitForExpectationsWithTimeout:handler: can be active at any given time, but
96 | * multiple discrete sequences of { expectations -> wait } can be chained together.
97 | *
98 | * -waitForExpectationsWithTimeout:handler: runs the run loop while handling events until all expectations
99 | * are fulfilled or the timeout is reached. Clients should not manipulate the run
100 | * loop while using this API.
101 | */
102 | - (void)waitForExpectationsWithTimeout:(NSTimeInterval)timeout handler:(XCWaitCompletionHandler)handlerOrNil;
103 |
104 | #if XCTestExpectation_OHRetroCompat_BETTER_FAILURE_LOCATIONS
105 | - (XCTestExpectation *)__file:(const char*)_ line:(NSUInteger)_ expectationWithDescription:(NSString *)description;
106 | - (void)__file:(const char*)_ line:(NSUInteger)_ waitForExpectationsWithTimeout:(NSTimeInterval)timeout handler:(XCWaitCompletionHandler)handlerOrNil;
107 | #define expectationWithDescription __file:__FILE__ line:__LINE__ expectationWithDescription
108 | #define waitForExpectationsWithTimeout __file:__FILE__ line:__LINE__ waitForExpectationsWithTimeout
109 | #endif
110 |
111 | @end
112 |
113 | #define XCTestCase XCTestCaseAsync
114 |
115 | #endif
116 |
--------------------------------------------------------------------------------
/Classes/BFTask+PromiseLike.m:
--------------------------------------------------------------------------------
1 | //
2 | // BFTask+PromiseLike.m
3 | // BFTaskPromise
4 | //
5 | // Copyright (c) 2014-2016 Hironori Ichimiya
6 | //
7 | // Permission is hereby granted, free of charge, to any person obtaining
8 | // a copy of this software and associated documentation files (the
9 | // "Software"), to deal in the Software without restriction, including
10 | // without limitation the rights to use, copy, modify, merge, publish,
11 | // distribute, sublicense, and/or sell copies of the Software, and to
12 | // permit persons to whom the Software is furnished to do so, subject to
13 | // the following conditions:
14 | // The above copyright notice and this permission notice shall be included
15 | // in all copies or substantial portions of the Software.
16 | //
17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 | // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | //
25 |
26 | #import
27 | #import "BFTask+PromiseLike.h"
28 |
29 | @implementation BFTask (PromiseLike)
30 |
31 | - (BFTask *)thenWithExecutor:(BFExecutor *)executor withBlock:(BFPSuccessResultBlock)block {
32 | return [self continueWithExecutor:executor withBlock: ^id (BFTask *task) {
33 | if ([task error] != nil || [task isCancelled]) {
34 | return task;
35 | } else {
36 | return block(task.result);
37 | }
38 | }];
39 | }
40 |
41 | - (BFTask *)catchWithExecutor:(BFExecutor *)executor withBlock:(BFPErrorResultBlock)block {
42 | return [self continueWithExecutor:executor withBlock: ^id (BFTask *task) {
43 | if (task.error) {
44 | return block(task.error);
45 | } else {
46 | return task;
47 | }
48 | }];
49 | }
50 |
51 | - (BFTask *)finallyWithExecutor:(BFExecutor *)executor withBlock:(BFPFinallyBlock)block {
52 | return [self continueWithExecutor:executor withBlock: ^id (BFTask *task) {
53 | BFTask *resultTask = block();
54 | if (resultTask != nil) {
55 | return resultTask.then( ^id (BFTask *task2) {
56 | return task;
57 | });
58 | } else {
59 | return task;
60 | }
61 | }];
62 | }
63 |
64 | - (BFTask *(^)(BFContinuationBlock))continueWith {
65 | return ^BFTask *(BFContinuationBlock block) {
66 | return [self continueWithExecutor:[BFExecutor defaultExecutor] withBlock:block];
67 | };
68 | }
69 |
70 | - (BFTask *(^)(BFPSuccessResultBlock))then {
71 | return ^BFTask *(BFPSuccessResultBlock block) {
72 | return [self thenWithExecutor:[BFExecutor defaultExecutor] withBlock:block];
73 | };
74 | }
75 |
76 | - (BFTask *(^)(BFPErrorResultBlock))catch {
77 | return ^BFTask *(BFPErrorResultBlock block) {
78 | return [self catchWithExecutor:[BFExecutor defaultExecutor] withBlock:block];
79 | };
80 | }
81 |
82 | - (BFTask *(^)(BFPErrorResultBlock))catchWith {
83 | return [self catch];
84 | }
85 |
86 | - (BFTask *(^)(BFPFinallyBlock))finally {
87 | return ^BFTask *(BFPFinallyBlock block) {
88 | return [self finallyWithExecutor:[BFExecutor defaultExecutor] withBlock:block];
89 | };
90 | }
91 |
92 | - (BFTask *(^)(BFExecutor *, BFContinuationBlock))continueOn {
93 | return ^BFTask *(BFExecutor *executor, BFContinuationBlock block) {
94 | return [self continueWithExecutor:executor withBlock:block];
95 | };
96 | }
97 |
98 | - (BFTask *(^)(BFExecutor *, BFPSuccessResultBlock))thenOn {
99 | return ^BFTask *(BFExecutor *executor, BFPSuccessResultBlock block) {
100 | return [self thenWithExecutor:executor withBlock:block];
101 | };
102 | }
103 |
104 | - (BFTask *(^)(BFExecutor *, BFPErrorResultBlock))catchOn {
105 | return ^BFTask *(BFExecutor *executor, BFPErrorResultBlock block) {
106 | return [self catchWithExecutor:executor withBlock:block];
107 | };
108 | }
109 |
110 | - (BFTask *(^)(BFExecutor *, BFPFinallyBlock))finallyOn {
111 | return ^BFTask *(BFExecutor *executor, BFPFinallyBlock block) {
112 | return [self finallyWithExecutor:executor withBlock:block];
113 | };
114 | }
115 |
116 | - (BFTask *(^)(BFContinuationBlock))continueOnMain {
117 | return ^BFTask *(BFContinuationBlock block) {
118 | return [self continueWithExecutor:[BFExecutor mainThreadExecutor] withBlock:block];
119 | };
120 | }
121 |
122 | - (BFTask *(^)(BFPSuccessResultBlock))thenOnMain {
123 | return ^BFTask *(BFPSuccessResultBlock block) {
124 | return [self thenWithExecutor:[BFExecutor mainThreadExecutor] withBlock:block];
125 | };
126 | }
127 |
128 | - (BFTask *(^)(BFPErrorResultBlock))catchOnMain {
129 | return ^BFTask *(BFPErrorResultBlock block) {
130 | return [self catchWithExecutor:[BFExecutor mainThreadExecutor] withBlock:block];
131 | };
132 | }
133 |
134 | - (BFTask *(^)(BFPFinallyBlock))finallyOnMain {
135 | return ^BFTask *(BFPFinallyBlock block) {
136 | return [self finallyWithExecutor:[BFExecutor mainThreadExecutor] withBlock:block];
137 | };
138 | }
139 |
140 | @end
141 |
--------------------------------------------------------------------------------
/Example/BFTaskPromiseExample/BFTaskPromiseExampleTests/XCTestExpectation+Xcode5/XCTestExpectation+OHRetroCompat.m:
--------------------------------------------------------------------------------
1 | /***********************************************************************************
2 | *
3 | * Copyright (c) 2012 Olivier Halligon
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy
6 | * of this software and associated documentation files (the "Software"), to deal
7 | * in the Software without restriction, including without limitation the rights
8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | * copies of the Software, and to permit persons to whom the Software is
10 | * furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in
13 | * all copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | * THE SOFTWARE.
22 | *
23 | ***********************************************************************************/
24 |
25 |
26 | /*----------------------------------------------------------------------------------
27 | * NOTE
28 | *
29 | * This file mirror the new XCTestExpectation API from Xcode 6's XCTest framework
30 | * (at least part of it) so that we can use the same API in older Xcode versions
31 | ----------------------------------------------------------------------------------*/
32 |
33 |
34 | #if (defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED < 80000) \
35 | || (defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && __MAC_OS_X_VERSION_MAX_ALLOWED < 101000)
36 |
37 |
38 | #import "XCTestExpectation+OHRetroCompat.h"
39 | #import
40 |
41 | #import
42 |
43 | static NSTimeInterval const kRunLoopSamplingInterval = 0.01;
44 |
45 |
46 | /////////////////////////////////////////////////////////
47 |
48 | @interface XCTestExpectation()
49 | @property(strong) NSString* descritionString;
50 | @property(weak) XCTestCase* associatedTestCase;
51 | @property(readonly) BOOL fulfilled;
52 | #if XCTestExpectation_OHRetroCompat_BETTER_FAILURE_LOCATIONS
53 | @property(assign) const char* sourceFile;
54 | @property(assign) NSUInteger sourceLine;
55 | #endif
56 | @end
57 |
58 | @interface XCTestCaseAsync()
59 | {
60 | NSMutableArray* _expectations;
61 | OSSpinLock _expectationsLock;
62 | int32_t _unfulfilledExpectationsCount;
63 | }
64 | @end
65 |
66 |
67 | /////////////////////////////////////////////////////////
68 |
69 | @implementation XCTestCaseAsync
70 |
71 | #if XCTestExpectation_OHRetroCompat_BETTER_FAILURE_LOCATIONS
72 | #undef expectationWithDescription
73 | #undef waitForExpectationsWithTimeout
74 | #endif
75 |
76 | - (void)setUp
77 | {
78 | [super setUp];
79 |
80 | _expectations = [NSMutableArray new];
81 | _unfulfilledExpectationsCount = 0;
82 | }
83 |
84 | - (void)tearDown
85 | {
86 | [super tearDown];
87 |
88 | if (!OSAtomicCompareAndSwap32(0, 0, &_unfulfilledExpectationsCount)) // if unfulfilledExpectationsCount != 0
89 | {
90 | OSSpinLockLock(&_expectationsLock);
91 | [_expectations filterUsingPredicate:[NSPredicate predicateWithFormat:@"fulfilled == NO"]];
92 | #if XCTestExpectation_OHRetroCompat_BETTER_FAILURE_LOCATIONS
93 | // Locate Xcode test failures at the exact line of each expectation, if we have thie FILE+LINE information
94 | for(XCTestExpectation* expectation in _expectations)
95 | {
96 | _XCTFailureHandler(self, YES, expectation.sourceFile, expectation.sourceLine, _XCTFailureDescription(_XCTAssertion_Fail, 0), @"Failed due to unwaited expectation.");
97 | }
98 | #else
99 | XCTFail(@"Failed due to unwaited expectations: %@.", [_expectations componentsJoinedByString:@", "]);
100 | #endif
101 | [_expectations removeAllObjects];
102 | OSSpinLockUnlock(&_expectationsLock);
103 | }
104 | }
105 |
106 | - (XCTestExpectation *)expectationWithDescription:(NSString *)description
107 | {
108 | XCTestExpectation* expectation = [XCTestExpectation new];
109 | expectation.associatedTestCase = self;
110 | expectation.descritionString = description;
111 |
112 | OSSpinLockLock(&_expectationsLock);
113 | {
114 | [_expectations addObject:expectation];
115 | OSAtomicIncrement32(&_unfulfilledExpectationsCount);
116 | }
117 | OSSpinLockUnlock(&_expectationsLock);
118 |
119 | return expectation;
120 | }
121 |
122 | - (void)decrementUnfulfilledExpectationsCount
123 | {
124 | OSAtomicDecrement32(&_unfulfilledExpectationsCount);
125 | }
126 |
127 | - (void)waitForExpectationsWithTimeout:(NSTimeInterval)timeout handler:(XCWaitCompletionHandler)handlerOrNil
128 | {
129 | [self __file:NULL line:0 waitForExpectationsWithTimeout:timeout handler:handlerOrNil];
130 | }
131 |
132 | - (void)__file:(const char*)_caller_source_file line:(NSUInteger)_caller_source_line waitForExpectationsWithTimeout:(NSTimeInterval)timeout handler:(XCWaitCompletionHandler)handlerOrNil
133 | {
134 | NSDate* timeoutDate = [NSDate dateWithTimeIntervalSinceNow:timeout];
135 |
136 | while ([timeoutDate timeIntervalSinceNow]>0)
137 | {
138 | CFRunLoopRunInMode(kCFRunLoopDefaultMode, kRunLoopSamplingInterval, YES);
139 | if (OSAtomicCompareAndSwap32(0, 0, &_unfulfilledExpectationsCount)) break; // if all expectations fulfilled, break
140 | }
141 |
142 | NSError* error = nil;
143 |
144 | if (!OSAtomicCompareAndSwap32(0, 0, &_unfulfilledExpectationsCount)) // if unfulfilledExpectationsCount != 0
145 | {
146 | error = [NSError errorWithDomain:@"com.apple.XCTestErrorDomain" code:0 userInfo:nil];
147 | }
148 |
149 | if (handlerOrNil)
150 | {
151 | handlerOrNil(error);
152 | }
153 |
154 | if (error)
155 | {
156 | OSSpinLockLock(&_expectationsLock);
157 | [_expectations filterUsingPredicate:[NSPredicate predicateWithFormat:@"fulfilled == NO"]];
158 | NSString* expectationsList = [_expectations componentsJoinedByString:@", "];
159 | [_expectations removeAllObjects];
160 | OSAtomicCompareAndSwap32(_unfulfilledExpectationsCount, 0, &_unfulfilledExpectationsCount); // reset to 0
161 | OSSpinLockUnlock(&_expectationsLock);
162 | #if XCTestExpectation_OHRetroCompat_BETTER_FAILURE_LOCATIONS
163 | _XCTFailureHandler(self, YES, _caller_source_file, _caller_source_line, _XCTFailureDescription(_XCTAssertion_Fail, 0),
164 | @"Asynchronous wait failed: Exceeded timeout of %g seconds, with unfulfilled expectations: %@.",
165 | timeout, expectationsList);
166 | #else
167 | XCTFail(@"Asynchronous wait failed: Exceeded timeout of %g seconds, with unfulfilled expectations: %@.",
168 | timeout, expectationsList);
169 |
170 | #endif
171 | }
172 | }
173 |
174 | #if XCTestExpectation_OHRetroCompat_BETTER_FAILURE_LOCATIONS
175 | - (XCTestExpectation *)__file:(const char*)_caller_source_file line:(NSUInteger)_caller_source_line
176 | expectationWithDescription:(NSString *)description
177 | {
178 | XCTestExpectation* expectation = [self expectationWithDescription:description];
179 | expectation.sourceFile = _caller_source_file;
180 | expectation.sourceLine = _caller_source_line;
181 | return expectation;
182 | }
183 | #endif
184 |
185 | @end
186 |
187 | /////////////////////////////////////////////////////////
188 |
189 | @implementation XCTestExpectation
190 | - (void)fulfill
191 | {
192 | if(!_associatedTestCase)
193 | {
194 | [NSException raise:NSInternalInconsistencyException format:@"The test case associated with this XCTestExpectation %@ has already finished!", self];
195 | }
196 | if (_fulfilled)
197 | {
198 | [NSException raise:NSInternalInconsistencyException format:@"The XCTestExpectation %@ has already been fulfilled!", self];
199 | }
200 | _fulfilled = YES;
201 | [_associatedTestCase decrementUnfulfilledExpectationsCount];
202 | }
203 |
204 | - (NSString*)description
205 | {
206 | return [NSString stringWithFormat:@"\"%@\"", _descritionString];
207 | }
208 | @end
209 |
210 | #endif
211 |
212 |
--------------------------------------------------------------------------------
/Example/BFTaskPromiseExample/BFTaskPromiseExampleTests/BFTaskPromiseExampleTests.m:
--------------------------------------------------------------------------------
1 | //
2 | // BFTaskPromiseExampleTests.m
3 | // BFTaskPromiseExampleTests
4 | //
5 | // Copyright (c) 2014-2018 Hironori Ichimiya
6 | //
7 | // Permission is hereby granted, free of charge, to any person obtaining
8 | // a copy of this software and associated documentation files (the
9 | // "Software"), to deal in the Software without restriction, including
10 | // without limitation the rights to use, copy, modify, merge, publish,
11 | // distribute, sublicense, and/or sell copies of the Software, and to
12 | // permit persons to whom the Software is furnished to do so, subject to
13 | // the following conditions:
14 | // The above copyright notice and this permission notice shall be included
15 | // in all copies or substantial portions of the Software.
16 | //
17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 | // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | //
25 |
26 | #import
27 | #import "XCTestExpectation+OHRetroCompat.h"
28 | #import "BFTask+PromiseLike.h"
29 | #import "BFTaskCompletionSource.h"
30 |
31 | #define MY_ERROR_DOMAIN @"MyErrorDomain"
32 |
33 | @interface BFTaskPromiseExampleTests : XCTestCase
34 |
35 | @end
36 |
37 | @implementation BFTaskPromiseExampleTests
38 |
39 | - (void)setUp {
40 | [super setUp];
41 | // Put setup code here. This method is called before the invocation of each test method in the class.
42 | }
43 |
44 | - (void)tearDown {
45 | // Put teardown code here. This method is called after the invocation of each test method in the class.
46 | [super tearDown];
47 | }
48 |
49 | - (void)testThenShouldRunWhenSucceeded {
50 | XCTestExpectation *expectation = [self expectationWithDescription:@"finish task"];
51 | [BFTask taskWithResult:@30].then( ^id (NSNumber *result) {
52 | XCTAssertEqual([result intValue], 30, "previous value should be passed.");
53 | [expectation fulfill];
54 | return nil;
55 | });
56 | [self waitForExpectationsWithTimeout:5.0 handler:nil];
57 | }
58 |
59 | - (void)testThenShouldNotRunWhenError {
60 | XCTestExpectation *expectation = [self expectationWithDescription:@"finish task"];
61 | __block BOOL ran = NO;
62 | [BFTask taskWithError:[NSError errorWithDomain:MY_ERROR_DOMAIN code:0 userInfo:nil]].then( ^id (BFTask *task) {
63 | ran = YES;
64 | return nil;
65 | }).finally( ^BFTask *() {
66 | [expectation fulfill];
67 | return nil;
68 | });
69 | [self waitForExpectationsWithTimeout:5.0 handler:nil];
70 | XCTAssertFalse(ran, @"then should not ran");
71 | }
72 |
73 | - (void)testThenShouldNotRunWhenCancelled {
74 | XCTestExpectation *expectation = [self expectationWithDescription:@"finish task"];
75 | __block BOOL ran = NO;
76 | [BFTask cancelledTask].then( ^id (BFTask *task) {
77 | ran = YES;
78 | return nil;
79 | }).finally( ^BFTask *() {
80 | [expectation fulfill];
81 | return nil;
82 | });
83 | [self waitForExpectationsWithTimeout:5.0 handler:nil];
84 | XCTAssertFalse(ran, @"then should not ran");
85 | }
86 |
87 | - (void)testCatchShouldNotRunWhenSucceeded {
88 | XCTestExpectation *expectation = [self expectationWithDescription:@"finish task"];
89 | __block BOOL ran = NO;
90 | [BFTask taskWithResult:@30].catch( ^id (NSError *error) {
91 | ran = YES;
92 | return nil;
93 | }).finally( ^BFTask *() {
94 | [expectation fulfill];
95 | return nil;
96 | });
97 | [self waitForExpectationsWithTimeout:5.0 handler:nil];
98 | XCTAssertFalse(ran, @"catch should not ran");
99 | }
100 |
101 | - (void)testCatchShouldRunWhenError {
102 | XCTestExpectation *expectation = [self expectationWithDescription:@"finish task"];
103 | [BFTask taskWithError:[NSError errorWithDomain:MY_ERROR_DOMAIN code:0 userInfo:nil]].catch( ^id (NSError *error) {
104 | XCTAssertEqualObjects([error domain], MY_ERROR_DOMAIN, "error should be passed.");
105 | [expectation fulfill];
106 | return nil;
107 | });
108 | [self waitForExpectationsWithTimeout:5.0 handler:nil];
109 | }
110 |
111 | - (void)testCatchShouldNotRunWhenCancelled {
112 | XCTestExpectation *expectation = [self expectationWithDescription:@"finish task"];
113 | __block BOOL ran = NO;
114 | [BFTask cancelledTask].catch( ^id (NSError *error) {
115 | ran = YES;
116 | return nil;
117 | }).finally( ^BFTask *() {
118 | [expectation fulfill];
119 | return nil;
120 | });
121 | [self waitForExpectationsWithTimeout:5.0 handler:nil];
122 | XCTAssertFalse(ran, @"catch should not ran");
123 | }
124 |
125 | - (void)testFinallyShouldRunWhenSucceeded {
126 | XCTestExpectation *expectation = [self expectationWithDescription:@"finish task"];
127 | [BFTask taskWithResult:@30].finally( ^BFTask *() {
128 | [expectation fulfill];
129 | return nil;
130 | });
131 | [self waitForExpectationsWithTimeout:5.0 handler:nil];
132 | }
133 |
134 | - (void)testFinallyShouldRunWhenFailed {
135 | XCTestExpectation *expectation = [self expectationWithDescription:@"finish task"];
136 | [BFTask taskWithError:[NSError errorWithDomain:MY_ERROR_DOMAIN code:0 userInfo:nil]].finally( ^BFTask *() {
137 | [expectation fulfill];
138 | return nil;
139 | });
140 | [self waitForExpectationsWithTimeout:5.0 handler:nil];
141 | }
142 |
143 | - (void)testFinallyShouldRunWhenCancelled {
144 | XCTestExpectation *expectation = [self expectationWithDescription:@"finish task"];
145 | [BFTask cancelledTask].finally( ^BFTask *() {
146 | [expectation fulfill];
147 | return nil;
148 | });
149 | [self waitForExpectationsWithTimeout:5.0 handler:nil];
150 | }
151 |
152 | - (BFTask *)delayAsyncAfter:(int64_t)milliseconds callback:(void (^)(void))callback {
153 | BFTaskCompletionSource *source = [BFTaskCompletionSource taskCompletionSource];
154 | int64_t delta = milliseconds * NSEC_PER_MSEC;
155 | dispatch_time_t time = dispatch_time(DISPATCH_TIME_NOW, delta);
156 | dispatch_after(time, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
157 | callback();
158 | [source setResult:[NSNumber numberWithLongLong:milliseconds]];
159 | });
160 | return [source task];
161 | }
162 |
163 | - (void)testFinallyShouldCompleteAfterReturnedTasksCompletion {
164 | XCTestExpectation *expectation = [self expectationWithDescription:@"finish task"];
165 | __block int v = 0;
166 | [BFTask taskWithResult:@30].finally( ^BFTask *() {
167 | return [self delayAsyncAfter:100 callback: ^{
168 | v = 100;
169 | }];
170 | }).then( ^id (BFTask *task) {
171 | XCTAssertEqual(v, 100, @"called after the task returnd from finally");
172 | [expectation fulfill];
173 | return nil;
174 | });
175 | [self waitForExpectationsWithTimeout:5.0 handler:nil];
176 | }
177 |
178 | - (void)testFinallyShouldNotChangeResultValue {
179 | XCTestExpectation *expectation = [self expectationWithDescription:@"finish task"];
180 | [BFTask taskWithResult:@30].finally( ^BFTask *() {
181 | return nil;
182 | }).then( ^id (NSNumber *result) {
183 | XCTAssertEqual([result intValue], 30, @"result value should not change");
184 | [expectation fulfill];
185 | return nil;
186 | });
187 | [self waitForExpectationsWithTimeout:5.0 handler:nil];
188 | }
189 |
190 | - (void)testFinallyShouldNotChangeErrorValue {
191 | XCTestExpectation *expectation = [self expectationWithDescription:@"finish task"];
192 | [BFTask taskWithError:[NSError errorWithDomain:MY_ERROR_DOMAIN code:0 userInfo:nil]].finally( ^BFTask *() {
193 | return nil;
194 | }).catch( ^id (NSError *error) {
195 | XCTAssertEqualObjects([error domain], MY_ERROR_DOMAIN, "error should not be changed.");
196 | [expectation fulfill];
197 | return nil;
198 | });
199 | [self waitForExpectationsWithTimeout:5.0 handler:nil];
200 | }
201 |
202 | - (void)testFinallyShouldNotChangeResultValueAfterReturnedTasksCompletion {
203 | XCTestExpectation *expectation = [self expectationWithDescription:@"finish task"];
204 | [BFTask taskWithResult:@30].finally( ^BFTask *() {
205 | return [self delayAsyncAfter:100 callback: ^{}];
206 | }).then( ^id (NSNumber *result) {
207 | XCTAssertEqual([result intValue], 30, @"result value should not change");
208 | [expectation fulfill];
209 | return nil;
210 | });
211 | [self waitForExpectationsWithTimeout:5.0 handler:nil];
212 | }
213 |
214 | - (void)testFinallyShouldNotChangeErrorValueAfterReturnedTasksCompletion {
215 | XCTestExpectation *expectation = [self expectationWithDescription:@"finish task"];
216 | [BFTask taskWithError:[NSError errorWithDomain:MY_ERROR_DOMAIN code:0 userInfo:nil]].finally( ^BFTask *() {
217 | return [self delayAsyncAfter:100 callback: ^{}];
218 | }).catch( ^id (NSError *error) {
219 | XCTAssertEqualObjects([error domain], MY_ERROR_DOMAIN, "error should not be changed.");
220 | [expectation fulfill];
221 | return nil;
222 | });
223 | [self waitForExpectationsWithTimeout:5.0 handler:nil];
224 | }
225 |
226 | - (void)testFinallyShouldChangeResultValueToErrorValueWhenErrorIsReturned {
227 | XCTestExpectation *expectation = [self expectationWithDescription:@"finish task"];
228 | [BFTask taskWithResult:@30].finally( ^BFTask *() {
229 | return [BFTask taskWithError:[NSError errorWithDomain:MY_ERROR_DOMAIN code:0 userInfo:nil]];
230 | }).then( ^id (BFTask *task) {
231 | XCTAssert(NO, "this code is not called because an error should be occured.");
232 | [expectation fulfill];
233 | return nil;
234 | }).catch( ^id (NSError *error) {
235 | XCTAssertEqualObjects([error domain], MY_ERROR_DOMAIN, "error should not be changed.");
236 | [expectation fulfill];
237 | return nil;
238 | });
239 | [self waitForExpectationsWithTimeout:5.0 handler:nil];
240 | }
241 |
242 | - (void)testFinallyShouldChangeResultValueToErrorValueAfterReturnedTaskReturnsError {
243 | XCTestExpectation *expectation = [self expectationWithDescription:@"finish task"];
244 | [BFTask taskWithResult:@30].finally( ^BFTask *() {
245 | return [self delayAsyncAfter:100 callback: ^{}].then( ^id (BFTask *task) {
246 | return [BFTask taskWithError:[NSError errorWithDomain:MY_ERROR_DOMAIN code:0 userInfo:nil]];
247 | });
248 | }).then( ^id (BFTask *task) {
249 | XCTAssert(NO, "this code is not called because an error should be occured.");
250 | [expectation fulfill];
251 | return nil;
252 | }).catch( ^id (NSError *error) {
253 | XCTAssertEqualObjects([error domain], MY_ERROR_DOMAIN, "error should not be changed.");
254 | [expectation fulfill];
255 | return nil;
256 | });
257 | [self waitForExpectationsWithTimeout:5.0 handler:nil];
258 | }
259 |
260 | @end
261 |
--------------------------------------------------------------------------------
/Example/BFTaskPromiseExample/BFTaskPromiseExample.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 46;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | 500FCC601ADD12D500483B14 /* BFTaskPromiseCppTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 500FCC5F1ADD12D500483B14 /* BFTaskPromiseCppTests.mm */; };
11 | 502A5F661B087D1300FAF832 /* SampleViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 502A5F651B087D1300FAF832 /* SampleViewController.m */; };
12 | 50CB3CE719A7866B0017ABC2 /* XCTestExpectation+OHRetroCompat.m in Sources */ = {isa = PBXBuildFile; fileRef = 50CB3CE619A7866B0017ABC2 /* XCTestExpectation+OHRetroCompat.m */; };
13 | 50DCEF41199EE58400EC94DC /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 50DCEF40199EE58400EC94DC /* Foundation.framework */; };
14 | 50DCEF43199EE58400EC94DC /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 50DCEF42199EE58400EC94DC /* CoreGraphics.framework */; };
15 | 50DCEF45199EE58400EC94DC /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 50DCEF44199EE58400EC94DC /* UIKit.framework */; };
16 | 50DCEF4B199EE58400EC94DC /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 50DCEF49199EE58400EC94DC /* InfoPlist.strings */; };
17 | 50DCEF4D199EE58400EC94DC /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 50DCEF4C199EE58400EC94DC /* main.m */; };
18 | 50DCEF51199EE58400EC94DC /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 50DCEF50199EE58400EC94DC /* AppDelegate.m */; };
19 | 50DCEF53199EE58400EC94DC /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 50DCEF52199EE58400EC94DC /* Images.xcassets */; };
20 | 50DCEF5A199EE58400EC94DC /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 50DCEF59199EE58400EC94DC /* XCTest.framework */; };
21 | 50DCEF5B199EE58400EC94DC /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 50DCEF40199EE58400EC94DC /* Foundation.framework */; };
22 | 50DCEF5C199EE58400EC94DC /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 50DCEF44199EE58400EC94DC /* UIKit.framework */; };
23 | 50DCEF64199EE58400EC94DC /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 50DCEF62199EE58400EC94DC /* InfoPlist.strings */; };
24 | 50DCEF66199EE58400EC94DC /* BFTaskPromiseExampleTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 50DCEF65199EE58400EC94DC /* BFTaskPromiseExampleTests.m */; };
25 | 7068DB2A2CB9FD310C818679 /* libPods-BFTaskPromiseExample.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 84AE5E18140601A5D84D1491 /* libPods-BFTaskPromiseExample.a */; };
26 | AA975B774F6BAB89CBBF5FC6 /* libPods-BFTaskPromiseExampleTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 8F368123E4D055378AB0D5DC /* libPods-BFTaskPromiseExampleTests.a */; };
27 | /* End PBXBuildFile section */
28 |
29 | /* Begin PBXContainerItemProxy section */
30 | 50DCEF5D199EE58400EC94DC /* PBXContainerItemProxy */ = {
31 | isa = PBXContainerItemProxy;
32 | containerPortal = 50DCEF35199EE58400EC94DC /* Project object */;
33 | proxyType = 1;
34 | remoteGlobalIDString = 50DCEF3C199EE58400EC94DC;
35 | remoteInfo = BFTaskPromiseExample;
36 | };
37 | /* End PBXContainerItemProxy section */
38 |
39 | /* Begin PBXFileReference section */
40 | 006F9A4B65DDEF532AF2B223 /* Pods-BFTaskPromiseExampleTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-BFTaskPromiseExampleTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-BFTaskPromiseExampleTests/Pods-BFTaskPromiseExampleTests.release.xcconfig"; sourceTree = ""; };
41 | 500FCC5F1ADD12D500483B14 /* BFTaskPromiseCppTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = BFTaskPromiseCppTests.mm; sourceTree = ""; };
42 | 502A5F641B087D1300FAF832 /* SampleViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SampleViewController.h; sourceTree = ""; };
43 | 502A5F651B087D1300FAF832 /* SampleViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SampleViewController.m; sourceTree = ""; };
44 | 50CB3CE519A7866B0017ABC2 /* XCTestExpectation+OHRetroCompat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "XCTestExpectation+OHRetroCompat.h"; sourceTree = ""; };
45 | 50CB3CE619A7866B0017ABC2 /* XCTestExpectation+OHRetroCompat.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "XCTestExpectation+OHRetroCompat.m"; sourceTree = ""; };
46 | 50DCEF3D199EE58400EC94DC /* BFTaskPromiseExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = BFTaskPromiseExample.app; sourceTree = BUILT_PRODUCTS_DIR; };
47 | 50DCEF40199EE58400EC94DC /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
48 | 50DCEF42199EE58400EC94DC /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
49 | 50DCEF44199EE58400EC94DC /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
50 | 50DCEF48199EE58400EC94DC /* BFTaskPromiseExample-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "BFTaskPromiseExample-Info.plist"; sourceTree = ""; };
51 | 50DCEF4A199EE58400EC94DC /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; };
52 | 50DCEF4C199EE58400EC94DC /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; };
53 | 50DCEF4E199EE58400EC94DC /* BFTaskPromiseExample-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "BFTaskPromiseExample-Prefix.pch"; sourceTree = ""; };
54 | 50DCEF4F199EE58400EC94DC /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; };
55 | 50DCEF50199EE58400EC94DC /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; };
56 | 50DCEF52199EE58400EC94DC /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; };
57 | 50DCEF58199EE58400EC94DC /* BFTaskPromiseExampleTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = BFTaskPromiseExampleTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
58 | 50DCEF59199EE58400EC94DC /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; };
59 | 50DCEF61199EE58400EC94DC /* BFTaskPromiseExampleTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "BFTaskPromiseExampleTests-Info.plist"; sourceTree = ""; };
60 | 50DCEF63199EE58400EC94DC /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; };
61 | 50DCEF65199EE58400EC94DC /* BFTaskPromiseExampleTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BFTaskPromiseExampleTests.m; sourceTree = ""; };
62 | 84AE5E18140601A5D84D1491 /* libPods-BFTaskPromiseExample.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-BFTaskPromiseExample.a"; sourceTree = BUILT_PRODUCTS_DIR; };
63 | 8F368123E4D055378AB0D5DC /* libPods-BFTaskPromiseExampleTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-BFTaskPromiseExampleTests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
64 | A6E6F45DFEA22A06E8A055F3 /* Pods-BFTaskPromiseExample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-BFTaskPromiseExample.debug.xcconfig"; path = "Pods/Target Support Files/Pods-BFTaskPromiseExample/Pods-BFTaskPromiseExample.debug.xcconfig"; sourceTree = ""; };
65 | E41082157BCEAAE4606F23C3 /* Pods-BFTaskPromiseExample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-BFTaskPromiseExample.release.xcconfig"; path = "Pods/Target Support Files/Pods-BFTaskPromiseExample/Pods-BFTaskPromiseExample.release.xcconfig"; sourceTree = ""; };
66 | FE599E2BC16603292C44AC65 /* Pods-BFTaskPromiseExampleTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-BFTaskPromiseExampleTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-BFTaskPromiseExampleTests/Pods-BFTaskPromiseExampleTests.debug.xcconfig"; sourceTree = ""; };
67 | /* End PBXFileReference section */
68 |
69 | /* Begin PBXFrameworksBuildPhase section */
70 | 50DCEF3A199EE58400EC94DC /* Frameworks */ = {
71 | isa = PBXFrameworksBuildPhase;
72 | buildActionMask = 2147483647;
73 | files = (
74 | 50DCEF43199EE58400EC94DC /* CoreGraphics.framework in Frameworks */,
75 | 50DCEF45199EE58400EC94DC /* UIKit.framework in Frameworks */,
76 | 50DCEF41199EE58400EC94DC /* Foundation.framework in Frameworks */,
77 | 7068DB2A2CB9FD310C818679 /* libPods-BFTaskPromiseExample.a in Frameworks */,
78 | );
79 | runOnlyForDeploymentPostprocessing = 0;
80 | };
81 | 50DCEF55199EE58400EC94DC /* Frameworks */ = {
82 | isa = PBXFrameworksBuildPhase;
83 | buildActionMask = 2147483647;
84 | files = (
85 | 50DCEF5A199EE58400EC94DC /* XCTest.framework in Frameworks */,
86 | 50DCEF5C199EE58400EC94DC /* UIKit.framework in Frameworks */,
87 | 50DCEF5B199EE58400EC94DC /* Foundation.framework in Frameworks */,
88 | AA975B774F6BAB89CBBF5FC6 /* libPods-BFTaskPromiseExampleTests.a in Frameworks */,
89 | );
90 | runOnlyForDeploymentPostprocessing = 0;
91 | };
92 | /* End PBXFrameworksBuildPhase section */
93 |
94 | /* Begin PBXGroup section */
95 | 50CB3CE419A786550017ABC2 /* XCTestExpectation+Xcode5 */ = {
96 | isa = PBXGroup;
97 | children = (
98 | 50CB3CE519A7866B0017ABC2 /* XCTestExpectation+OHRetroCompat.h */,
99 | 50CB3CE619A7866B0017ABC2 /* XCTestExpectation+OHRetroCompat.m */,
100 | );
101 | path = "XCTestExpectation+Xcode5";
102 | sourceTree = "";
103 | };
104 | 50DCEF34199EE58400EC94DC = {
105 | isa = PBXGroup;
106 | children = (
107 | 50DCEF46199EE58400EC94DC /* BFTaskPromiseExample */,
108 | 50DCEF5F199EE58400EC94DC /* BFTaskPromiseExampleTests */,
109 | 50DCEF3F199EE58400EC94DC /* Frameworks */,
110 | 50DCEF3E199EE58400EC94DC /* Products */,
111 | C79855277C0E1079B440461C /* Pods */,
112 | );
113 | sourceTree = "";
114 | };
115 | 50DCEF3E199EE58400EC94DC /* Products */ = {
116 | isa = PBXGroup;
117 | children = (
118 | 50DCEF3D199EE58400EC94DC /* BFTaskPromiseExample.app */,
119 | 50DCEF58199EE58400EC94DC /* BFTaskPromiseExampleTests.xctest */,
120 | );
121 | name = Products;
122 | sourceTree = "";
123 | };
124 | 50DCEF3F199EE58400EC94DC /* Frameworks */ = {
125 | isa = PBXGroup;
126 | children = (
127 | 50DCEF40199EE58400EC94DC /* Foundation.framework */,
128 | 50DCEF42199EE58400EC94DC /* CoreGraphics.framework */,
129 | 50DCEF44199EE58400EC94DC /* UIKit.framework */,
130 | 50DCEF59199EE58400EC94DC /* XCTest.framework */,
131 | 84AE5E18140601A5D84D1491 /* libPods-BFTaskPromiseExample.a */,
132 | 8F368123E4D055378AB0D5DC /* libPods-BFTaskPromiseExampleTests.a */,
133 | );
134 | name = Frameworks;
135 | sourceTree = "";
136 | };
137 | 50DCEF46199EE58400EC94DC /* BFTaskPromiseExample */ = {
138 | isa = PBXGroup;
139 | children = (
140 | 50DCEF4F199EE58400EC94DC /* AppDelegate.h */,
141 | 50DCEF50199EE58400EC94DC /* AppDelegate.m */,
142 | 502A5F641B087D1300FAF832 /* SampleViewController.h */,
143 | 502A5F651B087D1300FAF832 /* SampleViewController.m */,
144 | 50DCEF52199EE58400EC94DC /* Images.xcassets */,
145 | 50DCEF47199EE58400EC94DC /* Supporting Files */,
146 | );
147 | path = BFTaskPromiseExample;
148 | sourceTree = "";
149 | };
150 | 50DCEF47199EE58400EC94DC /* Supporting Files */ = {
151 | isa = PBXGroup;
152 | children = (
153 | 50DCEF48199EE58400EC94DC /* BFTaskPromiseExample-Info.plist */,
154 | 50DCEF49199EE58400EC94DC /* InfoPlist.strings */,
155 | 50DCEF4C199EE58400EC94DC /* main.m */,
156 | 50DCEF4E199EE58400EC94DC /* BFTaskPromiseExample-Prefix.pch */,
157 | );
158 | name = "Supporting Files";
159 | sourceTree = "";
160 | };
161 | 50DCEF5F199EE58400EC94DC /* BFTaskPromiseExampleTests */ = {
162 | isa = PBXGroup;
163 | children = (
164 | 50DCEF65199EE58400EC94DC /* BFTaskPromiseExampleTests.m */,
165 | 500FCC5F1ADD12D500483B14 /* BFTaskPromiseCppTests.mm */,
166 | 50CB3CE419A786550017ABC2 /* XCTestExpectation+Xcode5 */,
167 | 50DCEF60199EE58400EC94DC /* Supporting Files */,
168 | );
169 | path = BFTaskPromiseExampleTests;
170 | sourceTree = "";
171 | };
172 | 50DCEF60199EE58400EC94DC /* Supporting Files */ = {
173 | isa = PBXGroup;
174 | children = (
175 | 50DCEF61199EE58400EC94DC /* BFTaskPromiseExampleTests-Info.plist */,
176 | 50DCEF62199EE58400EC94DC /* InfoPlist.strings */,
177 | );
178 | name = "Supporting Files";
179 | sourceTree = "";
180 | };
181 | C79855277C0E1079B440461C /* Pods */ = {
182 | isa = PBXGroup;
183 | children = (
184 | A6E6F45DFEA22A06E8A055F3 /* Pods-BFTaskPromiseExample.debug.xcconfig */,
185 | E41082157BCEAAE4606F23C3 /* Pods-BFTaskPromiseExample.release.xcconfig */,
186 | FE599E2BC16603292C44AC65 /* Pods-BFTaskPromiseExampleTests.debug.xcconfig */,
187 | 006F9A4B65DDEF532AF2B223 /* Pods-BFTaskPromiseExampleTests.release.xcconfig */,
188 | );
189 | name = Pods;
190 | sourceTree = "";
191 | };
192 | /* End PBXGroup section */
193 |
194 | /* Begin PBXNativeTarget section */
195 | 50DCEF3C199EE58400EC94DC /* BFTaskPromiseExample */ = {
196 | isa = PBXNativeTarget;
197 | buildConfigurationList = 50DCEF69199EE58400EC94DC /* Build configuration list for PBXNativeTarget "BFTaskPromiseExample" */;
198 | buildPhases = (
199 | 2A25B06C00490F0579A796CA /* [CP] Check Pods Manifest.lock */,
200 | 192D6D08483A97EED98BCB51 /* 📦 Check Pods Manifest.lock */,
201 | 50DCEF39199EE58400EC94DC /* Sources */,
202 | 50DCEF3A199EE58400EC94DC /* Frameworks */,
203 | 50DCEF3B199EE58400EC94DC /* Resources */,
204 | );
205 | buildRules = (
206 | );
207 | dependencies = (
208 | );
209 | name = BFTaskPromiseExample;
210 | productName = BFTaskPromiseExample;
211 | productReference = 50DCEF3D199EE58400EC94DC /* BFTaskPromiseExample.app */;
212 | productType = "com.apple.product-type.application";
213 | };
214 | 50DCEF57199EE58400EC94DC /* BFTaskPromiseExampleTests */ = {
215 | isa = PBXNativeTarget;
216 | buildConfigurationList = 50DCEF6C199EE58400EC94DC /* Build configuration list for PBXNativeTarget "BFTaskPromiseExampleTests" */;
217 | buildPhases = (
218 | 86880097880D323FCF1D5244 /* [CP] Check Pods Manifest.lock */,
219 | B0B6BE3D0F276B9D0EDD4054 /* 📦 Check Pods Manifest.lock */,
220 | 50DCEF54199EE58400EC94DC /* Sources */,
221 | 50DCEF55199EE58400EC94DC /* Frameworks */,
222 | 50DCEF56199EE58400EC94DC /* Resources */,
223 | );
224 | buildRules = (
225 | );
226 | dependencies = (
227 | 50DCEF5E199EE58400EC94DC /* PBXTargetDependency */,
228 | );
229 | name = BFTaskPromiseExampleTests;
230 | productName = BFTaskPromiseExampleTests;
231 | productReference = 50DCEF58199EE58400EC94DC /* BFTaskPromiseExampleTests.xctest */;
232 | productType = "com.apple.product-type.bundle.unit-test";
233 | };
234 | /* End PBXNativeTarget section */
235 |
236 | /* Begin PBXProject section */
237 | 50DCEF35199EE58400EC94DC /* Project object */ = {
238 | isa = PBXProject;
239 | attributes = {
240 | LastUpgradeCheck = 0940;
241 | ORGANIZATIONNAME = Hironytic;
242 | TargetAttributes = {
243 | 50DCEF57199EE58400EC94DC = {
244 | TestTargetID = 50DCEF3C199EE58400EC94DC;
245 | };
246 | };
247 | };
248 | buildConfigurationList = 50DCEF38199EE58400EC94DC /* Build configuration list for PBXProject "BFTaskPromiseExample" */;
249 | compatibilityVersion = "Xcode 3.2";
250 | developmentRegion = English;
251 | hasScannedForEncodings = 0;
252 | knownRegions = (
253 | en,
254 | );
255 | mainGroup = 50DCEF34199EE58400EC94DC;
256 | productRefGroup = 50DCEF3E199EE58400EC94DC /* Products */;
257 | projectDirPath = "";
258 | projectRoot = "";
259 | targets = (
260 | 50DCEF3C199EE58400EC94DC /* BFTaskPromiseExample */,
261 | 50DCEF57199EE58400EC94DC /* BFTaskPromiseExampleTests */,
262 | );
263 | };
264 | /* End PBXProject section */
265 |
266 | /* Begin PBXResourcesBuildPhase section */
267 | 50DCEF3B199EE58400EC94DC /* Resources */ = {
268 | isa = PBXResourcesBuildPhase;
269 | buildActionMask = 2147483647;
270 | files = (
271 | 50DCEF4B199EE58400EC94DC /* InfoPlist.strings in Resources */,
272 | 50DCEF53199EE58400EC94DC /* Images.xcassets in Resources */,
273 | );
274 | runOnlyForDeploymentPostprocessing = 0;
275 | };
276 | 50DCEF56199EE58400EC94DC /* Resources */ = {
277 | isa = PBXResourcesBuildPhase;
278 | buildActionMask = 2147483647;
279 | files = (
280 | 50DCEF64199EE58400EC94DC /* InfoPlist.strings in Resources */,
281 | );
282 | runOnlyForDeploymentPostprocessing = 0;
283 | };
284 | /* End PBXResourcesBuildPhase section */
285 |
286 | /* Begin PBXShellScriptBuildPhase section */
287 | 192D6D08483A97EED98BCB51 /* 📦 Check Pods Manifest.lock */ = {
288 | isa = PBXShellScriptBuildPhase;
289 | buildActionMask = 2147483647;
290 | files = (
291 | );
292 | inputPaths = (
293 | );
294 | name = "📦 Check Pods Manifest.lock";
295 | outputPaths = (
296 | );
297 | runOnlyForDeploymentPostprocessing = 0;
298 | shellPath = /bin/sh;
299 | shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n";
300 | showEnvVarsInLog = 0;
301 | };
302 | 2A25B06C00490F0579A796CA /* [CP] Check Pods Manifest.lock */ = {
303 | isa = PBXShellScriptBuildPhase;
304 | buildActionMask = 2147483647;
305 | files = (
306 | );
307 | inputPaths = (
308 | "${PODS_PODFILE_DIR_PATH}/Podfile.lock",
309 | "${PODS_ROOT}/Manifest.lock",
310 | );
311 | name = "[CP] Check Pods Manifest.lock";
312 | outputPaths = (
313 | "$(DERIVED_FILE_DIR)/Pods-BFTaskPromiseExample-checkManifestLockResult.txt",
314 | );
315 | runOnlyForDeploymentPostprocessing = 0;
316 | shellPath = /bin/sh;
317 | shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
318 | showEnvVarsInLog = 0;
319 | };
320 | 86880097880D323FCF1D5244 /* [CP] Check Pods Manifest.lock */ = {
321 | isa = PBXShellScriptBuildPhase;
322 | buildActionMask = 2147483647;
323 | files = (
324 | );
325 | inputPaths = (
326 | "${PODS_PODFILE_DIR_PATH}/Podfile.lock",
327 | "${PODS_ROOT}/Manifest.lock",
328 | );
329 | name = "[CP] Check Pods Manifest.lock";
330 | outputPaths = (
331 | "$(DERIVED_FILE_DIR)/Pods-BFTaskPromiseExampleTests-checkManifestLockResult.txt",
332 | );
333 | runOnlyForDeploymentPostprocessing = 0;
334 | shellPath = /bin/sh;
335 | shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
336 | showEnvVarsInLog = 0;
337 | };
338 | B0B6BE3D0F276B9D0EDD4054 /* 📦 Check Pods Manifest.lock */ = {
339 | isa = PBXShellScriptBuildPhase;
340 | buildActionMask = 2147483647;
341 | files = (
342 | );
343 | inputPaths = (
344 | );
345 | name = "📦 Check Pods Manifest.lock";
346 | outputPaths = (
347 | );
348 | runOnlyForDeploymentPostprocessing = 0;
349 | shellPath = /bin/sh;
350 | shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n";
351 | showEnvVarsInLog = 0;
352 | };
353 | /* End PBXShellScriptBuildPhase section */
354 |
355 | /* Begin PBXSourcesBuildPhase section */
356 | 50DCEF39199EE58400EC94DC /* Sources */ = {
357 | isa = PBXSourcesBuildPhase;
358 | buildActionMask = 2147483647;
359 | files = (
360 | 50DCEF51199EE58400EC94DC /* AppDelegate.m in Sources */,
361 | 50DCEF4D199EE58400EC94DC /* main.m in Sources */,
362 | 502A5F661B087D1300FAF832 /* SampleViewController.m in Sources */,
363 | );
364 | runOnlyForDeploymentPostprocessing = 0;
365 | };
366 | 50DCEF54199EE58400EC94DC /* Sources */ = {
367 | isa = PBXSourcesBuildPhase;
368 | buildActionMask = 2147483647;
369 | files = (
370 | 50DCEF66199EE58400EC94DC /* BFTaskPromiseExampleTests.m in Sources */,
371 | 500FCC601ADD12D500483B14 /* BFTaskPromiseCppTests.mm in Sources */,
372 | 50CB3CE719A7866B0017ABC2 /* XCTestExpectation+OHRetroCompat.m in Sources */,
373 | );
374 | runOnlyForDeploymentPostprocessing = 0;
375 | };
376 | /* End PBXSourcesBuildPhase section */
377 |
378 | /* Begin PBXTargetDependency section */
379 | 50DCEF5E199EE58400EC94DC /* PBXTargetDependency */ = {
380 | isa = PBXTargetDependency;
381 | target = 50DCEF3C199EE58400EC94DC /* BFTaskPromiseExample */;
382 | targetProxy = 50DCEF5D199EE58400EC94DC /* PBXContainerItemProxy */;
383 | };
384 | /* End PBXTargetDependency section */
385 |
386 | /* Begin PBXVariantGroup section */
387 | 50DCEF49199EE58400EC94DC /* InfoPlist.strings */ = {
388 | isa = PBXVariantGroup;
389 | children = (
390 | 50DCEF4A199EE58400EC94DC /* en */,
391 | );
392 | name = InfoPlist.strings;
393 | sourceTree = "";
394 | };
395 | 50DCEF62199EE58400EC94DC /* InfoPlist.strings */ = {
396 | isa = PBXVariantGroup;
397 | children = (
398 | 50DCEF63199EE58400EC94DC /* en */,
399 | );
400 | name = InfoPlist.strings;
401 | sourceTree = "";
402 | };
403 | /* End PBXVariantGroup section */
404 |
405 | /* Begin XCBuildConfiguration section */
406 | 50DCEF67199EE58400EC94DC /* Debug */ = {
407 | isa = XCBuildConfiguration;
408 | buildSettings = {
409 | ALWAYS_SEARCH_USER_PATHS = NO;
410 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
411 | CLANG_CXX_LIBRARY = "libc++";
412 | CLANG_ENABLE_MODULES = YES;
413 | CLANG_ENABLE_OBJC_ARC = YES;
414 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
415 | CLANG_WARN_BOOL_CONVERSION = YES;
416 | CLANG_WARN_COMMA = YES;
417 | CLANG_WARN_CONSTANT_CONVERSION = YES;
418 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
419 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
420 | CLANG_WARN_EMPTY_BODY = YES;
421 | CLANG_WARN_ENUM_CONVERSION = YES;
422 | CLANG_WARN_INFINITE_RECURSION = YES;
423 | CLANG_WARN_INT_CONVERSION = YES;
424 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
425 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
426 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
427 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
428 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
429 | CLANG_WARN_STRICT_PROTOTYPES = YES;
430 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
431 | CLANG_WARN_UNREACHABLE_CODE = YES;
432 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
433 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
434 | COPY_PHASE_STRIP = NO;
435 | ENABLE_STRICT_OBJC_MSGSEND = YES;
436 | ENABLE_TESTABILITY = YES;
437 | GCC_C_LANGUAGE_STANDARD = gnu99;
438 | GCC_DYNAMIC_NO_PIC = NO;
439 | GCC_NO_COMMON_BLOCKS = YES;
440 | GCC_OPTIMIZATION_LEVEL = 0;
441 | GCC_PREPROCESSOR_DEFINITIONS = (
442 | "DEBUG=1",
443 | "$(inherited)",
444 | );
445 | GCC_SYMBOLS_PRIVATE_EXTERN = NO;
446 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
447 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
448 | GCC_WARN_UNDECLARED_SELECTOR = YES;
449 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
450 | GCC_WARN_UNUSED_FUNCTION = YES;
451 | GCC_WARN_UNUSED_VARIABLE = YES;
452 | IPHONEOS_DEPLOYMENT_TARGET = 9.0;
453 | ONLY_ACTIVE_ARCH = YES;
454 | SDKROOT = iphoneos;
455 | };
456 | name = Debug;
457 | };
458 | 50DCEF68199EE58400EC94DC /* Release */ = {
459 | isa = XCBuildConfiguration;
460 | buildSettings = {
461 | ALWAYS_SEARCH_USER_PATHS = NO;
462 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
463 | CLANG_CXX_LIBRARY = "libc++";
464 | CLANG_ENABLE_MODULES = YES;
465 | CLANG_ENABLE_OBJC_ARC = YES;
466 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
467 | CLANG_WARN_BOOL_CONVERSION = YES;
468 | CLANG_WARN_COMMA = YES;
469 | CLANG_WARN_CONSTANT_CONVERSION = YES;
470 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
471 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
472 | CLANG_WARN_EMPTY_BODY = YES;
473 | CLANG_WARN_ENUM_CONVERSION = YES;
474 | CLANG_WARN_INFINITE_RECURSION = YES;
475 | CLANG_WARN_INT_CONVERSION = YES;
476 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
477 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
478 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
479 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
480 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
481 | CLANG_WARN_STRICT_PROTOTYPES = YES;
482 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
483 | CLANG_WARN_UNREACHABLE_CODE = YES;
484 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
485 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
486 | COPY_PHASE_STRIP = YES;
487 | ENABLE_NS_ASSERTIONS = NO;
488 | ENABLE_STRICT_OBJC_MSGSEND = YES;
489 | GCC_C_LANGUAGE_STANDARD = gnu99;
490 | GCC_NO_COMMON_BLOCKS = YES;
491 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
492 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
493 | GCC_WARN_UNDECLARED_SELECTOR = YES;
494 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
495 | GCC_WARN_UNUSED_FUNCTION = YES;
496 | GCC_WARN_UNUSED_VARIABLE = YES;
497 | IPHONEOS_DEPLOYMENT_TARGET = 9.0;
498 | SDKROOT = iphoneos;
499 | VALIDATE_PRODUCT = YES;
500 | };
501 | name = Release;
502 | };
503 | 50DCEF6A199EE58400EC94DC /* Debug */ = {
504 | isa = XCBuildConfiguration;
505 | baseConfigurationReference = A6E6F45DFEA22A06E8A055F3 /* Pods-BFTaskPromiseExample.debug.xcconfig */;
506 | buildSettings = {
507 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
508 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
509 | GCC_PRECOMPILE_PREFIX_HEADER = YES;
510 | GCC_PREFIX_HEADER = "BFTaskPromiseExample/BFTaskPromiseExample-Prefix.pch";
511 | INFOPLIST_FILE = "BFTaskPromiseExample/BFTaskPromiseExample-Info.plist";
512 | PRODUCT_BUNDLE_IDENTIFIER = "com.hironytic.${PRODUCT_NAME:rfc1034identifier}";
513 | PRODUCT_NAME = "$(TARGET_NAME)";
514 | WRAPPER_EXTENSION = app;
515 | };
516 | name = Debug;
517 | };
518 | 50DCEF6B199EE58400EC94DC /* Release */ = {
519 | isa = XCBuildConfiguration;
520 | baseConfigurationReference = E41082157BCEAAE4606F23C3 /* Pods-BFTaskPromiseExample.release.xcconfig */;
521 | buildSettings = {
522 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
523 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
524 | GCC_PRECOMPILE_PREFIX_HEADER = YES;
525 | GCC_PREFIX_HEADER = "BFTaskPromiseExample/BFTaskPromiseExample-Prefix.pch";
526 | INFOPLIST_FILE = "BFTaskPromiseExample/BFTaskPromiseExample-Info.plist";
527 | PRODUCT_BUNDLE_IDENTIFIER = "com.hironytic.${PRODUCT_NAME:rfc1034identifier}";
528 | PRODUCT_NAME = "$(TARGET_NAME)";
529 | WRAPPER_EXTENSION = app;
530 | };
531 | name = Release;
532 | };
533 | 50DCEF6D199EE58400EC94DC /* Debug */ = {
534 | isa = XCBuildConfiguration;
535 | baseConfigurationReference = FE599E2BC16603292C44AC65 /* Pods-BFTaskPromiseExampleTests.debug.xcconfig */;
536 | buildSettings = {
537 | BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/BFTaskPromiseExample.app/BFTaskPromiseExample";
538 | FRAMEWORK_SEARCH_PATHS = (
539 | "$(inherited)",
540 | "$(DEVELOPER_FRAMEWORKS_DIR)",
541 | );
542 | GCC_PRECOMPILE_PREFIX_HEADER = YES;
543 | GCC_PREFIX_HEADER = "BFTaskPromiseExample/BFTaskPromiseExample-Prefix.pch";
544 | GCC_PREPROCESSOR_DEFINITIONS = (
545 | "DEBUG=1",
546 | "$(inherited)",
547 | );
548 | INFOPLIST_FILE = "BFTaskPromiseExampleTests/BFTaskPromiseExampleTests-Info.plist";
549 | PRODUCT_BUNDLE_IDENTIFIER = "com.hironytic.${PRODUCT_NAME:rfc1034identifier}";
550 | PRODUCT_NAME = "$(TARGET_NAME)";
551 | TEST_HOST = "$(BUNDLE_LOADER)";
552 | WRAPPER_EXTENSION = xctest;
553 | };
554 | name = Debug;
555 | };
556 | 50DCEF6E199EE58400EC94DC /* Release */ = {
557 | isa = XCBuildConfiguration;
558 | baseConfigurationReference = 006F9A4B65DDEF532AF2B223 /* Pods-BFTaskPromiseExampleTests.release.xcconfig */;
559 | buildSettings = {
560 | BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/BFTaskPromiseExample.app/BFTaskPromiseExample";
561 | FRAMEWORK_SEARCH_PATHS = (
562 | "$(inherited)",
563 | "$(DEVELOPER_FRAMEWORKS_DIR)",
564 | );
565 | GCC_PRECOMPILE_PREFIX_HEADER = YES;
566 | GCC_PREFIX_HEADER = "BFTaskPromiseExample/BFTaskPromiseExample-Prefix.pch";
567 | INFOPLIST_FILE = "BFTaskPromiseExampleTests/BFTaskPromiseExampleTests-Info.plist";
568 | PRODUCT_BUNDLE_IDENTIFIER = "com.hironytic.${PRODUCT_NAME:rfc1034identifier}";
569 | PRODUCT_NAME = "$(TARGET_NAME)";
570 | TEST_HOST = "$(BUNDLE_LOADER)";
571 | WRAPPER_EXTENSION = xctest;
572 | };
573 | name = Release;
574 | };
575 | /* End XCBuildConfiguration section */
576 |
577 | /* Begin XCConfigurationList section */
578 | 50DCEF38199EE58400EC94DC /* Build configuration list for PBXProject "BFTaskPromiseExample" */ = {
579 | isa = XCConfigurationList;
580 | buildConfigurations = (
581 | 50DCEF67199EE58400EC94DC /* Debug */,
582 | 50DCEF68199EE58400EC94DC /* Release */,
583 | );
584 | defaultConfigurationIsVisible = 0;
585 | defaultConfigurationName = Release;
586 | };
587 | 50DCEF69199EE58400EC94DC /* Build configuration list for PBXNativeTarget "BFTaskPromiseExample" */ = {
588 | isa = XCConfigurationList;
589 | buildConfigurations = (
590 | 50DCEF6A199EE58400EC94DC /* Debug */,
591 | 50DCEF6B199EE58400EC94DC /* Release */,
592 | );
593 | defaultConfigurationIsVisible = 0;
594 | defaultConfigurationName = Release;
595 | };
596 | 50DCEF6C199EE58400EC94DC /* Build configuration list for PBXNativeTarget "BFTaskPromiseExampleTests" */ = {
597 | isa = XCConfigurationList;
598 | buildConfigurations = (
599 | 50DCEF6D199EE58400EC94DC /* Debug */,
600 | 50DCEF6E199EE58400EC94DC /* Release */,
601 | );
602 | defaultConfigurationIsVisible = 0;
603 | defaultConfigurationName = Release;
604 | };
605 | /* End XCConfigurationList section */
606 | };
607 | rootObject = 50DCEF35199EE58400EC94DC /* Project object */;
608 | }
609 |
--------------------------------------------------------------------------------