how can I use one codebase to create an app from iOS, iPados and macOS?
Generated on 7/31/2024
1 search

This post is brought to you by Tailscan,
the best devtool for Tailwind CSS.
To create an app for iOS, iPadOS, and macOS using a single codebase, you can leverage several tools and frameworks provided by Apple. Here are some key points and sessions from WWDC that can help you achieve this:
-
SwiftUI:
- SwiftUI is a powerful framework that allows you to build user interfaces for all Apple platforms using a single set of tools and APIs. It supports adaptive views and scenes, which provide an idiomatic look and feel on any Apple platform.
- SwiftUI enables code sharing across platforms, but it is not a "write once, run everywhere" solution. It provides a common set of high and low-level components across platforms, with specialized APIs for each platform to handle unique design and interaction patterns.
- For more details, you can refer to the session SwiftUI essentials.
-
Xcode:
- Xcode simplifies targeting multiple Apple devices uniformly while allowing for necessary customizations. You can set up your project to target both macOS and iOS by configuring the project settings under supported destinations.
- Xcode makes it easy to differentiate elements like libraries, frameworks, and parts of code depending on the target. You can use target conditionals to compile parts of your files for one OS or the other.
- For more information, you can refer to the session Port advanced games to Apple platforms.
-
Unified Metal Shaders:
- If your app involves graphics or gaming, unified Metal shaders allow you to compile your shaders once and deploy them to both macOS and iOS. This unification simplifies the development process and ensures consistent performance across platforms.
- For more details, you can refer to the session Port advanced games to Apple platforms.
-
Cross Compilation:
- Cross compilation is a common development use case where you can generate an executable on one environment and run it on a different environment. For example, you could build your app on macOS and run it on an iPad.
- For more information, you can refer to the session What’s new in Swift.
By using these tools and frameworks, you can efficiently create and maintain a single codebase for your app that runs on iOS, iPadOS, and macOS.

Port advanced games to Apple platforms
Discover how simple it can be to reach players on Apple platforms worldwide. We’ll show you how to evaluate your Windows executable on Apple silicon, start your game port with code samples, convert your shader code to Metal, and bring your game to Mac, iPhone, and iPad. Explore enhanced Metal tools that understand HLSL shaders to validate, debug, and profile your ported shaders on Metal.

SwiftUI essentials
Join us on a tour of SwiftUI, Apple’s declarative user interface framework. Learn essential concepts for building apps in SwiftUI, like views, state variables, and layout. Discover the breadth of APIs for building fully featured experiences and crafting unique custom components. Whether you’re brand new to SwiftUI or an experienced developer, you’ll learn how to take advantage of what SwiftUI has to offer when building great apps.

What’s new in Swift
Join us for an update on Swift. We’ll briefly go through a history of Swift over the past decade, and show you how the community has grown through workgroups, expanded the package ecosystem, and increased platform support. We’ll introduce you to a new language mode that achieves data-race safety by default, and a language subset that lets you run Swift on highly constrained systems. We’ll also explore some language updates including noncopyable types, typed throws, and improved C++ interoperability.

Platforms State of the Union
Discover the newest advancements on Apple platforms.

Migrate your TVML app to SwiftUI
SwiftUI helps you build great apps on all Apple platforms and is the preferred toolkit for bringing your content into the living room with tvOS 18. Learn how to use SwiftUI to create familiar layouts and controls from TVMLKit, and get tips and best practices.