Create a Safari Extension to Extract Article Content

In this article, I’ll show you how to access a web page’s content, alter it using JavaScript, and display it using your Safari extension’s UI. Specifically, I’ll demonstrate how to display an article’s content in a popover. I often use Large Language Models (LLMs) to summarize articles when I’m unsure if they’re worth reading. Without the extension we’re about to build, I’d need to manually trigger Safari’s reader mode (⌘ + ⇧ + R), copy all content, and paste it into Claude or ChatGPT....

December 18, 2024 · Bartosz Kunat

Xcode: Missing Package Product (local package)

When adding a local Swift package to your Xcode project, you might encounter the following error: Missing package product `PACKAGE_NAME` The issue often occurs when the package you’re trying to add is already open in Xcode. To resolve: Close the package in Xcode. Close your main project. Reopen your main project. I’m not sure what might be causing this issue or why reopening the project is required (a clean build won’t do)....

June 24, 2024 · Bartosz Kunat

Open Any Xcode Project Type with a Shell Script

In my current role, we have around 30 projects distributed across roughly 20 different repositories. Most of them are Swift packages for various features used in our apps. This setup requires me to frequently switch between multiple projects. Just a few days ago, I was working on the login flow. This involved modifying two Swift packages and one Xcode project. Remembering whether a given project is a Swift package, a workspace (....

April 29, 2024 · Bartosz Kunat

Working with Local Swift Packages

Imagine you’re working on Project A, which relies on Package B, a remote Swift package. To incorporate modifications in B and assess their impact on A, the standard approach requires committing and pushing the changes in B, updating B’s version in A, and then rebuilding A to observe the outcomes. This method is slow and cumbersome. There must be a better way! Project A | └──> Swift Package B To speed up and improve the workflow, you can convert the remote dependency B to a local one....

February 27, 2024 · Bartosz Kunat

Alfred Snippet Converter

A few months ago, I wrote about Alfred Snippets on iOS. In that article, I described the manual process of converting Alfred text snippets into macOS text replacements. Since then, I’ve had time to refine this project and add some new features. You can download the final Command Line Interface (CLI) or the macOS app from this link. Next on my list is the complete automation of the process of synchronizing Alfred text snippets with macOS text replacements....

December 27, 2023 · Bartosz Kunat

Automating Adding SPM Plugins

How to automate adding plugins to all of your existing (and future) targets in a Swift package TL;DR package.targets = package.targets.map { target in var plugins = target.plugins ?? [] plugins.append(.plugin(name: "SwiftLintPlugin", package: "SwiftLint")) target.plugins = plugins return target } The Problem Last month, I was tasked with adding SwiftFormat and SwiftLint to one of the projects my team maintains. The project is medium-sized and uses Swift Package Manager (SPM) for modularization....

December 18, 2023 · Bartosz Kunat

GitLab Code Coverage for Pure Swift Packages

How to use GitLab’s built-in test coverage report tool for pure Swift packages? Some test coverage report generation tools do not support “pure” Swift packages. One example is Slather. By pure, I’m referring to packages that contain only the Package.swift file, without any .xcodeproj or .xcworkspace files. One solution to this problem was to generate a project file for a Swift package on the fly using Fastlane. This solution has one limitation: it’s not possible to generate a project file for a Swift package that contains any resources....

July 28, 2023 · Bartosz Kunat

Xcode Development Assets with XcodeGen

Development Assets in Xcode that allow developers to provide test data to use within SwiftUI previews and other code during development. Assets marked for development will only be included in debug builds and removed once you create an archive of your app. This solution is preferred to having larger assets in the production binary size. Developers can add different types of data as Development Assets, such as JSON files for mocked network requests, images to use in SwiftUI previews, Core Data sample databases, and Swift files representing mocked or sample data....

April 10, 2023 · Bartosz Kunat

How to Tackle Duplicate Test Doubles Problem in Modular Architecture

After SPM asset support has been added to Xcode 12, there is no reason not to use modularization in your iOS projects. It brings value no matter the project and team size. However, after some time, you might encounter problems like increased complexity, difficulty with integration testing, or code duplication. Today we’ll focus on the last one, specifically, testing doubles duplication. Let’s jump in! Introduction When saying “module” I’m always referring to a group of related targets....

March 30, 2023 · Bartosz Kunat

How to Connect Internal Dependencies in Swift Package Manager

Swift Package Manager (SPM) is a powerful tool for modularizing your code and managing dependencies in your projects. If you’re working on a project that uses SPM for modularization, you may need to add internal dependencies to connect different parts of your codebase. In this article, we’ll go over how to add internal dependencies in SPM and configure your Package.swift file to properly connect them. Assumptions Before we get started, let’s make a few assumptions about your project and its structure:...

March 16, 2023 · Bartosz Kunat

Handling Edit Menus Without the First Responder

Context I’m currently developing a chat-based app that requires the implementation of coping messages. Essentially, when a user long-presses a message bubble, an edit menu will appear with the option to “Copy.” This feature is a common element across most chat applications. For the purpose of this article, let’s assume that all message bubbles are constructed using a subclass of UITextView called MessageTextView. To make the “Copy” option appear on a long-press gesture, we’ll first need to add the appropriate gesture recognizer:...

January 31, 2023 · Bartosz Kunat