About app development with UIKit
Learn about the basic support that UIKit and Xcode provide for your iOS and tvOS apps.
Overview
The UIKit framework provides the core objects that you need to build apps for iOS and tvOS. You use these objects to display your content onscreen, to interact with that content, and to manage interactions with the system. Apps rely on UIKit for their basic behavior, and UIKit provides many ways for you to customize that behavior to match your specific needs.
Xcode provides template projects as starting points for every app you create. For example, the following image shows the structure of an app created using the iOS app template in Xcode. The template projects provide a minimal user interface, so you can build and run your project immediately and see the results on a device or in the simulator.
[Image]
When you build your app, Xcode compiles your source files and creates an app bundle for your project. An app bundle is a structured directory that contains the code and resources associated with the app. Resources include the image assets, storyboard files, strings files, and app metadata that support your code.
Add required resources
Every UIKit app is required to have the following resources:
App icons
Launch screen storyboard
The system displays your app icon on the Home Screen, in Settings, and anywhere it needs to differentiate your app from other apps. Because it may display in dark or light appearance, or a person may choose the tinted display option, you provide multiple versions of your app icon in your Xcode project’s AppIcon image asset. Create a distinctive app icon to help people quickly identify your app on the Home Screen. Test different appearances and display options to determine if you need to vary the details of your icon. For more information, see Creating your app icon using Icon Composer and Configuring your app icon using an asset catalog.
[Image]
The LaunchScreen.storyboard file contains your app’s initial interface, and it can be a splash screen or a simplified version of your actual interface. When someone taps your app’s icon, the system displays your launch screen immediately, letting the person know that your app is now launching. The launch screen also provides cover for your app while it initializes itself. When your app is ready, the system hides the launch screen and reveals your app’s actual interface. For more information, see Specifying your app’s launch screen.
Update required app metadata
The system derives information about your app’s configuration and capabilities from the information property list. Xcode provides a preconfigured version of this list with every new project template, and you modify it based on the needs of your app. For example, if your app relies on specific hardware, or uses specific system frameworks, you can add information related to those features to the list.
One common modification you can make to the information property list is to declare your app’s hardware and software requirements. These requirements are how you communicate to the system what your app needs to run. For example, a navigation app might require the presence of GPS hardware to provide turn-by-turn directions. The App Store prevents someone from installing your app on a device that doesn’t meet your app’s requirements.
[Image]
For information about the keys that you can include in your information property list, see Information Property List.
Review the code structure of a UIKit app
UIKit provides many of your app’s core objects, including those that interact with the system, run the app’s main event loop, and display your content onscreen. You use most of these objects as-is or with only minor modifications. Knowing which objects to modify, and when to modify them, is crucial to implementing your app.
Your app uses UIApplication and a UIApplicationDelegate subclass to interact with application-level services and information. You configure and customize one or more Scenes to present your app on the screen. Use multiple scenes to represent multiple instances of your app or to handle showing your app on a noninteractive external display.
The structure of UIKit apps is based on the Model-View-Controller (MVC) design pattern, where you create objects that fulfill specific purposes. Model objects manage the app’s data and business logic. View objects provide the visual representation of your data. Controller objects act as a bridge between your model and view objects, moving data between them at appropriate times.
Build and organize your app with UIKit objects
The UIKit and Foundation frameworks provide many of the basic types that you use to define your app’s model objects. UIKit provides a UIDocument object for organizing the data structures that belong in a disk-based file. The Foundation framework defines basic objects representing strings, numbers, arrays, and other data types. The Swift Standard Library provides many of the same types available in the Foundation framework.
UIKit provides controller objects to help you organize and move between your views. UIViewController is the basic controller object you subclass to manage and display a view. Implement common user interface designs with controllers like UINavigationController, UISplitViewController, and UITabBarController. For more information, see View controllers.
Build views with UIView, which displays your content onscreen. Lay out your views with UIStackView, or use Auto Layout for more complex layouts. Make your app responsive to size changes using details in View layout. Use objects like UIScrollView, UITableView, and UICollectionView to efficiently lay out multiple views, or to display views for more data than can fit on the screen at one time.
Manage and respond to interactions with UIControl objects, such as UIButton, UISlider, and UISegmentedControl. Use views such as UICalendarView, UIImageView, and UIPickerView to display and interact with specific types of data. Update your views in response to long presses, pans, swipes, pinches, and other gestures with UIGestureRecongizer and related subclasses.
Show and interact with text using UILabel, UITextField, and UITextView. For more information, see Views and controls.