【 例 】 In order to avoid a quarrel, advance declaration: this article is pure translation, only for learning, plus the level is limited, forgive me!

About using UIKit for application development

Learn about the basic support UIKit and Xcode provide for iOS and tvOS apps.

An overview of the

The UIKit framework provides the core objects you need to build iOS or tvOS applications. You can use these objects to present content on the screen, interact with that content, and manage interactions with the system. Applications rely on UIKit for their basic behavior, and UIKit also provides many methods for you to customize the behavior to suit your particular needs.

Developing an iOS or tvOS app always starts by creating a project in Xcode, Apple’s integrated development environment. If you don’t have Xcode, you can download it from the App Store. You can also download the latest version from developer.apple.com.

Xcode provides a project template as a starting point for every application you create. For example, Figure 1 shows the application structure created with the single-view template in Xcode. Project templates provide a minimalist user interface, so you can immediately build and run the project and see the results on a real machine or emulator.

As you build your application, Xcode compiles the source files and creates app bundles for your project. An app bundle is a structured directory that contains code and application-related resources. Resources include image resources, storyboards files, string files, and application metadata for your code. The structure of the app bundle is important, but Xcode knows to put resources there, so don’t worry about it for now.

Necessary resources

Every UIKit application must have the following resources:

  • App ICONS
  • Launch Screen storyboard

The system will display your app icon on the home screen, Settings page, and anything else you need to differentiate it from other apps. Since it needs to be used in multiple places and on multiple devices, you need to provide different versions of the AppIcon in the AppIcon image resource of the Xcode project, as shown in figure 2. Your app icon should be designed to stand out so that you can quickly identify your app on the home screen. However, you may need to modify the details of the icon to fit the different image sizes you must provide.

The launchscreen.storyboard file contains the application’s initial user interface, which can be a splash screen or a simplified version of the actual interface. When the user clicks on the app icon, the system immediately displays a startup screen to let the user know that your app is being launched. The startup screen also provides a cover for the application when it is initialized. When the application is initialized, the system hides the startup page and displays the actual application page.

Required application metadata

The system exports configuration and permission information about the application from the property list (info.plist) file in the application package. Xcode provides a pre-configured version of this file for every new project template, but sometimes you may modify this file. For example, if your application relies on specific hardware or needs to use specific system frameworks, you may want to add information related to those features to this file.

One of the most common changes you make to the info.plist file is to declare your application’s hardware and software requirements. These requirements are how you explain to the system what your application is going to run. For example, a navigation application may need to use GPS hardware to provide segment-based navigation, as shown in Figure 3. The App Store prevents apps from being installed on devices that don’t meet the app’s requirements.

Info.plist
Information Property List Key Reference

The code structure of UIKit applications

UIKit provides a number of application core objects, including those that interact with the system, run the application’s main event loop, and display content on the screen. For most objects you will probably use them exactly as they are or make only minor adjustments. Knowing which object to modify and when to modify it is important to implement your application.

The structure of UIKit applications is based on the Model-View-Controller (MVC) design pattern, where objects are divided by purpose. The Model object manages the data and business logic of the application. A View object provides a visual representation of the data. The Controller object acts as a bridge between the model and the view object, transferring data between the two in due course.

Figure 4 shows a classic UIKit application structure. You provide model objects that display data structures. UIKit works with most of the attempted objects, although you can customize views for your data as needed. Your view controller and your application delegate are responsible for coordinating the exchange of data between data objects and UIKit views.

The UIKit and Foundation frameworks provide a number of basic types that you can use to define application model objects. UIKit provides UIDocument objects to organize data structures that belong to disk files. The Foundation framework defines basic objects to display strings, numbers, arrays, and other data types. The Swift Standar Library provides many of the same types available in the Foundation framework.

UIKit provides many objects in the controller and view layer of your application. In particular, UIKit defines UIView, which is usually used to display your content on the screen (you can also use Metal and other system frameworks to render content directly on the screen). UIApplication object to run the main event loop of the application and manage the entire lifecycle of the application.