Last active
September 4, 2023 02:03
-
-
Save pookjw/dfd2d018f143885e18a1718697b87b0e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Cocoa/Cocoa.h> | |
NS_HEADER_AUDIT_BEGIN(nullability, sendability) | |
@class SVTextField; | |
@protocol SVTextFieldDelegate <NSTextFieldDelegate> | |
@optional - (BOOL)textField:(SVTextField *)textField shouldChangeTextInRange:(NSRange)range replacementString:(NSString *)string; | |
@end | |
@interface SVTextField : NSTextField | |
@end | |
NS_HEADER_AUDIT_END(nullability, sendability) | |
#import "SVTextField.hpp" | |
#import <objc/message.h> | |
@implementation SVTextField | |
- (BOOL)textView:(NSTextView *)textView shouldChangeTextInRange:(NSRange)range | |
replacementString:(NSString *)string { | |
if ([self.delegate respondsToSelector:@selector(textField:shouldChangeTextInRange:replacementString:)]) { | |
return [static_cast<id<SVTextFieldDelegate>>(self.delegate) textField:self shouldChangeTextInRange:range replacementString:string]; | |
} else { | |
objc_super superInfo = { self, [self superclass] }; | |
return reinterpret_cast<BOOL (*)(objc_super *, SEL, id, NSRange, id)>(objc_msgSendSuper)(&superInfo, _cmd, textView, range, string); | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment