Sign in

WWDC21 Scholar. I like to read manga and write about Swift. Check out my app, Find — look for text in real life, with outrageous speed. getfind.app

Markdown, colors, and formatting — it’s never been easier

Image Credit: author

Attributed Strings have always been hard to work with. The most basic implementation, in UIKit, would be something like this:

This is bad enough, but it’s even worse for SwiftUI. The current accepted answer on Stack Overflow uses UIViewRepresentable and some other unnecessarily complex code. However, that was the only way — until WWDC21.

Markdown

Markdown is everywhere: on GitHub, Stack Overflow, Discord’s message bubble… and now, the awesome formatting language comes to SwiftUI! Everything works, even links:


With Swift, Markdown, and GitHub Pages

Apps displaying help center
Image credit: Author

Most big apps have some sort of help center, also known as a “knowledge base.” You know, the “What can we help you with?” screens.

Search up “knowledge base software,” and you’ll find countless services that offer this functionality… but have you looked at their pricing?


It’s supposed to be a “feature”

Info.plist missing from the project navigator
Image by the author.

If you’ve created a new SwiftUI app using Xcode 13, you’ll notice that Info.plist is gone. It’s not a bug. According to the Xcode 13 release notes:

“Projects created from several templates no longer require configuration files such as entitlements and Info.plist files. Configure common fields in the target’s Info tab, and build settings in the project editor.”

That’s nice, but there’s a problem. All you get is a GUI, so you can’t see the underlying XML source code. This can be limiting when you’re resolving merge conflicts or when you just want to paste in some template properties.

Let’s…


43 lines of code is all it takes

decorative: abstract pattern of colored lights
Photo by Anton Maksimov juvnsky on Unsplash

Markdown is probably the easiest way to edit and format rich text. It’s also extremely popular, and pretty much everyone knows how to use it.

So, want to implement Markdown in your app? It used to be… complicated. You’d need to use a third-party Markdown parser, then display the result in a web view. If you wanted to use it with SwiftUI, well, good luck working with UIViewRepresentable.

Good news, though: At WWDC21, Apple released SwiftUI 3 with Markdown support! It’s one of the features that have kind of flown under the radar, but it’s also one of the most…


Make your designs look great on any device

Ever since Apple released the iPhone X, using the safe area has been a must-do for developers. You don’t want your work hidden under the notch or clipped beneath the status bar or under the rounded corners, etc.

The launch of the iPhone X along with the safe area came back in 2017, so I think it’s safe to say every iOS developer knows how to use it — if not, here’s the documentation.

But sometimes you need to dive deeper. You might want the safe area present in some views but not in others — maybe a blur partially…


Music makes everything better

Photo by the author.

In 2016, Apple released an iPad version of Swift Playgrounds. Paired with an external keyboard, it’s almost as good as Xcode and a lot faster, but it’s slightly oversimplified. Sure, you can write code, but what about adding files or playing audio?

When I was coding my playground for this year’s Swift Student Challenge, I started out using my iPad. It was extremely fast. Pressing “Run My Code” would yield the result in less than a second! But I hit some snags — the most significant one being there was no way to play audio! …

Zheng

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store