Blog / What is UIKit and what is it for?

What is UIKit and what is it for?

by SW Team

This time, we'll dive into the fundamentals of UIKit, Apple's toolkit for creating user interfaces in iOS apps. Throughout this series, we'll explore how to start from scratch with UIKit, understand the MVC (Model-View-Controller) architecture, and dive into creating views using Storyboards, as well as understand essential concepts such as AutoLayout, ViewControllers and more.

cta:hosting

What is UIKit and why is it important?

Before we dive into the technical details, it is essential to understand what UIKit is and why it is crucial for iOS app development. UIKit is one of Apple's core frameworks designed specifically for creating user interfaces on iOS devices. Although SwiftUI has gained popularity since its release in 2019, UIKit is still widely used due to its long history and maturity.

So why is it important to learn UIKit? While SwiftUI offers new ways to create user interfaces, many apps in the App Store are still based on UIKit. Therefore, for those aspiring to become professional iOS developers, mastering UIKit is critical. Even in projects that adopt SwiftUI, it is common to encounter the need to refactor or integrate existing UIKit components.

Find out more about SwiftUI on our blog

Creating a project with UIKit

UIKit provides a solid structure for organising our projects, and understanding the main elements of this structure is essential.

cta:domains

When creating a project with UIKit, we will find several key components:

  • AppDelegate: Entry point of our application.
  • SceneDelegate: Handles the different screens we might display within the application, as well as state change events.
  • Main.storyboard: Here we visually design our views using Storyboards.
  • ViewController: Controls the lifecycle and logic of our views.
  • Assets: Where we can store images, icons, and other visual resources.
  • LaunchScreen: The view that appears while the application is loading.

Delving into ViewController and the MVC architecture

The ViewController is a fundamental component in UIKit. It is in charge of controlling the logic and lifecycle of the views that make up our application. It is also important to understand the MVC (Model-View-Controller) architecture adopted by Apple in UIKit:

  • Model: Responsible for handling the application's data.
  • View: Represents the user interface and displays the model data.
  • Controller: Acts as an intermediary between the model and the view, handling user interactions and updating the model as needed.

This architecture provides a clear separation of responsibilities, which facilitates code maintenance and scalability.

Creating a view with Storyboard

One of the most powerful features of UIKit is the ability to design user interfaces visually using Storyboards. Here, we create a simple view in our Storyboard, adding a UILabel and a UIButton. We then connect these views to our ViewController using IBOutlets and IBActions to perform actions such as changing properties or handling user events.

Conclusion

In this brief overview of UIKit, we have covered fundamental aspects such as creating projects, the structure of the main components, understanding the ViewController and the MVC architecture, as well as creating views using Storyboards. We hope this post has provided a useful introduction for those venturing into iOS app development.

cta:cloud_so

i