Dordor Dordor - 3 months ago
174 0

I was making a title program when i got this error fatal error: Array index out of range (lldb)
i don't know what it means and how to debug it help please

Swift

fatal error: Array index out of range (lldb)

//
//  thirdViewController.swift
//  GameDemO
//
//  Created by Dordor Zheng on 8/31/16.
//  Copyright © 2016 Dordor Zheng. All rights reserved.
//

import UIKit



class thirdViewController: UIViewController {

    
    var PikatchuArray : Array<UIImage> = [
        UIImage(named: "Pikachu.png")!,
        UIImage(named: "Pikachu02.png")!,
        UIImage(named: "Pikachu03.png")!,
        UIImage(named: "Pikachu04.png")!,
        UIImage(named: "Pikachu05.png")!,
        UIImage(named: "Pikachu06.png")!,
        UIImage(named: "Pikachu07.png")!,
        UIImage(named: "Pikachu08.png")!
    ]
    
    var lolipopArray : Array<UIImage> = [
        UIImage(named: "lolipop01.png")!,
        UIImage(named: "lolipop02.png")!,
        UIImage(named: "lolipop03.png")!,
        UIImage(named: "lolipop04.png")!,
        UIImage(named: "lolipop05.png")!,
        UIImage(named: "lolipop06.png")!,
        UIImage(named: "lolipop07.png")!,
        UIImage(named: "lolipop08.png")!,
    ]
    

    
    var marshmallowArray : Array<UIImage> = [
        UIImage(named: "marshmallow01.png")!,
        UIImage(named: "marshmallow02.png")!,
        UIImage(named: "marshmallow03.png")!,
        UIImage(named: "marshmallow04.png")!
    ]

    
    var owlArray : Array<UIImage> = [
        UIImage(named: "owl.png")!,
        UIImage(named: "owl02.png")!,
        UIImage(named: "owl03.png")!,
        UIImage(named: "owl04.png")!,
        UIImage(named: "owl05.png")!,
        UIImage(named: "owl06.png")!
    ]
    
    var popsicleArray : Array<UIImage> = [
        UIImage(named: "popsicle.png")!,
        UIImage(named: "popsicle02.png")!,
        UIImage(named: "popsicle03.png")!,
        UIImage(named: "popsicle04.png")!,
        UIImage(named: "popsicle05.png")!,
        UIImage(named: "popsicle06.png")!,
]
    
    var sheepArray : Array<UIImage> = [
        UIImage(named: "sheep.png")!,
        UIImage(named: "sheep02.png")!,
        UIImage(named: "sheep03.png")!,
        UIImage(named: "sheep04.png")!,
        UIImage(named: "sheep05.png")!,
        UIImage(named: "sheep06.png")!
    ]
    
    
    var cloudArray : Array<UIImage> = [
        UIImage(named: "cloud.png")!,
        UIImage(named: "cloud02.png")!,
        UIImage(named: "cloud03.png")!,
        UIImage(named: "cloud04.png")!,
        UIImage(named: "cloud05.png")!,
        UIImage(named: "cloud06.png")!,
        UIImage(named: "cloud07.png")!
    ]
    
    var appleArray : Array<UIImage> = [
        UIImage(named: "candyApple.png")!,
        UIImage(named: "candyApple02.png")!,
        UIImage(named: "candyApple03.png")!,
        UIImage(named: "candyApple04.png")!,
        UIImage(named: "candyApple05.png")!,
        UIImage(named: "candyApple06.png")!,
    ]
    
    
    var numberArray : Array<String> = [
        "1",
        "2",
        "3",
        "4"
    ]
    
    
    
    var nameArray : Array<String> = [
        "ONE",
        "TWO",
        "THREE",
        "FOUR"
    ]
    
    
    @IBOutlet weak var NAME: UILabel!
    
    
    
    @IBOutlet weak var Number: UILabel!
    
    
    @IBOutlet weak var firstImg: UIImageView!

    
    @IBOutlet weak var secondImage: UIImageView!
    
    
    var Timer = NSTimer()
    var Timmer: NSTimer?
    var allArray : Array<Array<UIImage>>?
    var allArrayTwo : Array<Array<UIImage>>?
    var stepNum : Int = 0
    
    
    
    
    
   
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    

        
        allArray = []
        allArray?.append(PikatchuArray)
        allArray?.append(marshmallowArray )
        allArray?.append(popsicleArray)
        allArray?.append(appleArray)
      
        
        allArrayTwo = []
        allArrayTwo?.append(lolipopArray)
        allArrayTwo?.append(owlArray)
        allArrayTwo?.append(sheepArray)
        allArrayTwo?.append(cloudArray)
        
        
        
        firstImg.animationImages = allArray![stepNum]
        firstImg.animationDuration = 0.9
        firstImg.startAnimating()
        
        
        
        secondImage.animationImages = allArrayTwo![stepNum]
        secondImage.animationDuration = 0.9
        secondImage.startAnimating()

        
        Timmer = NSTimer.scheduledTimerWithTimeInterval(4.0, target: self, selector: "myFunc", userInfo: nil, repeats: true)

        
        
        
        

    }
    
    
    func myFunc() {
        
        
        stepNum++
        
        Number.text = numberArray[stepNum]
        
        NAME.text =  nameArray[stepNum]
        
        if(stepNum>=allArray?.count){
            stepNum = 0
            
        }
        
        firstImg.animationImages = allArray![stepNum]
        firstImg.animationDuration = 1.2
        firstImg.startAnimating()
        
        
        secondImage.animationImages = allArrayTwo![stepNum]
        secondImage.animationDuration = 0.9
        secondImage.startAnimating()

        
    }


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

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
Comments