performSelector may cause a leak because its selector is unknown

后端 未结 19 2460
小蘑菇
小蘑菇 2020-11-22 01:54

I\'m getting the following warning by the ARC compiler:

\"performSelector may cause a leak because its selector is unknown\".

Here\'s what

19条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-22 02:28

    You could also use a protocol here. So, create a protocol like so:

    @protocol MyProtocol
    -(void)doSomethingWithObject:(id)object;
    @end
    

    In your class that needs to call your selector, you then have a @property.

    @interface MyObject
        @property (strong) id source;
    @end
    

    When you need to call @selector(doSomethingWithObject:) in an instance of MyObject, do this:

    [self.source doSomethingWithObject:object];
    

提交回复
热议问题