performSelector with more than 2 objects

前端 未结 3 1505
旧时难觅i
旧时难觅i 2020-12-23 16:45

Is there a way to call [anObject performSelector]; with more than 2 objects? I know you can use an array to pass multiple arguments, but I was wondering if there was a lowe

3条回答
  •  攒了一身酷
    2020-12-23 17:01

    An additional option, when you require to send multiple objects with performSelector is (if it's easy enough to do) to amend the method you wish to call to take an NSDictionary object instead of multiple parameters, as you'll be able to send as many as you like within the dictionary.

    For example

    I had a method similar to this which had 3 arguments and I needed to call it from performSelector -

    -(void)getAllDetailsForObjectId:(NSString*)objId segment:(Segment*)segment inContext:(NSManagedObjectContext*)context{
    

    I changed this method to make use of a dictionary to store the arguments

    -(void)getAllDetailsForObject:(NSDictionary*)details{
    

    therefore I was able to call the method easily

    [self performSelector:@selector(getAllDetailsForObject:) withObject:@{Your info stored within a dictionary}];
    

    Thought I'd be as well sharing this as an alternative option as it works for me.

    Cheers

提交回复
热议问题