diff --git a/BlocksKit.xcodeproj/project.pbxproj b/BlocksKit.xcodeproj/project.pbxproj index c08aa3775..30e10656b 100644 --- a/BlocksKit.xcodeproj/project.pbxproj +++ b/BlocksKit.xcodeproj/project.pbxproj @@ -152,9 +152,6 @@ DB4CA4F61B3A6657004B70F8 /* UIPopoverController+BlocksKit.h in Headers */ = {isa = PBXBuildFile; fileRef = DB4CA49D1B3A6657004B70F8 /* UIPopoverController+BlocksKit.h */; settings = {ATTRIBUTES = (Public, ); }; }; DB4CA4F81B3A6657004B70F8 /* UIPopoverController+BlocksKit.m in Sources */ = {isa = PBXBuildFile; fileRef = DB4CA49E1B3A6657004B70F8 /* UIPopoverController+BlocksKit.m */; }; DB4CA4F91B3A6657004B70F8 /* UIPopoverController+BlocksKit.m in Sources */ = {isa = PBXBuildFile; fileRef = DB4CA49E1B3A6657004B70F8 /* UIPopoverController+BlocksKit.m */; }; - DB4CA4FB1B3A6657004B70F8 /* UITextField+BlocksKit.h in Headers */ = {isa = PBXBuildFile; fileRef = DB4CA49F1B3A6657004B70F8 /* UITextField+BlocksKit.h */; settings = {ATTRIBUTES = (Public, ); }; }; - DB4CA4FD1B3A6657004B70F8 /* UITextField+BlocksKit.m in Sources */ = {isa = PBXBuildFile; fileRef = DB4CA4A01B3A6657004B70F8 /* UITextField+BlocksKit.m */; }; - DB4CA4FE1B3A6657004B70F8 /* UITextField+BlocksKit.m in Sources */ = {isa = PBXBuildFile; fileRef = DB4CA4A01B3A6657004B70F8 /* UITextField+BlocksKit.m */; }; DB4CA5001B3A6657004B70F8 /* UIView+BlocksKit.h in Headers */ = {isa = PBXBuildFile; fileRef = DB4CA4A11B3A6657004B70F8 /* UIView+BlocksKit.h */; settings = {ATTRIBUTES = (Public, ); }; }; DB4CA5021B3A6657004B70F8 /* UIView+BlocksKit.m in Sources */ = {isa = PBXBuildFile; fileRef = DB4CA4A21B3A6657004B70F8 /* UIView+BlocksKit.m */; }; DB4CA5031B3A6657004B70F8 /* UIView+BlocksKit.m in Sources */ = {isa = PBXBuildFile; fileRef = DB4CA4A21B3A6657004B70F8 /* UIView+BlocksKit.m */; }; @@ -274,7 +271,6 @@ DB5C6C781C5200B200778E5F /* UIImage+BlocksKit.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DB4CA4991B3A6657004B70F8 /* UIImage+BlocksKit.h */; }; DB5C6C791C5200B200778E5F /* UIImagePickerController+BlocksKit.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DB4CA49B1B3A6657004B70F8 /* UIImagePickerController+BlocksKit.h */; }; DB5C6C7A1C5200B200778E5F /* UIPopoverController+BlocksKit.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DB4CA49D1B3A6657004B70F8 /* UIPopoverController+BlocksKit.h */; }; - DB5C6C7B1C5200B200778E5F /* UITextField+BlocksKit.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DB4CA49F1B3A6657004B70F8 /* UITextField+BlocksKit.h */; }; DB5C6C7C1C5200B200778E5F /* UITextView+BlocksKit.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DB5C6C4E1C52009700778E5F /* UITextView+BlocksKit.h */; }; DB5C6C7D1C5200B200778E5F /* UIView+BlocksKit.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DB4CA4A11B3A6657004B70F8 /* UIView+BlocksKit.h */; }; DB5C6C7E1C5200B200778E5F /* UIWebView+BlocksKit.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DB4CA4A31B3A6657004B70F8 /* UIWebView+BlocksKit.h */; }; @@ -368,7 +364,6 @@ DB5C6C781C5200B200778E5F /* UIImage+BlocksKit.h in CopyFiles */, DB5C6C791C5200B200778E5F /* UIImagePickerController+BlocksKit.h in CopyFiles */, DB5C6C7A1C5200B200778E5F /* UIPopoverController+BlocksKit.h in CopyFiles */, - DB5C6C7B1C5200B200778E5F /* UITextField+BlocksKit.h in CopyFiles */, DB5C6C7C1C5200B200778E5F /* UITextView+BlocksKit.h in CopyFiles */, DB5C6C7D1C5200B200778E5F /* UIView+BlocksKit.h in CopyFiles */, DB5C6C7E1C5200B200778E5F /* UIWebView+BlocksKit.h in CopyFiles */, @@ -454,8 +449,6 @@ DB4CA49C1B3A6657004B70F8 /* UIImagePickerController+BlocksKit.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImagePickerController+BlocksKit.m"; sourceTree = ""; }; DB4CA49D1B3A6657004B70F8 /* UIPopoverController+BlocksKit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIPopoverController+BlocksKit.h"; sourceTree = ""; }; DB4CA49E1B3A6657004B70F8 /* UIPopoverController+BlocksKit.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIPopoverController+BlocksKit.m"; sourceTree = ""; }; - DB4CA49F1B3A6657004B70F8 /* UITextField+BlocksKit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UITextField+BlocksKit.h"; sourceTree = ""; }; - DB4CA4A01B3A6657004B70F8 /* UITextField+BlocksKit.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UITextField+BlocksKit.m"; sourceTree = ""; }; DB4CA4A11B3A6657004B70F8 /* UIView+BlocksKit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+BlocksKit.h"; sourceTree = ""; }; DB4CA4A21B3A6657004B70F8 /* UIView+BlocksKit.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+BlocksKit.m"; sourceTree = ""; }; DB4CA4A31B3A6657004B70F8 /* UIWebView+BlocksKit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIWebView+BlocksKit.h"; sourceTree = ""; }; @@ -688,8 +681,6 @@ DB4CA49C1B3A6657004B70F8 /* UIImagePickerController+BlocksKit.m */, DB4CA49D1B3A6657004B70F8 /* UIPopoverController+BlocksKit.h */, DB4CA49E1B3A6657004B70F8 /* UIPopoverController+BlocksKit.m */, - DB4CA49F1B3A6657004B70F8 /* UITextField+BlocksKit.h */, - DB4CA4A01B3A6657004B70F8 /* UITextField+BlocksKit.m */, DB5C6C4E1C52009700778E5F /* UITextView+BlocksKit.h */, DB5C6C4F1C52009700778E5F /* UITextView+BlocksKit.m */, DB4CA4A11B3A6657004B70F8 /* UIView+BlocksKit.h */, @@ -902,7 +893,6 @@ DB4CA4421B3A662A004B70F8 /* NSMutableArray+BlocksKit.h in Headers */, DB4CA4DD1B3A6657004B70F8 /* UIBarButtonItem+BlocksKit.h in Headers */, DB4CA50F1B3A6720004B70F8 /* BlocksKit+QuickLook.h in Headers */, - DB4CA4FB1B3A6657004B70F8 /* UITextField+BlocksKit.h in Headers */, DB4CA4331B3A662A004B70F8 /* NSIndexSet+BlocksKit.h in Headers */, DBA576A41B3A7B9700E41A6B /* BKDefines.h in Headers */, DB4CA4B01B3A6657004B70F8 /* NSCache+BlocksKit.h in Headers */, @@ -1191,7 +1181,6 @@ DB4CA4EE1B3A6657004B70F8 /* UIImage+BlocksKit.m in Sources */, DB4CA5071B3A6657004B70F8 /* UIWebView+BlocksKit.m in Sources */, DB4CA4621B3A662A004B70F8 /* NSObject+BKBlockExecution.m in Sources */, - DB4CA4FD1B3A6657004B70F8 /* UITextField+BlocksKit.m in Sources */, DB4CA43A1B3A662A004B70F8 /* NSInvocation+BlocksKit.m in Sources */, DB4CA4DF1B3A6657004B70F8 /* UIBarButtonItem+BlocksKit.m in Sources */, DB4CA4711B3A662A004B70F8 /* NSSet+BlocksKit.m in Sources */, @@ -1347,7 +1336,6 @@ DB4CA4BD1B3A6657004B70F8 /* NSObject+A2BlockDelegate.m in Sources */, DB4CA4681B3A662A004B70F8 /* NSObject+BKBlockObservation.m in Sources */, DB4CA4DB1B3A6657004B70F8 /* UIAlertView+BlocksKit.m in Sources */, - DB4CA4FE1B3A6657004B70F8 /* UITextField+BlocksKit.m in Sources */, DB4CA4F91B3A6657004B70F8 /* UIPopoverController+BlocksKit.m in Sources */, DB5C6C521C52009700778E5F /* UITextView+BlocksKit.m in Sources */, DB4CA4771B3A662A004B70F8 /* NSTimer+BlocksKit.m in Sources */, diff --git a/BlocksKit/UIKit/UITextField+BlocksKit.h b/BlocksKit/UIKit/UITextField+BlocksKit.h deleted file mode 100644 index b5d0cb131..000000000 --- a/BlocksKit/UIKit/UITextField+BlocksKit.h +++ /dev/null @@ -1,69 +0,0 @@ -// -// UITextField+BlocksKit.h -// BlocksKit -// -// Contributed by Samuel E. Giddins. -// - -#import "BKDefines.h" -#import - -NS_ASSUME_NONNULL_BEGIN - -/** Block callbacks for UITextField. - - @warning UITextField is only available on a platform with UIKit. - - Created by [Samuel E. Giddins](https://github.com/segiddins) and - contributed to BlocksKit. - */ -@interface UITextField (BlocksKit) - -/** - * The block that fires before the receiver begins editing - * - * The return value indicates whether the receiver should begin editing - */ -@property (nonatomic, copy, nullable) BOOL(^bk_shouldBeginEditingBlock)(UITextField *textField); - -/** - * The block that fires after the receiver begins editing - */ -@property (nonatomic, copy, nullable) void(^bk_didBeginEditingBlock)(UITextField *textField); - -/** - * The block that fires before the receiver ends editing - * - * The return value indicates whether the receiver should end editing - */ -@property (nonatomic, copy, nullable) BOOL(^bk_shouldEndEditingBlock)(UITextField *textField); - -/** - * The block that fires after the receiver ends editing - */ -@property (nonatomic, copy, nullable) void(^bk_didEndEditingBlock)(UITextField *textField); - -/** - * The block that fires when the receiver's text will change - * - * The return value indicates whether the receiver should replace the characters in the given range with the replacement string - */ -@property (nonatomic, copy, nullable) BOOL(^bk_shouldChangeCharactersInRangeWithReplacementStringBlock)(UITextField *textField, NSRange range, NSString *string); - -/** - * The block that fires when the receiver's clear button is pressed - * - * The return value indicates whether the receiver should clear its contents - */ -@property (nonatomic, copy, nullable) BOOL(^bk_shouldClearBlock)(UITextField *textField); - -/** - * The block that fires when the keyboard's return button is pressed and the receiver is the first responder - * - * The return value indicates whether the receiver should return - */ -@property (nonatomic, copy, nullable) BOOL(^bk_shouldReturnBlock)(UITextField *textField); - -@end - -NS_ASSUME_NONNULL_END diff --git a/BlocksKit/UIKit/UITextField+BlocksKit.m b/BlocksKit/UIKit/UITextField+BlocksKit.m deleted file mode 100644 index ea936cd37..000000000 --- a/BlocksKit/UIKit/UITextField+BlocksKit.m +++ /dev/null @@ -1,120 +0,0 @@ -// -// UITextField+BlocksKit.m -// BlocksKit -// - -#import "UITextField+BlocksKit.h" -#import "A2DynamicDelegate.h" -#import "NSObject+A2DynamicDelegate.h" -#import "NSObject+A2BlockDelegate.h" - -#pragma mark Delegate - -@interface A2DynamicUITextFieldDelegate : A2DynamicDelegate - -@end - -@implementation A2DynamicUITextFieldDelegate - -- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField -{ - BOOL ret = YES; - id realDelegate = self.realDelegate; - if (realDelegate && [realDelegate respondsToSelector:@selector(textFieldShouldBeginEditing:)]) - ret = [realDelegate textFieldShouldBeginEditing:textField]; - BOOL (^block)(UITextField *) = [self blockImplementationForMethod:_cmd]; - if (block) - ret &= block(textField); - return ret; -} - -- (void)textFieldDidBeginEditing:(UITextField *)textField -{ - id realDelegate = self.realDelegate; - if (realDelegate && [realDelegate respondsToSelector:@selector(textFieldDidBeginEditing:)]) - [realDelegate textFieldDidBeginEditing:textField]; - void (^block)(UITextField *) = [self blockImplementationForMethod:_cmd]; - if (block) - block(textField); -} - -- (BOOL)textFieldShouldEndEditing:(UITextField *)textField -{ - BOOL ret = YES; - id realDelegate = self.realDelegate; - if (realDelegate && [realDelegate respondsToSelector:@selector(textFieldShouldEndEditing:)]) - ret = [realDelegate textFieldShouldEndEditing:textField]; - BOOL (^block)(UITextField *) = [self blockImplementationForMethod:_cmd]; - if (block) - ret &= block(textField); - return ret; -} - -- (void)textFieldDidEndEditing:(UITextField *)textField -{ - id realDelegate = self.realDelegate; - if (realDelegate && [realDelegate respondsToSelector:@selector(textFieldDidEndEditing:)]) - [realDelegate textFieldDidEndEditing:textField]; - void (^block)(UITextField *) = [self blockImplementationForMethod:_cmd]; - if (block) - block(textField); -} - -- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string -{ - BOOL ret = YES; - id realDelegate = self.realDelegate; - if (realDelegate && [realDelegate respondsToSelector:@selector(textField:shouldChangeCharactersInRange:replacementString:)]) - ret = [realDelegate textField:textField shouldChangeCharactersInRange:range replacementString:string]; - BOOL (^block)(UITextField *, NSRange, NSString *) = [self blockImplementationForMethod:_cmd]; - if (block) - ret &= block(textField, range, string); - return ret; -} - -- (BOOL)textFieldShouldClear:(UITextField *)textField -{ - BOOL ret = YES; - id realDelegate = self.realDelegate; - if (realDelegate && [realDelegate respondsToSelector:@selector(textFieldShouldClear:)]) - ret = [realDelegate textFieldShouldClear:textField]; - BOOL (^block)(UITextField *) = [self blockImplementationForMethod:_cmd]; - if (block) - ret &= block(textField); - return ret; -} - -- (BOOL)textFieldShouldReturn:(UITextField *)textField -{ - BOOL ret = YES; - id realDelegate = self.realDelegate; - if (realDelegate && [realDelegate respondsToSelector:@selector(textFieldShouldReturn:)]) - ret = [realDelegate textFieldShouldReturn:textField]; - BOOL (^block)(UITextField *) = [self blockImplementationForMethod:_cmd]; - if (block) - ret &= block(textField); - return ret; -} - -@end - -#pragma mark - Category - -@implementation UITextField (BlocksKit) - -@dynamic bk_shouldBeginEditingBlock, bk_didBeginEditingBlock, bk_shouldEndEditingBlock, bk_didEndEditingBlock, bk_shouldChangeCharactersInRangeWithReplacementStringBlock, bk_shouldClearBlock, bk_shouldReturnBlock; - -+ (void)load { - [self bk_registerDynamicDelegate]; - [self bk_linkDelegateMethods: @{ - @"bk_shouldBeginEditingBlock": @"textFieldShouldBeginEditing:", - @"bk_didBeginEditingBlock": @"textFieldDidBeginEditing:", - @"bk_shouldEndEditingBlock": @"textFieldShouldEndEditing:", - @"bk_didEndEditingBlock" : @"textFieldDidEndEditing:", - @"bk_shouldChangeCharactersInRangeWithReplacementStringBlock" : @"textField:shouldChangeCharactersInRange:replacementString:", - @"bk_shouldClearBlock" : @"textFieldShouldClear:", - @"bk_shouldReturnBlock" : @"textFieldShouldReturn:", - }]; -} - -@end