// // ViewController.swift // Dog Breeds 2 // // Created by lrosier on 11/5/18. // Copyright © 2018 lrosier. All rights reserved. // import UIKit import AVFoundation class ViewController: UIViewController { // FINISH ME // create a variable called dogPosition and assign // it a value of zero ???? // FINISH ME // create a variable called dogNames and assign // it a value of ["Beagle", "Bulldog", "Golden Retriever"] // this is a list of values (or an array) ??? ?????? = ["Beagle", "Bulldog", "Golden Retriever"] // FINISH ME // create a variable called dogMessages and assign // it a value of ["I am a Beagle", "I am a Bulldog", "I am a Golden Retriever"] // this is a list of values (or an array) ??? ?????? = ??????? // FINISH ME // create a variable called dogPictures and assign // it a value of ["Beagle.png","Bulldog.png", "GoldenRetriever.png"] // this is a list of all of the dog filenames for the images ??? ?????? = ["Beagle.png","Bulldog.png", "GoldenRetriever.png"] // FINISH ME // create a variable called dogInfo // this is a list of all the text data for each dog (for the TextView) ??? ????? = ["The beagle is a very common family dog.","The bulldog is a very friendly family dog.","The Golden Retriever is a very friendly dog."] // FINISH ME // create a variable called timer ??? ????? = Timer() let synth = AVSpeechSynthesizer() // FINISH ME // Connect your dog label to this variable @IBOutlet weak var dogLabel: UILabel! // FINISH ME // Connect your dog ImageView to this variable @IBOutlet weak var dogPictureImageView: UIImageView! // FINISH ME // Connect your dog TextView to this variable @IBOutlet weak var dogInfoTextView: UITextView! // FINISH ME // Connect your slider to this variable // The slider determines how fast the timer runs @IBOutlet weak var slider: UISlider! // this function gets called each time that you move the slider // sender is a reference to the slider @IBAction func sliderValueChangedEvent(_ sender: UISlider) { timer.invalidate() // not really necessary, but it's good to know about the value property slider.value = sender.value // FINISH ME // convert slider.value to a Double object let seconds = ??????(slider.value) timer = Timer.scheduledTimer(timeInterval: seconds, target: self, selector: #selector(timerAction), userInfo: nil, repeats: true) } func speak(_ message:String) { let speech = AVSpeechUtterance(string: message) synth.speak(speech) } func updateDogPage() { // FINISH ME // set the dogLabel's text to dogNames[dogPosition] // this will set the label at the top of the view to // the type of dog dogLabel.???? = ????[?????] // here we get a reference to the image of the dog let dogImage = UIImage(named:dogPictures[dogPosition]) // FINISH ME // set dogText to dogNames[dogPosition] let dogText = ?????? // FINISH ME // set the image field to dogImage dogPictureImageView.image = ????? // FINISH ME // set the dogInfoTextView text field to dogText dogInfoTextView.??? = ?????? speak(dogMessages[dogPosition]) } func nextPage() { // FINISH ME // add 1 to variable dogPosition dogPosition = if dogPosition >= dogPictures.count { // FINISH ME // set your variable dogPosition to zero ?????? } // FINISH ME // call the updateDogPage() method (function) ?????? } func nextPageWithStop() { // FINISH ME // add 1 to variable dogPosition dogPosition = ???? if dogPosition >= dogPictures.count { // FINISH ME // set dogPosition to 1 less than your dogNames.count // dogNames.count is the number of dogs in the list ????? = ????? } // FINISH ME // call the updateDogPage() method (function) ??????? } func lastPage() { // FINISH ME // set dogPosition to the number of dogPictures - 1 dogPosition = dogPictures.???? - 1 // FINISH ME // call the updateDogPage() method (function) ????? } @IBAction func firstButtonEvent(_ sender: UIButton) { // FINISH ME // set dogPosition to zero ?????? // FINISH ME // call the updateDogPage() method (function) ?????? } @IBAction func prevButtonEvent(_ sender: UIButton) { // FINISH ME // subtract 1 from your dogPosition dogPosition = ???? - 1 // FINISH ME // see if dogPosition is less than zero if ???? < ? { // FINISH ME // set dogPosition to zero ????? } // FINISH ME // call the updateDogPage() method (function) ?????? } @IBAction func nextButtonEvent(_ sender: UIButton) { nextPageWithStop() } @IBAction func lastButtonEvent(_ sender: UIButton) { // FINISH ME // set dogPosition to the number of dogPictures - 1 dogPosition = dogPictures.????? - 1 // FINISH ME // call the updateDogPage() method (function) ??????? } @IBAction func startSlideShowEvent(_ sender: UIButton) { // FINISH ME // convert slider.value to a Double object let seconds = Double(slider.value) timer = Timer.scheduledTimer(timeInterval: seconds, target: self, selector: #selector(timerAction), userInfo: nil, repeats: true) } @IBAction func stopSlideShowEvent(_ sender: UIButton) { // we turn the timer off timer.invalidate() } // this function gets called every so many seconds @objc func timerAction() { // FINISH ME // call the method (or function) nextPage() ????? } override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. updateDogPage() // every 4 seconds for timer event slider.minimumValue = 1 // sets the lowest value for the slider slider.maximumValue = 10 // sets the highest value for the slider slider.value = 4 // sets the current value for the slider } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } }