IKEA dictionary

Source code in Dictionary.zip

  1. AppDelegate.swift: unchanged. Contains three pairs of methods: launch/terminate, foreground/background, active/inactive. See Managing State Transitions and Execution States for Apps.
  2. ViewController.swift. The viewDidLoad method of the view controller let the view controller be the delegate of the text view. .
  3. Main.storyboard: The UIView contains three subviews: a yellow UILabel, a UITextField, and a green UIView. .
  4. LaunchScreen.storyboard: unchanged.
  5. Info.plist: the information property list file. Unchanged.

Download the app

  1. Click on the above link to the file Dictionary.zip to download the file.
  2. Move the file Dictionary.zip from your Mac Downloads directory to your Desktop.
  3. Double-click on Dictionary.zip to unzip it. This will create a new folder named Dictionary.
  4. Double-click on the Dictionary.xcodeproj file in this folder. This will open the Dictionary project in Xcode.

Things to try

  1. Make a different dictionary. For example,
    //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.


  2. Instead of trying to look up textField.text in the dictionary, create the following variable and try to look it up.
    let lowercase: String = textField.text!.lowercased();
    

  3. Instead of displaying textField.text in the answer label, create the following variable and display it instead.
    let capitalized: String = lowercase.prefix(1).uppercased() + lowercase.dropFirst();
    

  4. Make a dictionary whose first column is a column of Ints.
    	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.
    

  5. Make a dictionary whose second column is a column of Ints.
    	//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];