0

I want to make it so that there is a delay between each time the "universe" is shown, so that the user can see it at the screen before it changes. As of right now, I can only see the last one, because the other ones update too quickly.

EDIT: So I tried adding a NSTimer to make the action timed, and the app crashes when I run it, and in the console this appears: libc++abi.dylib: terminating with uncaught exception of type NSException

    var universeCounter = 0

    func paintUniverse () {

        var placeCounter = 0
        if universeCounter < simulatedUniverse.count {
            for place in simulatedUniverse[universeCounter] {
                if place == 1 {
        self.realCollectionView.cellForItemAtIndexPath(returnTheRightCell(placeCounter))?.contentView.backgroundColor = UIColor.whiteColor()
                }
                else {
            self.realCollectionView.cellForItemAtIndexPath(returnTheRightCell(placeCounter))?.contentView.backgroundColor = UIColor.blackColor()
                }
                placeCounter++
            }
            universeCounter++
        }
        else {
            timer.invalidate()
        }
    }
    timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: "paintUniverse", userInfo: nil, repeats: true)
PKLJ
  • 19
  • 6
  • There is nothing wrong with your timer. I'm guessing that your code that constantly increments placeCounter eventually tries to load an invalid cell. You haven't provided nearly enough information about the specifics of your application, or about your crash, for us to be able to help you. – Duncan C Mar 05 '16 at 21:41
  • @DuncanC So what this program does is take all the arrays from the simulatedUniverse: [[Int]] and paint every cell, corresponding to an Int in the array white if the Int is equal to 1, and black if it equals to 0. The app crashes when I first run it, so no cells are painted, sorry for not having specified this before. – PKLJ Mar 05 '16 at 22:10

0 Answers0