What is SwiftUI?

SwiftUI is Apple's modern framework for building user interfaces across Apple platforms using declarative Swift code.
Written by

Chris C

Updated on

May 01 2024

Table of contents

    SwiftUI is a framework for building app interfaces on Apple platforms. Instead of designing screens in Storyboards or manually configuring every view with UIKit, you describe the interface you want in Swift code and let SwiftUI handle much of the layout and rendering work.

    What was the old way?

    Before SwiftUI, most iOS interfaces were built with UIKit. UIKit includes controls and classes such as buttons, text fields, stack views, table views, and view controllers. Developers could arrange those pieces visually with Interface Builder or build the interface programmatically in Swift.

    UIKit is powerful, but it often requires you to spell out many small implementation details. For example, creating a simple form might involve creating a vertical stack view, adding it to the main view, applying layout constraints, creating a text field, and inserting that text field into the stack.

    • Create a vertical UIStackView.
    • Add it to the root view.
    • Add layout constraints so the stack appears where you want it.
    • Create a UITextField.
    • Add the text field into the stack view.

    Each of those steps usually needs code or visual configuration. SwiftUI approaches the same kind of interface from a higher level.

    So what's the difference between SwiftUI and UIKit?

    The biggest difference is the way you think about the interface. UIKit is often imperative: you create views, update properties, connect constraints, and tell the system exactly what to do. SwiftUI is declarative: you describe the result you want, and the framework figures out how to produce and update it.

    UIKit

    You tend to control the individual steps: create this view, add it here, constrain it there, and update it when state changes.

    SwiftUI

    You describe the screen as a function of your data: show these text fields and this button in a vertical stack, then let SwiftUI update the result.

    A simple SwiftUI version of a form might read almost like a plain-English description: group two text fields and a button inside a vertical stack. SwiftUI creates the elements, places them in the view hierarchy, and applies sensible defaults. You can still customize alignment, spacing, sizing, and styling when the defaults are not what you need.

    VStack {
        TextField("Email", text: $email)
        SecureField("Password", text: $password)
        Button("Sign In") {
            signIn()
        }
    }

    That declarative style saves time because the framework handles many of the repetitive layout and update details that previously had to be managed by hand.

    The way you use SwiftUI is also different from UIKit

    With UIKit, you may use Storyboards and Interface Builder to drag elements onto the screen, connect outlets, and configure layout visually. You can also build everything programmatically, but either way you are usually working with lower-level details.

    With SwiftUI, you write the interface in Swift code. Xcode can preview that code visually, but the source of truth is the SwiftUI view declaration itself. You state what the interface should look like for the current data, and SwiftUI keeps the screen in sync as that data changes.

    Does SwiftUI replace UIKit?

    SwiftUI is Apple's intended direction for modern app interface development, but UIKit still exists and is still useful. Many production apps use UIKit, and some specialized controls or older APIs may still require UIKit.

    Apple made it possible to mix the two. You can bring UIKit views into a SwiftUI app when needed, and you can embed SwiftUI views inside UIKit apps. That means you do not have to choose one framework forever at the start of a project.

    Practical takeaway: beginners should usually start with SwiftUI, but knowing that UIKit exists will help you understand older tutorials, legacy apps, and APIs that have not fully moved to SwiftUI.

    Does SwiftUI use UIKit?

    SwiftUI and UIKit are different user interface frameworks. SwiftUI does not require you to write UIKit code for normal SwiftUI views, although Apple provides interoperability tools so the two can work together in the same app.

    For a new learner, the simplest way to think about it is this: Swift is the programming language, SwiftUI is the modern Apple UI framework written with Swift, and UIKit is the older UI framework that still powers many existing apps.