Alejandro Martinez

BlogPodcastPortfolio Youtube

26 August, 2014Development🕐 1min 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 have any feedback you can reach me at alexito4

Refactoring — Not on the backlog! | xProgramming.comSwift extensions and inheritance

Alejandro Martinez
alexito4@gmail.com

Buka pintu

alexito4
alexito4