Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 调用超级块/扩展块_Objective C_Subclass_Objective C Blocks - Fatal编程技术网

Objective c 调用超级块/扩展块

Objective c 调用超级块/扩展块,objective-c,subclass,objective-c-blocks,Objective C,Subclass,Objective C Blocks,我已经对一个类进行了子类化,它拥有一个block属性,我需要扩展它 超类的属性: @property (nonatomic, copy) id (^willMapDeserializedResponseBlock)(id deserializedResponseBody); 每次设置此块时,我都需要用自己的代码/块扩展该块 基本上这就是我想在我的子类中做的: [self setWillMapDeserializedResponseBlock:^id(id deserializedRespons

我已经对一个类进行了子类化,它拥有一个block属性,我需要扩展它

超类的属性:

@property (nonatomic, copy) id (^willMapDeserializedResponseBlock)(id deserializedResponseBody);
每次设置此块时,我都需要用自己的代码/块扩展该块

基本上这就是我想在我的子类中做的:

[self setWillMapDeserializedResponseBlock:^id(id deserializedResponseBody) {

    // original block

    // do my own stuff 

    return deserializedResponseBody;
}];
我如何实现这样的东西?
我发现了一个类似问题的解决方案,但它对我没有帮助,可能是因为块的返回值?

不,您不能向现有块添加代码,但您可以根据链接的问题轻松调整解决方案:

- (void)setWillMapDeserializedResponseBlock:(id(^)(id))willMapDeserializedResponseBlock
{
    id (^additionalCode)(id, id) = ^id (id deserializedResponseBody, id originalReturnVal){
        // Do your own stuff
        return whatever;
    };

    id (^newWillMapBlock)(id) = ^id (id deserializedResponseBody){
        id retVal = willMapDeserializedResponseBlock(deserializedResponseBody);
        return additionalCode(deserializedResponseBody, retVal);
    };

    _willMapDeserializedResponseBlock = newWillMapBlock;
}

超级班怎么会有积木呢?请提供调用此方法的一些示例用法。在您的想法中,谁将接收返回的
反序列化响应体
?@Droppy超类本身也会设置此块,并有自己的实现,但我需要添加一些自己的内容。请提供更多代码/类定义以澄清。好,也许我表达了自己的错误,在setter方法中运行块不是很少见吗?我可以这么说,但是这里没有调用任何块。非常感谢,我稍微修改了代码,但它工作起来很有魅力!