Block property with parameters and setter

I have a block with an installer:

@property (nonatomic, copy) void (^action)(UIControlEvents);

- (void)setAction:(void (^)(UIControlEvents))action {
    // ?
}

      

I need to use a setter and there is no way to skip it. How can I access the UIControlEvents .. parameter?

+3


source to share


1 answer


You can set a block property by filling your setter like this:

- (void)setAction:(void (^)(UIControlEvents))action {
    _action = action;
}

      



However, you will not be able to access any particular parameter UIControlEvents

as you have requested it, because you are providing it. The block action

takes a value UIControlEvents

as an argument, so it won't be inside the block. Calling an action block with a parameter UIControlEvents

might look something like this:

- (void)handleControlEvents:(UIControlEvents)events {
    if (self.action) self.action(events)
}

      

0


source







All Articles