RSSAmplifier

Blog

Safe from the Losing Fight

mac and ios development

losingfight.comRSS feed ↗10 posts

Latest posts

Reading and writing files in Swift async/await

Because of habits ingrained in me, by default I tend to reach for synchronous, blocking APIs when reading and writing data to and from disk. This causes problems with Swift’s cooperatively scheduled Tasks. In this post, I examine the various async-safe approaches I’ve discovered to hitting disk, and end with a general approach that I ended up using. The synchronous way If I’m…

Swift async/await: do you even need a queue?

Alternative title: A concurrency limiter for Swift async/await This post is really for me and my future self to help clarify my thinking about modeling asynchronous operations in Swift async/await. But I suppose you can read along as well. In the world prior to async/await I used dispatch queues and OperationQueue s to model asynchronous operations. As a result, my thinking about async naturally…

Modeling condition variables in Swift async/await

In the brave new world of Swift async/await, a problem I sometimes encounter is how to communicate between Task s. More specifically, if I need one Task to wait on a condition to be true as a result of work that’s done by another set of Task s. In this post I’ll cover how I eventually ended up solving this using something like a condition variable. Refining the problem scope…

Updating NativeMarkKit for SwiftUI and iOS 14

I’ve pushed a small update to NativeMarkKit , my native Markdown rendering framework. It adds some SwiftUI wrappers that incorporate workarounds for the UIKit-SwiftUI interop bugs . It also fixes a bug introduced by iOS/tvOS 14 that prevented inline backgrounds from being rendered. Enjoy!

Introducing NativeMarkKit, native Markdown rendering

I’d like to announce the release of one of my side projects: NativeMarkKit . NativeMarkKit is a Swift package implementing the rendering of NativeMark. What’s NativeMark? Well, it’s a flavor of Markdown designed to be rendered by native iOS, macOS, or tvOS apps. i.e. it compiles down to NSAttributedString (mostly) instead of HTML and CSS. It’s basically CommonMark , but…

UIViewRepresentable doesn't respect intrinsicContentSize invalidation

This is a quick write-up of an unexpected SwiftUI limitation I encountered recently. In my own searching, I couldn’t find it documented anywhere so I’m hoping this post will help someone in the future. Problem summary You can’t wrap a UIView in SwiftUI’s UIViewRepresentable if that UIView changes its intrinsicContentSize based in its frame width, because UIViewRepresentable…

Sharing HTTP API bindings between Swift Vapor and iOS/macOS apps

I’ve been building a macOS/iOS front for my Swift Vapor side project. When I first started I simply duplicated the API HTTP request and response information between the client and server. But, as the project has grown, this has become more tedious. Since both client and server are in Swift, it seems like I should be able to come up with a more scalable solution. Ideally, I’d like to…

Handling periodic tasks in Swift Vapor

In my Swift Vapor side project, there have been a couple of instances where I wanted to run some periodic tasks. My needs were pretty simple: every X amount of time, I wanted to run a closure that would perform some database operations. On top of that, it would be nice to have a tiny bit of infrastructure to make periodic jobs require less boilerplate, have visibility in production (i.e. logging…

Building a declarative router for Swift Vapor

As I’ve been using Swift Vapor 3 , one of the things that I felt could be better was the way routes were declared. So I built a framework to meet my Vapor routing needs . If you’d like to try it out, go to the Github page and checkout the README . For the rest of this post, I’m going to talk about what my goals were, and highlight parts of the implementation that were interesting…

Sending email from Swift Vapor

Like most services these days, my Vapor side project needs to send welcome emails when a user signs up for the service. While I could write my own SMTP client, it would still require a lot of DNS setup to make sure those emails made it through various spam countermeasures . Given this is a side project, and sending email is a minor component of it, that didn’t seem worthwhile to me. So I…