DEVELOPMENT NOTES · 15 articles

Swift & runtime

From Swift 2 and Swift 3 notes to the Objective-C runtime and design patterns, these articles preserve the process of understanding language behaviour. Syntax changes; asking why a piece of code executes this way is still useful.

How to read this collection

  1. Start with delegation, blocks and common Swift pitfalls. Distinguish values, references, closure captures and object lifetimes.
  2. For runtime articles, work through properties and ivars, messaging, then dictionary-to-model conversion. Separate what the runtime can do from what your project actually needs.
  3. Compare templates, singletons, flyweights and responsibilities against a concrete duplication or shared-state problem before choosing a pattern.

These notes date from 2015–2017. Their examples have not been rerun for this archive update. Check the dates and version notes before applying the ideas to a current project.

Articles in this topic

15 articles · newest first
  • Bitwise Operations in iOS

    Introduces bitwise AND, OR, XOR, and NOT, using packed RGBA colors and state flags as examples. It then explains how enumerations and masks can store and query several states together.

    Sindribitwise operations · bit masks · RGBA
  • Balancing Code Responsibilities in iOS

    Uses an example project to examine oversized MVC controllers and the responsibilities of views, models, and controllers. It extracts repeated logic and reassigns functionality, emphasizing clear ownership of code before switching architecture labels.

    SindriMVC · separation of responsibilities · refactoring
  • Swift 3.0 Design Patterns: Singleton

    Introduces the uses and trade-offs of Swift singletons, creating shared instances with a static class constant or a global constant. It covers private initializers, access across modules, and the need to consider thread safety for shared mutable state.

    SindriSwift 3.0 · singleton pattern · static let
  • Swift 3.0 Design Patterns: Flyweight

    Introduces the flyweight pattern through shared local-data managers. A dictionary reuses loaded data and tracks usage counts; unused data is saved and released. The example contrasts this lifecycle with a singleton that remains in memory.

    SindriSwift 3.0 · flyweight pattern · object reuse
  • Protocols and Delegation in iOS

    Uses UITableView and custom controls to distinguish protocols from delegation. It compares delegate and block callbacks, then discusses how data sources and protocol abstractions can reduce coupling between objects.

    Sindriprotocol · delegate · block
  • Objective-C Runtime in Practice: Mapping Dictionaries to Models

    Moves from manual assignment, KVC, and third-party model libraries to an NSObject category that traverses runtime information and maps dictionaries to models. It also defines the example's support for two levels of nested data.

    BisonObjective-C Runtime · dictionary-to-model mapping · KVC
  • Decoupling iOS Views from Concrete Model Types

    Uses several types of ticket data with different fields but similar presentation needs to explore a dictionary-backed approach. A protocol exposes common display properties, reducing cells' and controllers' dependence on specific models and clarifying where data conversion belongs.

    Sindriprotocols · model decoupling · MVC
  • Swift in practice: the template pattern

    Uses product data and calculations to examine code that depends on a tuple's structure. Types and protocols then organise reusable processing, showing how abstraction can reduce coupling between parameter formats and business methods.

    SindriSwift · template pattern · protocols
  • Reading the Objective-C runtime source to understand messaging

    Uses an unrecognized selector error to introduce Objective-C messaging, examining method lookup, caching and forwarding in the source. Runtime examples then explain how a method call is resolved during execution.

    SindriObjective-C Runtime · message sending · method cache
  • Objective-C runtime in practice: changing fonts throughout an interface

    Starts with registering a custom font and finding its name, then uses Objective-C runtime techniques to replace interface fonts. It discusses the differences between controls created in code and those loaded from a storyboard when applying a common setting.

    HenryChengObjective-C Runtime · custom fonts · UIFont
  • Understanding blocks in iOS development

    Starts with block declarations and calls, then examines captured variables and callback wrappers. Examples modelled on Swift's higher-order functions demonstrate how blocks can be used to process data in Objective-C.

    Sindriblock · variable capture · Objective-C
  • iOS refactoring notes: Extract Method

    Applies the Extract Method technique from Refactoring to split long stretches of code into functions organised by intent. Parameters, local variables and return values are handled step by step, with examples showing how to reduce repetition and improve readability.

    SindriLinrefactoring · Extract Method · function extraction
  • Seven Swift pitfalls and how to avoid them

    Uses code examples to investigate surprising behaviour in protocol extensions, optional-chain assignment and functional processing. It compares dispatch for value and reference types and explains how code can compile successfully while producing an unexpected result.

    bestswifterSwift · protocol extensions · optional chaining
  • Inside KVO on iOS

    Starts with observing a list's scroll offset, then examines the dynamic subclass and isa-pointer changes caused by registering an observer. Runtime functions are used to attempt a similar mechanism, connecting practical KVO usage with its underlying behaviour.

    SindriLinKVO · isa · dynamic subclasses
  • Objective-C runtime fundamentals: properties and instance variables

    Distinguishes Objective-C properties from instance variables, examining runtime structures, memory offsets and synthesize to explain how properties are generated. Examples then show why dynamically inspecting and manipulating an object's structure can be useful.

    SindriLinObjective-C Runtime · property · ivar