Take 2 SWIFT Bites Out of Apple’s New Programming Language

Posted on Updated on

by Linda Cohen

Building with XCode through http://www.appledeveloper.com . It is a 4GB application

WEB187 is the iOS developer course, although WEB251 is also used at another college. WEB151 ANdroid WEB251 iOS at Waketech.edu

We’ll be building a discount app. There is a LET command which will allow a variable to become a constant. However, forms are also required to be a LET command, so we’ll be looking at that as well.

We’ll be suing a single VIEW and sticking with that VIEW in this class. We chose single view. We’ve given a product name, and we’ll create. This is made for iPAD, but there are different ways to create for the iPhone. The target we’re using ins 9.2. If you have an older version, use that.

The word TEAM says NONE. That means that your work is open source. That allows you to work for android, windows, or apple.

When working with android, its all xml in the background. Then you had to create the JAVA. Android developer studio seems to have some wonderful parts

The STORYBOARDis where we’ll design the interface for the application. Clicking on the first view, we’ll see the information on the view. You can add titles and other materials here as well.

Naming Conventions for the Objects

  • LABELS are for output only and start with lbl
  • TEXT fields are for input and start with txt
  • BUTTONS are to create an event where the actual code goes and they start with btn

A Label is added, and the right column allows us to give specifics about these items. Several display pieces are allowed to show us the basic profiles. Some basic labels are added in here, names, discount amounts, amount of the meal without text. And then, we add a button. We did not add labels with names.


ONce you have the interface, you need to relate the code behind the scenes. Next right column with left boxes allow us to visit this graphic layout in several different fashions. txt is for text lbl is for labels

Buttons work similarly, dragging the visual side to the code area. While the others are OUTLETS, the button is an ACTION. “Touch up inside” is the same as click or touch. Applie will be different and not count if dragged across.

Initialize all variables BEFORE they are used.

let TAX = 0.07  //  Declare TAX as a constant

var subTotal : Double = 0.0

var total : Double = 0.0

lblDisplayTotal.text = “”

let name = txtName.text!

let discountAmt(txtDisAmt.text!)

let mealCost = Double(txtMealCost.text!)

This material does not require () for IF statment, but does require {

if discoutnAmt != nil && mealCost != nil


   subTotal = mealCost! – discountAmt!    // create subtotal

   total = subTotal*TAX + subTotal   // create total

   lblDIsplayTOtal.textColor = UIColor.blueColor()

lblDisplayTotal.text = String(format: “Thank you, /(name) with tax, your total is %.2f”, total )

Once everything is selected, choose “Get Results” The PIN tool. Clicking on the top three lines will tell you the number of restraints you’ll need to keep this in place. These restraints allow you to keep these items in place with a responsive design. To get around this, Clear the restraints, make changes, and then return the constraints.


We loaded up the program. It worked. Once you’ve developed in the open source section, you can attach your ipad directly (because we programmed for ipad) and it will automatically add this to your device.