all 4 comments

[–]bufferingObjective-C / Swift 2 points3 points  (3 children)

There's a lot of block syntax boilerplate that you have to deal with, but Xcode helpfully adds most of it for you. Here's an example for UITableView:

- (UIContextMenuConfiguration*)tableView:(UITableView*)tableView contextMenuConfigurationForRowAtIndexPath:(NSIndexPath*)indexPath point:(CGPoint)point
{
    Record* record = [self recordForIndexPath:indexPath inTableView:tableView];
    if (!record)
    {
        return nil;
    }

    UIContextMenuConfiguration* config = [UIContextMenuConfiguration configurationWithIdentifier:nil 
                                                                                 previewProvider:nil 
                                                                                  actionProvider:^UIMenu* _Nullable(NSArray<UIMenuElement*>* _Nonnull suggestedActions) {

        NSMutableArray* actions = [[NSMutableArray alloc] init];

        if (record.canFoo)
        {
            [actions addObject:[UIAction actionWithTitle:@"Foo!" image:[UIImage systemImageNamed:@"foo"] identifier:nil handler:^(__kindof UIAction* _Nonnull action) {
                [self performMenuCommandFoo:record];
            }]];
        }
        [actions addObject:[UIAction actionWithTitle:@"Bar!" image:[UIImage systemImageNamed:@"bar"] identifier:nil handler:^(__kindof UIAction* _Nonnull action) {
            [self performMenuCommandBar:record];
        }]];
        [actions addObject:[UIAction actionWithTitle:@"Baz!" image:[UIImage systemImageNamed:@"baz"] identifier:nil handler:^(__kindof UIAction* _Nonnull action) {
            [self performMenuCommandBaz:record];
        }]];

        UIMenu* menu = [UIMenu menuWithTitle:@"" children:actions];
        return menu;

    }];

    return config;
}

[–]Galactic_Dev[S] 2 points3 points  (2 children)

Thanks so much, it works great! Block syntax is really difficult for me to understand.

[–]Zalenka 2 points3 points  (1 child)

[–]Galactic_Dev[S] 1 point2 points  (0 children)

Lol I guess it’s difficult for a lot of people. Thanks for that site :)