3

I have a block with setter:

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

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

I have to use setter and there is no option to skip it. How can I access UIControlEvents parameter..?

Nat
  • 12,032
  • 9
  • 56
  • 103

1 Answers1

0

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

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

However, you won't be able to access any particular UIControlEvents parameter as you requested because you're the one providing it. The action block takes the UIControlEvents value as an argument, so it won't be there within the block. Calling the action block with your UIControlEvents parameter might look something like this:

- (void)handleControlEvents:(UIControlEvents)events {
    if (self.action) self.action(events)
}
Logan
  • 52,262
  • 20
  • 99
  • 128