Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

category on UIViewController #2

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions BAPromise.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ s.osx.deployment_target = '10.10'
s.tvos.deployment_target = '9.0'
s.requires_arc = true

s.source_files = 'Classes/*'
s.source_files = 'Classes/*', 'Categories/*'

s.public_header_files = 'Classes/BAPromise.h'
s.public_header_files = 'Classes/BAPromise.h', 'Categories/*.h'

end
14 changes: 14 additions & 0 deletions BAPromise.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
E7B8D23A1B7E6D0200823BFC /* TestWaiter.h in Sources */ = {isa = PBXBuildFile; fileRef = E7B8D2221B7E6CDF00823BFC /* TestWaiter.h */; };
E7B8D23B1B7E6D0200823BFC /* TestWaiter.m in Sources */ = {isa = PBXBuildFile; fileRef = E7B8D2231B7E6CDF00823BFC /* TestWaiter.m */; };
E7B8D23C1B7E6D0200823BFC /* ThenTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E7B8D2241B7E6CDF00823BFC /* ThenTests.m */; };
E7C2C0791CC9160800D271CC /* UIViewController+BAPromise.m in Sources */ = {isa = PBXBuildFile; fileRef = E7C2C0781CC9160800D271CC /* UIViewController+BAPromise.m */; };
E7CA16FD1BB9B0FC002D7196 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = E7CA16FC1BB9B0FC002D7196 /* main.m */; };
E7CA17001BB9B0FC002D7196 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = E7CA16FF1BB9B0FC002D7196 /* AppDelegate.m */; };
E7CA17031BB9B0FC002D7196 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E7CA17021BB9B0FC002D7196 /* ViewController.m */; };
Expand Down Expand Up @@ -126,6 +127,8 @@
E7B8D2221B7E6CDF00823BFC /* TestWaiter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TestWaiter.h; path = BAPromiseTests/TestWaiter.h; sourceTree = "<group>"; };
E7B8D2231B7E6CDF00823BFC /* TestWaiter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TestWaiter.m; path = BAPromiseTests/TestWaiter.m; sourceTree = "<group>"; };
E7B8D2241B7E6CDF00823BFC /* ThenTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ThenTests.m; path = BAPromiseTests/ThenTests.m; sourceTree = "<group>"; };
E7C2C0771CC9160800D271CC /* UIViewController+BAPromise.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIViewController+BAPromise.h"; sourceTree = "<group>"; };
E7C2C0781CC9160800D271CC /* UIViewController+BAPromise.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIViewController+BAPromise.m"; sourceTree = "<group>"; };
E7CA16F91BB9B0FC002D7196 /* tvOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = tvOS.app; sourceTree = BUILT_PRODUCTS_DIR; };
E7CA16FC1BB9B0FC002D7196 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
E7CA16FE1BB9B0FC002D7196 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -206,6 +209,7 @@
E712B3231B7E6B4800590AA8 = {
isa = PBXGroup;
children = (
E7C2C0761CC915DA00D271CC /* Categories */,
E7B8D22C1B7E6CE400823BFC /* Tests */,
E712B3771B7E6B8000590AA8 /* Classes */,
E712B32E1B7E6B4800590AA8 /* OS X */,
Expand Down Expand Up @@ -321,6 +325,15 @@
name = Tests;
sourceTree = "<group>";
};
E7C2C0761CC915DA00D271CC /* Categories */ = {
isa = PBXGroup;
children = (
E7C2C0771CC9160800D271CC /* UIViewController+BAPromise.h */,
E7C2C0781CC9160800D271CC /* UIViewController+BAPromise.m */,
);
path = Categories;
sourceTree = "<group>";
};
E7CA16FA1BB9B0FC002D7196 /* tvOS */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -731,6 +744,7 @@
buildActionMask = 2147483647;
files = (
E712B3341B7E6B4800590AA8 /* main.m in Sources */,
E7C2C0791CC9160800D271CC /* UIViewController+BAPromise.m in Sources */,
E7B8D21B1B7E6CB000823BFC /* BAPromise.m in Sources */,
E712B3311B7E6B4800590AA8 /* AppDelegate.m in Sources */,
);
Expand Down
13 changes: 13 additions & 0 deletions Categories/UIViewController+BAPromise.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// UIViewController+BAPromise.h
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

YES
freddy

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hah!

oh it would help if i added the methods to the interface file

// BAPromise
//
// Created by Ben Allison on 4/21/16.
// Copyright © 2016 Ben Allison. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface UIViewController (BAPromise)

@end
52 changes: 52 additions & 0 deletions Categories/UIViewController+BAPromise.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//
// UIViewController+BAPromise.m
// BAPromise
//
// Created by Ben Allison on 4/21/16.
// Copyright © 2016 Ben Allison. All rights reserved.
//

#import "UIViewController+BAPromise.h"
#import "BAPromiseClient.h"

@implementation UIViewController (BAPromise)

-(BAPromise *)promise_DismissViewControllerAnimated:(BOOL)animated
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick here but you are using snake_case for first part of ...present... below :-)

{
BAPromiseClient *promise = BAPromiseClient.new;
if (!self.presentedViewController) {
// TODO(benski) a better error
return [promise rejectedPromise:[NSError errorWithDomain:@"org.benski.promise" code:0 info:nil]];
}

[self dismissViewControllerAnimated:animated completion:^{
[promise fulfil];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this a typo? Now i'm forgetting how to spell it

}];
return promise;
}

-(BAPromise *)promise_presentViewController:(UIViewController *)controller
animated:(BOOL)animated
{
BAPromiseClient *promise = BAPromiseClient.new;
[self presentViewController:controller animated:YES completion:^{
[promise fullfil];
}];
return promise;
}

- (BAPromise<NSNumber *> *)transitionFromViewController:(UIViewController *)fromViewController toViewController:(UIViewController *)toViewController duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options animations:(void (^ __nullable)(void))animations completion:(void (^ __nullable)(BOOL finished))completion
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would recommend line breaks on fields for this one :-)

{
BAPromiseClient *promise = BAPromiseClient.new;
[self transitionFromViewController:fromViewController
toViewController:toViewController
duration:duration
options:options
animations:animations
completion:^(BOOL finished) {
[promise fulfillWithObject:@(finished)];
}];
return promise;
}

@end