Может NSProxy заменять подклассы NSView? - PullRequest
0 голосов
/ 08 июня 2019

Я пробовал простой тест, который приводит к ошибке EXC_BAD_ACCESS:

#import "AppDelegate.h"

@interface CrashingProxy : NSProxy
@property (strong) id target;
- (instancetype)initWithTarget:(id)targetObj;
@end

@implementation CrashingProxy
@synthesize target;
- (instancetype)initWithTarget:(id)targetObj {
    [self setTarget:targetObj];
    return self;
}
- (void)forwardInvocation:(NSInvocation *)invocation {
    [invocation invokeWithTarget:[self target]];
}
- (NSMethodSignature *)methodSignatureForSelector:(SEL)selector {
    return [[self target] methodSignatureForSelector:selector];
}
@end

@interface AppDelegate ()
@property (weak) IBOutlet NSWindow *window;
@end

@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    NSButton *button = [[NSButton alloc] initWithFrame:NSMakeRect(20.0, 20.0, 100.0, 32.0)];
    [button setButtonType:NSButtonTypeMomentaryLight];
    [button setTitle:@"Hello"];
    [[[self window] contentView] addSubview:[[CrashingProxy alloc] initWithTarget:button]];
}
@end

Что-то не так с этим тестом, или есть фундаментальная причина, по которой подклассы NSView нельзя использовать с NSProxy?

Сведения об ошибке:

Тема 1: EXC_BAD_ACCESS (код = 1, адрес = 0xc) в [NSView addSubview:]

...