Alexito's World

A world of coding 💻, by Alejandro Martinez

Swift protocols are not Objective-C protocols

For now, the Siwft and Objective-C protocols are two diferent things. The biggest differences is that Swift protocols can have structs and enums and can be adopted by value types.

This makes a huge diffrence when you try to do things like this:

extension Array : UITableViewDataSource {
    func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int {
        return count

    func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
        return ...

This throws a compiler error because Array is a struct and value types cannot adopt Objective-C protocols. So this handy feature that we have on our codebase cannot be ported directly to Swift.

If you liked this article please consider supporting me