{
"$type": "site.standard.document",
"bskyPostRef": {
"cid": "bafyreidcczyiulf7rlyvdm2ww6qtmtdwaljowwyd6y47x6k7mgiteqgdku",
"uri": "at://did:plc:e7ehpd5hzctp5oq7dlfbz6e5/app.bsky.feed.post/3mm66kxcbbgi2"
},
"path": "/posts/swiftui-limits/",
"publishedAt": "2026-05-18T17:27:55.000Z",
"site": "https://swiftdevjournal.com",
"tags": [
"May 2026 Swift Blog Carnival"
],
"textContent": "This post is part of the May 2026 Swift Blog Carnival that asks people to write about the limits they ran into with SwiftUI when developing their apps. I encountered the following limitations with SwiftUI:\n\n * Limited rich text editing experience.\n * The file exporter returns a folder URL when exporting to PDF.\n * SwiftUI lets you save documents in unwanted export file formats in Mac apps.\n\n\n\n## Limited rich text editing experience\n\nSwiftUI includes a `TextEditor` view to enter longer amounts of text, but the initial version was very limited. You could edit only plain text, and you couldn’t access the selected text or the selection range.\n\nApple added rich text support to `TextEditor` in iOS and macOS 26. On Mac you would think `TextEditor` would be similar to AppKit’s `NSTextView` with rich text support and an inspector bar with controls to format the text.\n\nIf you add a `TextEditor` view to a SwiftUI Mac app, bind the view to an attributed string, and run the app, all you get is a text editor that looks like a plain text editor with no formatting controls. You have to add `TextFormattingCommands()` to the `.commands` modifier in the `App` struct, and the user has to choose Format > Text > Show Ruler to see any formatting controls.\n\nIf your app has a sidebar, the sidebar covers up the formatting controls on the left side of the text editor and the left part of the ruler view.\n\nSomeone using the app has to hide the sidebar to apply a paragraph style to the text in `TextEditor`. You have to use `NSTextView` to keep the sidebar from blocking the formatting controls.\n\n## File exporter returning folder URL\n\nI wanted to export a document to PDF in an app I was developing. I used SwiftUI’s `.fileExporter` to get the URL for the exported PDF. I tried to create a Core Graphics PDF context to create the PDF, supplying the URL from the file exporter. The app kept crashing, and I saw the following error message in Xcode’s console:\n\n\n CGDataConsumerCreateWithFilename:\n failed to open /path/to/fileExporterURL\n for writing: Is a directory.\n\n\nThe file exporter was returning a folder URL instead of a file URL so I couldn’t create the PDF context. On Mac I could work around the issue by using `NSSavePanel`. `NSSavePanel` returns a file URL for a PDF file. iOS doesn’t have an equivalent to `NSSavePanel` so I couldn’t export a PDF in the iOS version of the app.\n\n## SwiftUI allows saving documents in unwanted file formats\n\nI developed a SwiftUI app for Mac and iOS that lets writers publish their own ebooks. The app has a custom document type for book documents, and people can publish an EPUB book from the app.\n\nTo allow publishing an EPUB book from the app, I had to add `.epub` to the list of writable content types for the SwiftUI document type. Otherwise the published book would have the file extension for my app’s document type instead of `.epub`.\n\n\n static var bookDocument: UTType {\n UTType(importedAs:\n \"com.CheckSimSoftware.book\",\n conformingTo: .package)\n }\n\n static var writableContentTypes: [UTType] {\n [.bookDocument, .epub]\n }\n\n\nThe problem I ran into was when people saved the document in the Mac version, the Save panel showed a File Format menu that let people save the document as my app’s document type or as an EPUB file. If someone chose EPUB, they wouldn’t be able to open the document.\n\nSwiftUI provides no way to limit document saving to the app’s document type for Mac apps. An app developer has two options for saving documents in apps that can export to additional formats.\n\n * Live with the File Format menu in the Save panel and tell people to save only in the default format.\n * Force users to manually change the file extension for exported files.\n\n\n\nI filed a bug report about this issue in December 2022, FB11876082. The issue has not been addressed.",
"title": "SwiftUI Limits I Encountered"
}