Skip to content

Instantly share code, notes, and snippets.

@pookjw
Last active September 4, 2023 02:03
Show Gist options
  • Save pookjw/dfd2d018f143885e18a1718697b87b0e to your computer and use it in GitHub Desktop.
Save pookjw/dfd2d018f143885e18a1718697b87b0e to your computer and use it in GitHub Desktop.
#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