-3

I'm practicing iOS app programming by watching Stanford for iOS (before 6 years) and these

codes are when it comes to facial expression app.

Here are FaceView module part of the app(the Model, among MVCs)

and these codes are correct logic and grammar in terms of Swift

import UIKit

@IBDesignable
class FaceView: UIView {

    @IBInspectable
    var scale: CGFloat = 0.90 { didSet { setNeedsDisplay() } }
    @IBInspectable
    var mouthCurvature: Double = 0.0 { didSet { setNeedsDisplay() } } // 1 full smile, -1 full frown
    @IBInspectable
    var eyesOpen: Bool = true { didSet { setNeedsDisplay() } }
    @IBInspectable
    var eyeBrowTilt: Double = 0.0 { didSet { setNeedsDisplay() } } // 1 fully relaxed, -1 full furrow
    @IBInspectable
    var color: UIColor = UIColor.blue { didSet { setNeedsDisplay() } }
    @IBInspectable
    var lineWidth: CGFloat = 5.0 { didSet { setNeedsDisplay() } }
    
    func changeScale(recognizer: UIPinchGestureRecognizer) {
        switch recognizer.state {
        case .changed, .ended:
            scale *= recognizer.scale
            recognizer.scale = 1.0
        default:
            break
        }
    }
...

But I just imitate what this video lectures this is what happened!

import UIKit

class FaceViewController: UIViewController {

    var expression = FacialExpression(eyes: .Open, eyeBrows: .Normal, mouth: .Smile) {
        didSet {
            updateUI()
        }
    }
    
    @IBOutlet weak var faceView: FaceView! {
        didSet {
            faceView.addGestureRecognizer(UIPinchGestureRecognizer(
                target:faceView, action: #selector(FaceView.changeScale(_:)) **Type 'FaceView' has no member 'changeScale'**
            ))
            let happierSwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(FaceViewController.increaseHappiness)
            )
            happierSwipeGestureRecognizer.direction = .up
            faceView.addGestureRecognizer(happierSwipeGestureRecognizer)
            
            let sadderSwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(FaceViewController.decreaseHappiness)
            )
            sadderSwipeGestureRecognizer.direction = .down
            faceView.addGestureRecognizer(sadderSwipeGestureRecognizer)
            
            updateUI()
        }
    }
    
    @objc func increaseHappiness() {
        expression.mouth = expression.mouth.happierMouth() **Value of type 'FacialExpression.Mouth' has no member 'happierMouth'**
    }
    
    @objc func decreaseHappiness() {
        expression.mouth = expression.mouth.sadderMouth() **Value of type 'FacialExpression.Mouth' has no member 'sadderMouth'**
    }
    
    private var mouthCurvatures = [FacialExpression.Mouth.Frown: -1.0, .Grin: 0.5, .Smile: 1.0, .Smirk: -0.5, .Neutral: 0.0]
    private var eyeBrowTilts = [FacialExpression.EyeBrows.Relaxed: 0.5, .Furrowed: -0.5, .Normal: 0.0]
    
    private func updateUI() {
        switch expression.eyes {
        case .Open: faceView.eyesOpen = true
        case .Closed: faceView.eyesOpen = false
        case .Squinting: faceView.eyesOpen = false
        }
        faceView.mouthCurvature = mouthCurvatures[expression.mouth] ?? 0.0
        faceView.eyeBrowTilt = eyeBrowTilts[expression.eyeBrows] ?? 0.0
    }
    
    @IBAction func toggleEyes(_ sender: UITapGestureRecognizer) {
        if recognizer.state == .ended { **Cannot find 'recognizer' in scope**
            switch expression.eyes {
            case .Open: expression.eyes = .Closed
            case .Closed: expression.eyes = .Open
            case .Squinting: break
            }
        }
    }
}

cf) I described detailed errors '** ~ **' mark signs

1 Answers1

0

Some of your issues might be due to carelessness, but I'm afraid that in general the real reason is that you're using a very old tutorial and the Swift language has completely changed since then. For example, nowadays you would need to change

 func changeScale(recognizer: UIPinchGestureRecognizer)

to

 func changeScale(_ recognizer: UIPinchGestureRecognizer)

(note the underscore) in order for the rest of your code to compile, i.e. so that #selector(FaceView.changeScale(_:)) matches the method signature. But you have no way of knowing that; I think your best bet here is to abandon this tutorial, as it will do you more harm than good — it is just too old.

matt
  • 515,959
  • 87
  • 875
  • 1,141