I have ISYS120 Homework project, Swift programming.

Part I: (50 pts.)

Swift Chapter 1 – Getting Started

-Choose Playground from the File > New menu.

 -Enter a name for the new playground.

 -Choose iOS from the Platform menu.

A Swift playground opens with two sections. On the left, you have the Swift code editor. On the right, you have the results sidebar. The code in the editor is evaluated and run top to bottom, if possible, every time the source changes. The results of the code are displayed in the results sidebar.

Notice that the first line of text is green and that it begins with two forward slashes: //. The slashes signify to the compiler that the line is a comment, and Xcode shows comments in green.

Delete the forward slashes. The compiler will issue an error complaining that it cannot parse the expression. Add the slashes back using the handy keyboard shortcut Command-/.

Below the import statement is a line that reads var str = "Hello, playground". The text in quotes is copied on the right, in the results sidebar: "Hello, playground". Let’s take a closer look at that line of code. First, notice the equals sign, which is called the assignment operator. The assignment operator assigns the result of code on its righthand side to a constant or variable on its lefthand side.

On the right hand side of the equality, you have "Hello, playground". In Swift, the quotation marks indicate a String, an ordered collection of characters. The template named this new variable str, but variables can be named almost anything. (There are limitations, of course. Try to change the name str to be var. What happens? Why do you think you cannot name your variable var? Be sure to change the name back to str before moving on.)

String is a type, and we say that the str variable is “an instance of the String type.” Types describe a particular structure for representing data.

Add after Hello Playground

str += "!"

To add the exclamation point, you are using the += addition assignment operator. The addition assignment operator combines the addition (+) and assignment (=) operations in a single operator.

To print to the console, you will use the function print(). Functions are groupings of related code that send instructions to the computer to complete a specific task. print() is a function used to print a value to the console, followed by a line break. Unlike playgrounds, Xcode projects do not have a results sidebar, so you will use the print() function frequently when you are writing fully featured apps. The console is useful for checking the current value of some variable of interest.

Add this line next:

print(str)

Bronze Challenge Ch. 1:

Many of the chapters in this book end with one or more challenges. The challenges are for you to work through on your own to deepen your understanding of Swift and get a little extra experience. Your first challenge is below. Before you get started, create a new playground. You learned about the String type and printing to the console using print(). Use your new playground to create a new instance of the String type. Set the value of this instance to be equal to your last name. Print its value to the console. 

Submit a screen shot of the Ch. 1 Bronze Challenge.

Mathias,Matthew. Swift Programming: The Big Nerd Ranch Guide (Big Nerd Ranch Guides) (Kindle Locations 505-508). Big Nerd Ranch Guides. Kindle Edition.

Swift Chapter 2 – Types, Constants, Variables

Let’s see this in action. Create a new macOS playground. (From the welcome screen, choose Get started with a playground. From within Xcode, choose File → New → Playground... .) Name the playground Variables. Suppose you want to model a small town in your code. You might want a variable for the number of stoplights in the town. Remove the code that came with the template, create a variable called numberOfStoplights, and give it a value. (Remember that code you are to delete is shown struck through.)

 

import Cocoa

 

var str = "Hello, playground"  Take out this line

var numberOfStoplights = "Four" – Add this line

Now add this line below:

numberOfStoplights += 2

 The compiler gives you an error telling you that this operation does not make sense. You get this error because you are trying to add a number to a variable that is an instance of a different type: String. What does it mean to add the number 2 to a string? Does it double the string and give you “FourFour”? Does it put “2” on the end and give you “Four2”? Nobody knows. It just does not make sense to add a number to an instance of String. If you are thinking that it does not make sense to have numberOfStoplights be of type String in the first place, you are right. Because this variable represents the number of stoplights in your theoretical town, it makes sense to use a numerical type.

Swift provides an Int type to represent whole integers that is perfect for your variable. Change your code to use Int instead.

import Cocoa

 

var numberOfStoplights = "Four" – Change line to below

var numberOfStoplights: Int = 4

numberOfStoplights += 2

 Let’s take a look at the changes here. Before, the compiler relied on type inference to determine the data type of the variable numberOfStoplights. Now, you are explicitly declaring the variable to be of the Int type using Swift’s type annotation syntax. The colon in the code above represents the phrase “of type.” 

