I am trying to learn Swift, by following the Stanford University CS193-P course. Was OK until I got to lecture 5.
Getting multiple errors, even though I have checked the code against the Demo Code.
Here is the file where the errors occured, with errors noted after the file.
Is it to do with the way the files are linked, as this was not to clear in the lecture?
/
/
/
/
/
/
import UIKit
class ViewController: UIViewController
{
var expression = FacialExpression(eyes: .closed, mouth: .frown) { //eyes is indicated with triangle under e
didSet {
updateUI()
}
}
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
}
private let mouthCurvatures =
[FacialExpression.Mouth.grin:0.5,.frown:-1.0,.smile:1.0,.neutral:0.0,.smirk:-0.5]
@IBOutlet weak var FaceView: FaceView! {
didSet {
let handler = #selector(FaceView.changeScale(byReactingTo:))
let pinchRecognizer = UIPinchGestureRecognizer(target: FaceView, action: handler)
FaceView.addGestureRecognizer(pinchRecognizer)
let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(toggleEyes(byReactingTo:)))
tapRecognizer.numberOfTapsRequired = 1
FaceView.addGestureRecognizer(tapRecognizer)
let swipeUpRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(increaseHappiness))
swipeUpRecognizer.direction = .up
FaceView.addGestureRecognizer(swipeUpRecognizer)
let swipeDownRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(decreaseHappiness))
swipeDownRecognizer.direction = .down
FaceView.addGestureRecognizer(swipeDownRecognizer)
updateUI()
}
}
func increaseHappiness()
{
expression = expression.happier
}
func decreaseHappiness(){
expression = expression.sadder
}
func toggleEyes(byReactingTo taprecognizer: UITapGestureRecognizer){
if taprecognizer.state == .ended {
let eyes: FacialExpression.Eyes = (expression.eyes == .closed) ? .open : .closed
expression = FacialExpression(eyes: eyes, mouth: expression.mouth)
}
}
}Errors
Line 11 - argument passed to call that takes no arguments
Demo code can be seen on Google Drive owner: Digit77.com
Thanks! But I am unclear where the code goes. I assume it's in FacialExpression.swift?
Also, What about the other facial expressions?
This is the other file:
/
/
/
/ Hudson on 08/02/2018.
/ Tony Hudson. All rights reserved.
/
import Foundation
struct FacialExpression {
enum Eyes: Int {
case open
case closed
case squinting
}
enum Mouth: Int {
case frown
case smirk
case grin
case neutral
case smile
var sadder: Mouth {
return Mouth(rawValue: rawValue - 1) ?? .frown
}
var happier: Mouth {
return Mouth(rawValue: rawValue + 1) ?? .smile
}
}
var sadder: FacialExpression {
return FacialExpression(eyes: self.eyes, mouth: self.mouth.sadder)
}
var happier: FacialExpression {
return FacialExpression(eyes: self.eyes, mouth: self.mouth.happier)
}
let eyes = Eyes
let mouth = Mouth
}Sorry I did not show this in the first post!
This file also has the same errors on lines 32 & 35. Also different errors on lines 37 & 38. (Expected Member name or constructor call after type name)
The code is as supplied by the tutor, so should work providing ther are no typos, but it dosn't.
What am I missing?
Here is the source of the code I used: https://github.com/duliodenis/cs193p-Winter-2017
It can be found under DemoCode for Lecture 5