Open in app

Sign In

Write

Sign In

Toby O'Connell
Toby O'Connell

60 Followers

Home

About

Published in CodeX

·Sep 19, 2022

Why structs are better than protocols for dependency inversion

When we think of dependency inversion in Swift, protocols are usually the first thing that come to mind. The well known pattern is to create a protocol that defines some required behaviour and create a concrete implementation that performs that responsibility. This becomes invaluable when testing our code as we…

Dependency Injection

3 min read

Why structs are better than protocols for dependency inversion
Why structs are better than protocols for dependency inversion
Dependency Injection

3 min read


Published in CodeX

·Apr 12, 2022

The importance of logical data modelling

As an iOS developer, I am forever shocked at how often I see fatalError(“This should never happen”) in production code. This usually arises in situations where an edge case is programatically possible, but logically impossible. The scenario Imagine a situation where I’d like an app to catalog the CDs and books on…

Struct

2 min read

The importance of logical data modelling
The importance of logical data modelling
Struct

2 min read


Published in CodeX

·Apr 10, 2022

Fun with Natural Language Processing

I’ve recently discovered Apple’s Natural Language framework and decided to have a play, test out some ideas and share my findings. This will be a short article about a few things the framework can do and potentially offer some inspiration for your own apps I started with UITextChecker. As the…

Swift

2 min read

Fun with Natural Language Processing
Fun with Natural Language Processing
Swift

2 min read


Published in CodeX

·Oct 22, 2021

Swift + C: Callback Interoperability

Background A very common pattern across programming languages is the use of callback functions. A callback function is a reference to executable code passed as an argument to other code, allowing it to be executed at a later time. In swift we encounter this patten often. One particularly common example is…

Swift

3 min read

Swift + C: Callback Interoperability
Swift + C: Callback Interoperability
Swift

3 min read


Aug 28, 2021

Tuple splatting in Swift

What Is Splatting? Argument splatting is the concept of extracting the parameters of an object to pass to a function automatically. In Swift this can be done using tuples. Suppose we had some data and a function that looked like this: We’d like to pass all our users through the makeGreeting function…

Swift

2 min read

Tuple splatting in Swift
Tuple splatting in Swift
Swift

2 min read


Published in CodeX

·Jul 24, 2021

Enums Cases as Protocol Witnesses and the Open-Closed Principle

Background Recently I have been implementing a lot of analytics events in a client’s app. Tagging this application (which has a great deal of UI) was always going to a laborious task, so I was looking to architect an ergonomic API to interact with. Whilst deciding on the interface I remembered…

Enum

2 min read

Enums Cases as Protocol Witnesses and the Open-Closed Principle
Enums Cases as Protocol Witnesses and the Open-Closed Principle
Enum

2 min read


Published in CodeX

·Mar 26, 2021

Encoding awkward types with minimal boilerplate using `withUnsafeBytes`

History For many years now, the go-to way of encoding and decoding Swift types to JSON has been the Codable protocol. This gave a more type safe way of handling json than its predecessor JSONSerialization, which spat out [String: Any] dictionaries. Conversely Codable handles conversion upfront, dealing with all the type…

Json

2 min read

Encoding awkward types with minimal boilerplate using `withUnsafeBytes`
Encoding awkward types with minimal boilerplate using `withUnsafeBytes`
Json

2 min read


Published in CodeX

·Mar 20, 2021

Using tuples for Comparable and Equatable conformance

Recently I discovered that tuples can be used to easily and simply compare and equate multiple variables. Take for example the implementation of Date and Comparable taken from the Swift documentation: This compares the year, month and day in that order to determine which is greater…

Tuples

1 min read

Tuples

1 min read


Published in CodeX

·Mar 7, 2021

UIGestureRecognizer with closures

One of the biggest downsides to UIGestureRecognizer is the inability to attach simple closures in-line. To use them, a target object must be specified alongside a Selector pointing to a function to call. One major disadvantage to this paradigm is that UIGestureRecognizer only passes the calling object to the called…

Uigesturerecognizer

1 min read

Uigesturerecognizer

1 min read


Published in CodeX

·Feb 17, 2021

Coordinators, the back button problem and a simple way to fix it

Background The Coordinator pattern has become increasingly popular recently in handling navigation through an iOS apps without tightly coupling different view controllers. There are a number of great articles that explain the various flavours of the pattern fantastically, so I’ll not rehash the same detail again. There is, however, one area…

Swift

2 min read

Swift

2 min read

Toby O'Connell

Toby O'Connell

60 Followers

Swift / iOS developer - I write about things that I find interesting or innovative.

Following
  • Alessandro Manilii

    Alessandro Manilii

  • Lee Kah Seng

    Lee Kah Seng

  • Adi Mizrahi

    Adi Mizrahi

  • Amisha I

    Amisha I

  • Albert Montserrat Gambus

    Albert Montserrat Gambus

See all (53)

Help

Status

Writers

Blog

Careers

Privacy

Terms

About

Text to speech