Swift

About Code written in Swift. My open source Swift projects are available at code.knabel.dev/swift-lang.

NSDataAsset reduces Code signing overhead  — 

I had completely forgotten about NSDataAsset. Maybe I should move some of my JSON files into asset catalogs. According to @emergetools that should remove some code signing overhead from the app size.

Read »
Attaching to UIScrollView's parent with Auto Layout  — 

When using auto layout with a UIScrollView, subviews may not attach to the top edge of the scroll view’s parent. Else you cannot scroll, but the handle shrinks the more you scroll.

Read »
SwiftPM can detect breaking api changes  — 

Starting with Swift 5.6 the Swift Package Manager can automatically detect Breaking API changes. Really great for libs!

Read »
Missing Async XCTests on Linux  — 

Async tests do not work on Linux, only on macOS. Instead you need to implement a helper function that runs the test async by relying on expectations.

Read »
WKWebView Configuration Cookies not working  — 

Cookies in WKWebView are broken. When manually setting a Cookie using the Configuration, it will be ignored by the web view.

Read »
Swift custom table of contents lib  — 

If the default Table Of Contents / Index Set for iOS does not fit your use cases. This library might be interesting:

Read »
Debugging Swift in VS Code in 2022  — 

Back in 2019 I wrote an article about how to debug your Swift Package Manager projects in Visual Studio Code. In late december 2021, the Swift Server Working group released a brand new extension for vscode, which dramatically improves debugging your Swift code. Especially for linux! Time for an update!

Read »
UINavigationBar black after Xcode 13 upgrade  — 

In case your UINavigationBar has been set to a custom color and the navigation bar is not translucent, you will experience a visual regression when updating to Xcode 13. The navigation bar background will be black - until you start scrolling. Then it behaves as expected.

Read »
Adopting Swift Async Await in Vapor  — 

A few months ago Swift 5.5 has been released and made async/await available. And in 4.50.0 Vapor added support for it, too!

Read »
Converting simple iOS apps to tvOS is easy!  — 

Converting a simple and small iOS app was far easier than expected. Of course webviews, gesture recognizers, navbars, etc. are not supported or work differently, but at a first glance there are not a lot parts with visual regressions!

UIApplication.shared not in Extensions  — 

UIApplication.shared isn’t available within an iOS app extension. To annotate your code paths not needed in an extension, but using UIApplication.shared, just use the @available(iOSApplicationExtension, unavailable) annotation.

Read »
Static Table enums  — 

Using enums in Swift for static Table View Data Sources is really great. Especially when declaring them as enum X: Int and using the rawValue to reflect the section or row index.

Read »
SwiftGen has evolved!  — 

I haven’t used SwiftGen for a long time, but wow, it has improved a lot. I am a bit impressed.

iOS apps require account deletion  — 

Since WWDC21 all iOS apps that provide registration are also required to provide the deletion of those accounts.

Swift and Firebase  — 

Nothing especially new here, but a reminder: Firebase might be a good choice if you need realtime updates.

Read »
SwiftUI @main AppDelegate  — 

When using @main on a SwiftUI.App and @UIApplicationDelegateAdaptor(AppDelegate.self) you can still have an AppDelegate without handling SwiftUI manually as without @main.

Read »
Updating Bitrise binary uploads  — 

Bitrise binary uploads cannot be updated after saving. Instead they need to be deleted and recreated. Thus all workflow steps need to be updated if they rely on the data.

Read »
Localization order  — 

When maintaining multiple locales within your project, try to keep line numbers consistent across all locales. Also keep the order of translations consistent.

Read »
SwiftUI translations and UIKit  — 

Nothing new today, but a quick reminder:

Read »
Localizcable vs Swift unicode escapes  — 

Localizable.strings doesn’t support unicode \unnnn escapes, but only \Unnnn! In Swift the \U is for UTF-16 escapes like \Unnnnnnnn.

NSDataDetector  — 

How to detect a URL in a String using NSDataDetector - free Swift 5.1 example code and tips https://www.hackingwithswift.com/example-code/strings/how-to-detect-a-url-in-a-string-using-nsdatadetector

Coordinator [unowned self]  — 

An [unowned self] in a Coordinator is okay.

Read »
Fucking SwiftUI  — 

This cheat sheet is actually not bad!

Read »
Missing UIView animation delay  — 

UIView animate does not delay if there are no changes.

Read »
SwiftUI random colors  — 

When setting the background color randomly in SwiftUI, you will be able to detect every single repaint! Might be helpful while debugging.

Read »
UICollectionViewCell alpha  — 

Wnat your UICollectionViewCell transparent? Set alpha on contentView! => Setting alpha on the UICollectionViewCell itself doesn’t work.

UIImageView is not animatable  — 

UIImageView image is not animatable. Instead use transitions!

Swift Coverage for VS Code  — 

When developing Swift in Visual Studio Code there were a few cases, where I preferred Xcode. Beside the obvious cases like iOS Development, managing certificates and provisioning profiles, there was one big case left: Writing unit tests.

Read »
Upgrading a server-side Swift project to Vapor 4  — 

The past few days I created a new server using Vapor and hit vapor new <project> --auth which created a Vapor 3 server. Later I upgraded the young project to Vapor 4, but found some lack of practical information about the upgrade on the internet. So here I share my subjective experience and try to give you some tips.

Read »
Swift, VS Code and you  — 

Editors like Visual Studio Code live from a wide range of extensions and customization. In contrast there are IDEs like Xcode and AppCode, which have everything set up and are ready to go. In order to provide a rich set of features, they cannot not offer the same level of flexibility. Which editor you might want to use is a highly personal decision.

Read »
Debugging Swift in VS Code the old way  — 

Running and debugging your targets in Visual Studio Code is not prepared by default. Especially for us Swift developers this might come unexpected, especially in comparison to Xcode. In VS Code we require extensions and configs for this purpose.

Read »
InferIt: a Constraint Solving Package Manager  — 

The initial idea behind InferIt was to create some mixture of a constraint solver and a dependency manager: you would just tell it what to install and it would gather as much information as possible to install it.

Read »
ReactifSwift: async function composition  — 

Async operators debounce, throttle or delay that functional reactive programming libraries as RxSwift and ReactiveSwift provide are super useful and expressive. Though their biggest benefit lays within composability.

Read »
Swifducks: simple Redux store with multiple reducers  — 

A simple example implementation of the Redux pattern with multiple reducers and listeners.

Read »
Archery 0.3.0 released  — 

Archery is about doing something with your project’s metadata. The new version 0.3.0 puts everything on steroids and allows you to script your metadata. A detailed overview of all changes can be found on GitHub.

Read »
Apple’s SourceKit LSP and SDE Roadmap  — 

Apple recently announced to develop a language server for Swift and C-family languages. Or said more clearly: Apple started development to support every editor implementing the language server protocol like VS Code, Sublime Text, Jet Brains‘ IDEs and Atom.

Read »
ArgumentOverture  — 

A Swift Playground aiming to provide some functional helpers to parse arguments for command line tools. It uses Overture and is build for high composability, flexibility and little impact on your project’s freedom to evolve.

Read »
CommandMine  — 

Command mine is a concept of a swift library for parsing command line arguments. It is designed to support asynchronous implementations of CLIS, that may even be used inside frameworks.

Read »
Why I created Rock for Swift CLIs  — 

I excessively make use of the official Swift Package Manager as I usually do some CLIs or other stuff. For this use case it is really great. When developing Apps, Carthage and CocoaPods come in handy, which are great, too. For Web Development there are yarn and NPM, which support project based and global installs. Then there are gem (global) and bundler (project) for ruby based dependencies.

Read »