相关疑难解决方法(0)

NSInvocation getReturnValue:在forwardInvocation内调用:使返回的对象调用dealloc:

test.m是我用来测试行为的独立文件.

编译:clang test.m -o test.app -fobjc-arc -ObjC -framework Foundation.确保已安装Xcode命令行工具.

#import <Foundation/Foundation.h>

@protocol Protocol

@optional
- (id)objProxyMethod;

@end

@interface ReturnObject: NSObject

@end

@interface Test : NSObject <Protocol>

@end

@interface Proxy : NSObject <Protocol>

- (id)objProxyMethod;

@end

@implementation ReturnObject

- (void)dealloc {
    NSLog(@"ERROR:");
    NSLog(@"I'm getting deallocated!");
    NSLog(@"This shouldn't happen!");
}

- (NSString *)description {
    return @"Blank object!";
}

@end

@implementation Proxy

- (id)objProxyMethod {
    NSLog(@"in [Proxy objProxyMethod]!");
    return [[ReturnObject alloc] init];
}

@end

@implementation Test

- (void)forwardInvocation:(NSInvocation *)invocation …
Run Code Online (Sandbox Code Playgroud)

objective-c nsinvocation

6
推荐指数
1
解决办法
3471
查看次数

标签 统计

nsinvocation ×1

objective-c ×1