de en es fr nl pl pt sv zh

swift

Handling unknown enum cases

5sw.de

Even though they are sometimes overused, enums are still a great tool. Thanks to Codable they can easily be decoded from JSON sent by your backend. This is great until you need to add a new case to the enum. Then you have to either deal with versioning your API or you need to tell your users...

Enum or struct?

5sw.de

I often see a pattern where there is an enum with a bunch of computed properties that return a different value for each case. In the rest of the code base then only those properties are used. Something like this: enum Style { case headline case bodyText case emphasis var...

Automatic builders

5sw.de

While investigating the new AttributedString API I realized you could use the same techniques to build a generic fluid builder interface for any type. This is what I came up with: And here is an example how you can use it:

New attributed strings

5sw.de

Finally we are going to get attributed strings as a native Swift value type. So lets see how we can update the example of my last article about attributed strings: let string = "Name (whatever)" var attributed = AttributedString(string) let nameEnd = attributed.range(of: " (")?.lowerBound ??...

Traits of a good accessible iOS app

Daniel Devesa Derksen-Staats

You may know that you can configure a UI component with an accessibility label. The accessibility label is the name of the component. You can also configure an accessibility trait. The accessibility trait is the role of the component, it gives the user information on how they can interact with it....

Tips for testing your iOS app’s accessibility

Daniel Devesa Derksen-Staats

The cycle for creating great accessible apps starts and ends with testing. Sure, it is always better to get feedback from users to create an experience that holds up to their expectations. But that’s not always possible. Till you can do it, I think the way to go is to do your best. Build it as...

Quick Notes about How Apple Silicion Impacts Swift Developers

Fernando Castor

New Macs will use Apple-developed processors, not Intel. This new architecture has been named Apple silicon. Initial Developer Transition Kits (DTKs) are ready to be shipped to developers. They will pack the A12Z processor of the iPad Pro. Many apps are already being ported to leverage Apple...

Attributed Strings

5sw.de

I had to take a string like “Name (whatever)” and display it in a label. The Name part should be bold, and anything in parentheses should use the regular font. Pretty simple, I just put the string in a NSAttributedString, find the opening parenthesis and add a bold font attribute to everything up...

Factories and Protocol Composition DI

5sw.de

Especially on iOS it’s often necessary to create new objects like new view controllers or such things. This often cannot be avoided. This usually is solved by having the object that creates new objects also require all the dependencies of the objects it wants to create. This of course is not a...

Protocol Composition and Dependency Injection

5sw.de

I recently read the article “Using protocol composition for dependency injection” by Krzysztof Zabłocki. I found this to be a rather interesting technique for doing DI, but when trying to implement it I found it somewhat limited: It doesn’t really handle dependencies that have dependencies...