Connected2.me Jan 28, 2019

A Swift Journey Episode 1: Generic Protocols in Action

Article Summary

Engin Deniz Usta from Connected2me shows how generic protocols can eliminate boilerplate code that iOS developers write dozens of times per project. No more casting, no more repetitive XIB and Storyboard initialization.

This is the first episode in a series documenting Connected2me's iOS architecture journey. Usta tackles a common pain point: the verbose, error-prone code needed to instantiate ViewControllers and Views from XIBs and Storyboards. He demonstrates how Swift's protocol-oriented programming with Self types creates elegant, reusable solutions.

Key Takeaways

Critical Insight

Protocol-oriented programming transforms verbose ViewController instantiation into single-line calls without casting or repetitive parameters.

The article hints at more advanced generic protocol patterns coming in future episodes, including something involving snakes (Python integration, perhaps?).

About This Article

Problem

iOS developers spend a lot of time writing repetitive initialization code for ViewControllers and Views loaded from XIBs and Storyboards. They have to manually cast types, pass hardcoded bundle parameters, and make sure nib names match class names across different projects.

Solution

Engin Deniz Usta created generic protocols with Self types that automatically figure out class names and remove the need for optional parameters. Developers can now replace long initialization calls with a single loadFromNib() method.

Impact

Any ViewController or UIView can now conform to NibInitiable or StoryboardInitiable protocols without writing any implementation code. This cuts boilerplate from multiple lines down to a single call, with no casting or repeated parameters needed.

Recent from Connected2.me

Related Articles