Connecting Siri to Custom Intents in SwiftUI

Making a custom intent for Siri is pretty simple and there are some good articles on it out there but when I followed them it wasn’t working for me. Specifically asking Siri or invoking a shortcut was returning an error and my Intent handler wasn’t being called. The answer turned out to be really simple once I knew what I was doing. Hopefully this helps someone else. Creating the intent For SwiftUI this article is a good walk through, the Apple documentation is also good. What was missing for me is how Siri knows to invoke your extension in a [Read on…]

Simple HTML Parsing in Swift

I needed to parse some HTML in a SwiftUI project so I could put the content into a Text view. I couldn’t use the HTML partly because of weird behaviour in WKWebView but that’s for another post. This is was a simple case, I didn’t need any structure information from the HTML, just the text with the tags removed. Parsing HTML is always a bit evil so I tend to look for built-in services that can do it for me. Here’s what I found. Using NSAttributedString to load HTML Turns out that NSAttributedString has a way to directly load HTML [Read on…]

Missing argument in SwiftUI ForEach

I’ve been experimenting a bit with SwiftUI and ran into an error that it took me an embarrassingly long time to diagnose. The error message is “Missing argument for parameter #1 in call” and it appeared on a ForEach statement in a View. Here’s the cause as well as some troubleshooting steps I wish I’d followed. The SwiftUI Code The change I was trying to make was to the return type of the property stuff.all. I wanted to return a more specialized type to handle some localization conditions. For example, a change like this: As soon as I made the [Read on…]

JSON decoding in Swift Failure

Just ran into this error when trying to decode some JSON in Swift and the error message had me stumped for too long despite being trivial so I thought I’d commit it to memory. The JSON looked like this: And here’s the Swift struct I was trying to use to decode it: The problem is in the declaration of bar in Foo, it is not an array of Bar, it is just a Bar. So the declaration should be: Then this test case will work:

Flutter plugin iOS tests in Swift

Creating plugins for Flutter is well documented and pretty easy. Unit testing the resulting native code in iOS wasn’t quite as straightforward so I thought I’d capture what I did while I still remember the steps. This post shows how to create a new plugin for Flutter with a Swift implementation for iOS, and then add Swift XCTest unit tests for that implementation. Creating a new plugin To create my first plugin I followed the Flutter docs, in particular the section on Developing plugin packages. I used the version of the create command that specified the native languages, like so: [Read on…]