Skip to content

Syntax Comparison #1: tableView:didSelectRowAtIndexPath: #1

@KevinVitale

Description

@KevinVitale

Thought it would be valuable to give a comparison of common patterns in Cocoa (Touch).

Objective-C

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [self.navigationController pushViewController:({
        UIViewController *viewController    = UIViewController.new;
        viewController.view.backgroundColor = UIColor.blueColor;
        viewController;
    })
                                         animated:YES];
}

Swift

override func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!)  {
    self.navigationController.pushViewController(({
        () -> UIViewController? in
        var viewController = UIViewController()
        viewController.view.backgroundColor = UIColor.whiteColor()
        return viewController
        })(),
        animated: true)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions