Xcode 16 introduced the @Previewable macro for SwiftUI Previews, allowing you to use dynamic properties inline in previews. You’ll be able to make richer and more dynamic previews of your SwiftUI views without the need to wrap any state inside child views. Swift and SwiftUI use macros to hide implementation details, and this new attached-macro …
Swift Package Manager framework creation in Xcode
Swift Package Manager (SPM) is Apple’s answer for managing dependencies. We’re all familiar with tools like CocoaPods and Carthage, but we’ll likely all use Swift Package Manager soon instead of those. If you’re deciding which package manager to use, it’s recommended to start using SPM today. By switching to the Swift Package Manager, we also …
ChatGPT for Swift: Top 5 code generation prompts
Using ChatGPT for Swift code generation can drastically increase your productivity. While I’m uncertain whether AI will take over our jobs as developers, I’m certain developers without knowledge of using AI to their advantage will become much slower in writing code. Today, we will look at a few of my favorite ways of using ChatGPT …
MVVM: An architectural coding pattern to structure SwiftUI Views
MVVM (Model-View-ViewModel) is an architectural coding pattern for structuring SwiftUI views. The goal of the pattern is to separate the view definition from the business logic behind it. Your views will not depend on any specific model type if done correctly. While MVVM was mostly used in the UIKit/AppKit days, it’s still a commonly used …
Repository design pattern in Swift explained using code examples
The repository design pattern allows you to create an accessible data layer that’s easy to mock for tests. By using common design patterns, you’ll be able to create a consistent project structure, separate concerns, and increase the chances for the project to be easier to understand by outside contributors. One of my favorite design patterns …
Xcode Build Insights: Keep track of project compilation times
Xcode Build Insights lets you keep track of compilation times to ensure your project doesn’t suddenly become slow to build. You’re likely building your project tens of times per day, so compilation times that become slower can significantly impact your overall productivity. While Xcode keeps a history of your builds, it only briefly retains it. …
Solve Missing API declaration using required reason (ITMS-91053)
Apps submitted to the App Store must define API declarations using the required reasons. Apps that don’t will be rejected until they do. This requirement counts for APIs declared in your app’s code and third-party libraries. For the latter, you might be dependent on the library maintainers. While Apple provides rich documentation, it’s hard to …
Using @Environment in SwiftUI to link Swift Package dependencies
The @Environment property wrapper in SwiftUI allows you to read values from a view’s environment. You’re able to configure an environment value yourself or make use of the default available values. Please read my article on Property Wrappers before diving into this one. Note that this is a different wrapper than @EnvironmentObject, which I explain …
Bar Chart creation using Swift Charts
Apple introduced Swift Charts during WWDC ’22, allowing you to visualize data into bar charts. Before this framework, we had to include all kinds of third-party solutions to draw charts in SwiftUI. Visualizing data using a similar declarative syntax to SwiftUI is simply fantastic. A bar chart is just one of the available options to …
Statistical significance and its importance with app experiments
Statistical significance tells you whether the result from an experiment is likely attributable to the specific change you did. It’s an essential quantification when running app experiments, and it prevents you from concluding too early about a change you’ve made. I’ve been running hundreds of experiments throughout my career and only a few of the …