[Swift Day 1 ] - Tap not working


#1

I am new to programming and I trying to follow along with the videos.

My code is working except for the tap. I am not receiving any errors so it runs fine, just on the tap nothing happens. It’s not printing out the “tap” in the console.

Any help would be appreciated!

Here is my code:

import UIKit

class ViewController: UIViewController {

// 1. Declare ivars (instance variable)
var myFirstLabel:UILabel!
var iPhoneLabel: UILabel!



override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    
    // 2. Create the labels
    
    myFirstLabel = UILabel()
    iPhoneLabel = UILabel()
    
    addLabels()
    
    var tapGesture = UIGestureRecognizer(target: self, action: Selector("handleTapGesture:"))
    view.addGestureRecognizer(tapGesture)
    
}

func handleTapGesture (tapGesture:UITapGestureRecognizer) {
    println("tap")
    
    addLabels()
}

func addLabels () {
    
    myFirstLabel.text = "My first"
    myFirstLabel.font = UIFont.systemFontOfSize(36)
    myFirstLabel.sizeToFit() // resize based on text and font size.
    myFirstLabel.center = CGPoint(x: 100, y: 40) //change center position. Use integer values
    view.addSubview(myFirstLabel)
    
    UIView.animateWithDuration(0.5, delay: 0.0, usingSpringWithDamping: 0.9, initialSpringVelocity: 0.0, options: nil, animations: {
            self.myFirstLabel.center = CGPoint(x: 100, y: 40 + 200)
        }, completion: nil)
    
    iPhoneLabel.text = "iPhone app"
    iPhoneLabel.font = UIFont.boldSystemFontOfSize(48)
    iPhoneLabel.sizeToFit()
    iPhoneLabel.center = CGPoint(x: 200, y: 90)
    view.addSubview(iPhoneLabel) //use this to make it show on the screen
    
    iPhoneLabel.alpha = 0 // Hidden = 0
    
    UIView.animateWithDuration(2.0, delay: 0.5, usingSpringWithDamping: 0.2, initialSpringVelocity: 0.0, options: nil, animations: {
            self.iPhoneLabel.center = CGPoint(x: 200, y: 90 + 200)
            self.iPhoneLabel.alpha = 1 //Visible = 1
        }, completion: nil)
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

}


#2

Change this UIGestureRecognizer to this: UITapGestureRecognizer …


#3

Thank you!

I figured it out right when you responded.

Appreciate the help!