Keep blocks inside a dictionary

后端 未结 4 543
不知归路
不知归路 2020-12-14 11:00

I have my own method that takes a block as an argument. I want to keep track of that block inside an NSDictionary. What is the best way to add the block to the dictionary?

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-14 11:29

    If you are using ARC, use -copy:

     void (^handlerCopy)(NSURLResponse*, NSData*, NSError*) = [handler copy];
     [dict setObject:handlerCopy forKey:@"foo"];
    

提交回复
热议问题