Note that type annotation does not mean that the compiler is no longer paying attention to what is on each side of the equality. If, for example, you tried to reassign your previous String instance of "Four" to be an integer using type annotation, the compiler would give you a warning telling you that it cannot convert a string to an integer.

Often, however, you will want to create instances with values that do not change. Use constants for these cases. As the name indicates, the value of a constant cannot be changed. You made numberOfStoplights a variable, and you changed its value. But what if you did not want to vary the value of numberOfStoplights? In that case, making numberOfStoplights a constant would be better. A good rule of thumb is to use variables for instances that must vary and constants for instances that will not. Swift has different syntax for declaring constants and variables. As you have seen, you declare a variable with the keyword var. You use the let keyword to declare that an instance is a constant.

import Cocoa

 

var numberOfStoplights: Int = 4 – Change line to below

let numberOfStoplights: Int = 4

numberOfStoplights += 2

 You declare numberOfStoplights to be a constant via the let keyword. Unfortunately, this change causes the compiler to issue an error. Why? You have just changed numberOfStoplights to be a constant, but you still have code that attempts to change its value: numberOfStoplights += 2. Because constants cannot change, the compiler gives you an error when you try to change it. Fix the problem by removing the addition and assignment code.

Listing 2.5  Constants do not vary

import Cocoa

 

let numberOfStoplights: Int = 4

numberOfStoplights += 2 – Remove this line

 Now, add an Int to represent the town’s population. (Do you think it should be a variable or a constant?)

import Cocoa

 

let numberOfStoplights: Int = 4

var population: Int – Add this line

 Your town’s population is likely to vary over time. Thus, you declared population with the var keyword to make this instance a variable. You also declared population to be an instance of type Int. You did so because a town’s population is counted in terms of whole persons. But you did not initialize population with any value. It is therefore an uninitialized Int.

Use the assignment operator to give population its starting value.

Listing 2.7  Giving population a value

import Cocoa

let numberOfStoplights: Int = 4

var population: Int

population = 5422 – Add this line

let townName: String = "Knowhere" Add this line

 It would be nice to have a short description of the town that the Tourism Council could use. The description is going to be a constant String, but you will be creating it a bit differently than the constants and variables you have created so far. The description will include all the data you have entered, and you are going to create it using a Swift feature called string interpolation. String interpolation lets you combine constant and variable values into a new string. You can then assign the string to a new variable or constant or just print it to the console. You are going to print the town description to the console.

let townName: String = "Knowhere"

Add the below lines:

let townDescription =

"\(townName) has a population of \(population) and \(numberOfStoplights) stoplights."

print(townDescription)

 The \() syntax represents a placeholder in the String literal that accesses an instance’s value and places it (or “interpolates” it) within the new String. For example, \(townName) accesses the constant townName’s value and places it within the new String instance.

Give a screenshot of the final program lines and results for the playground.

Bronze Challenge Swift Chapter 2:

Add a new variable to your playground representing Knowhere’s level of unemployment. Which data type should you use? Give this variable a value and update townDescription to use this new information.

 

Mathias,Matthew. Swift Programming: The Big Nerd Ranch Guide (Big Nerd Ranch Guides) (Kindle Locations 602-610). Big Nerd Ranch Guides. Kindle Edition.

Part II: (50 pts.)

  1. I want you all to complete a write up on an app you frequently use.  This should be at least 1 page single spaced.  (30 points)

  • What is your app?

  • Who is their customer?

  • Who is their target market?

  • What other app user interfaces do you go to once you are at the app home screen?

  • Do they charge or is the app free?

  • Do they require any in app purchases?

  • How do they encourage users to download their app?

  • What else do you want to say about their app?

  1. Scanned in submittal of your hand drawn frequently used app (20 points). You should review and follow some basic app user interface design principles such as:

https://developer.apple.com/design/tips/ (Links to an external site.)

 (Links to an external site.)

https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/MobileHIG/ (Links to an external site.)

 (Links to an external site.)

https://developer.apple.com/design/ (Links to an external site.)

 (Links to an external site.)

https://www.linkedin.com/pulse/mobile-user-interface-design-tips-best-practices-michael-muli (Links to an external site.)

 (Links to an external site.)

http://www.goodui.org (Links to an external site.)

 (Links to an external site.)

If you need extra copies of the storyboard, I have attached them below.

storyboard-letter-16to9-2x1.pdf