/Applications
directory.FoodTracker
com.example
.AppDelegate.swift
file.AppDelegate.swift
.AppDelegate.swift
file to open it in a separate window.AppDelegate.swift
source file has two primary functions:AppDelegate
class. The app delegate creates the window where your app’s content is drawn and provides a place to respond to state transitions within the app. UIApplicationMain
attribute (@UIApplicationMain
), which appears toward the top of the file. UIApplicationMain
attribute is equivalent to calling the UIApplicationMain
function and passing your AppDelegate
class’s name as the name of the delegate class. In response, the system creates an application object. The application object is responsible for managing the life cycle of the app. The system also creates an instance of your AppDelegate
class, and assigns it to the application object. Finally, the system launches your app.AppDelegate
class is automatically created whenever you create a new project. Unless you are doing something highly unusual, you should use this class provided by Xcode to initialize your app and respond to app-level events. The AppDelegate
class adopts the UIApplicationDelegate
protocol. This protocol defines a number of methods you use to set up your app, to respond to the app’s state changes, and to handle other app-level events.AppDelegate
class contains a single property: window
. AppDelegate
class also contains stub implementations of the following delegate methods: funcapplication(_application: UIApplication, didFinishLaunchingWithOptionslaunchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool
funcapplicationWillResignActive(_application: UIApplication)
funcapplicationDidEnterBackground(_application: UIApplication)
funcapplicationWillEnterForeground(_application: UIApplication)
funcapplicationDidBecomeActive(_application: UIApplication)
funcapplicationWillTerminate(_application: UIApplication)
AppDelegate
class, you get the default behavior whenever that method is called. Alternatively, you can add your own code to the stub methods, defining custom behaviors that are executed when the methods are called.AppDelegate.swift
file.ViewController.swift
. Select ViewController.swift
in the project navigator to view it.UIViewController
named ViewController
. Right now, this class simply inherits all the behavior defined by UIViewController
. To override or extend that behavior, you override the methods defined on UIViewController
.ViewController.swift
file, the template’s implementation overrides both the viewDidLoad()
and didReceiveMemoryWarning()
methods; however, the template’s stub implementation doesn’t do anything yet, except call the UIViewController
version of these methods. You can add your own code to customize the view controller’s response to these events.didReceiveMemoryWarning()
method, you won’t need to implement it in these lessons, so go ahead and delete it.ViewController.swift
code should look something like this: Sticky note app for mac desktop.importUIKit
classViewController: UIViewController {
overridefuncviewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
}
Main.storyboard
.UIView
or one of its subclasses. Many UIView
subclasses are highly specialized in appearance and behavior. Start by adding a text field (UITextField
), one such subclass of UIView
, to your scene. A text field lets a user type in a single line of text, which you’ll use as the name of a meal.text field
in the filter field to find the Text Field object quickly.Enter meal name
.UILabel
) at the top of the scene. A label isn’t interactive; it just displays static text in the user interface. To help you understand how to define interaction between elements in the user interface, you’ll configure this label to display the text the user enters into the text field. It’ll be a good way to test that the text field is taking the user input and processing it appropriately.label
in the filter field to find the Label object quickly.Meal Name
.UIButton
) to the scene. A button is interactive, so users can tap it to trigger an action that you define. Later, you’ll create an action to reset the label text to a default value.button
in the filter field to find the Button object quickly.Set Default Label Text
.UIStackView
). A stack view provides a streamlined interface for laying out a collection of views in either a column or a row. The stack view uses Auto Layout under the hood to calculate the size and position of all the views that it manages. This lets you easily access the full power of Auto Layout, while greatly reducing the complexity of your layout. 8
in the Spacing field. Press Return.0
in the left and right boxes, and type 20
spacing in the top box.0
in the right box.Attribute | Value |
---|---|
Format | PNG |
Color space | sRGB or P3 (see Color Management) |
Layers | Flattened with no transparency |
Resolution | Varies. See Image Size and Resolution |
Shape | Square with no rounded corners |
Device or context | Icon size |
---|---|
iPhone | 180px × 180px (60pt × 60pt @3x) |
120px × 120px (60pt × 60pt @2x) | |
iPad Pro | 167px × 167px (83.5pt × 83.5pt @2x) |
iPad, iPad mini | 152px × 152px (76pt × 76pt @2x) |
App Store | 1024px × 1024px (1024pt × 1024pt @1x) |
Device | Spotlight icon size |
---|---|
iPhone | 120px × 120px (40pt × 40pt @3x) |
80px × 80px (40pt × 40pt @2x) | |
iPad Pro, iPad, iPad mini | 80px × 80px (40pt × 40pt @2x) |
Device | Settings icon size |
---|---|
iPhone | 87px × 87px (29pt × 29pt @3x) |
58px × 58px (29pt × 29pt @2x) | |
iPad Pro, iPad, iPad mini | 58px × 58px (29pt × 29pt @2x) |
Device | Notification icon size |
---|---|
iPhone | 60px × 60px (20pt × 20pt @3x) |
40px × 40px (20pt × 20pt @2x) | |
iPad Pro, iPad, iPad mini | 40px × 40px (20pt × 20pt @2x) |