AppDelegate.swift
:
unchanged.
Contains three pairs of methods:
launch/terminate,
foreground/background,
active/inactive.
See
Managing
State Transitions
and
Execution
States for Apps.
ViewController.swift
.
The
viewDidLoad
method of the view controller let the view controller be the
delegate
of the
text view.
.Main.storyboard
:
The
UIView
contains three subviews: a yellow
UILabel
,
a
UITextField
,
and a green
UIView
.
.LaunchScreen.storyboard
:
unchanged.Info.plist
:
the
information
property list
file.
Unchanged.//Look up each state and find its two-letter abbreviation. let dictionary: [String: String] = [ "Alabama": "AL", "Alaska": "AK", "Arizona": "AZ", "Arkansas": "AR", "California": "CA" ];
Update the user instructions in the yellow
UILabel
.
textField.text
in the dictionary,
create the following variable and try to look it up.
let lowercase: String = textField.text!.lowercased();
textField.text
in the answer label,
create the following variable and display it instead.
let capitalized: String = lowercase.prefix(1).uppercased() + lowercase.dropFirst();
Int
s.
let dictionary: [Int: String] = [ 1492: "Columbus discovers America", 1776: "American Independence", 1929: "Stock market crash", 1969: "Moon landing" ];Change the original
let ikeaWord: String = textField.text!;to
let year: Int = Int(textField.text!)!; //Convert String to Int.
Int
s.
//How many electoral votes does each state have? let dictionary: [String: Int] = [ "AL": 9, //Alabama "AK": 3, //Alaska "AZ": 11, //Arizona "AR": 6, //Arkansas "CA": 55 //California ];Change the original
let meaning: String? = dictionary[ikeaWord];to
let votes: Int? = dictionary[state];