26 August 2014 0min read

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 enjoyed this post

Continue reading