Swift 为什么这个NSTimer会崩溃?

Swift 为什么这个NSTimer会崩溃?,swift,Swift,当我运行这段代码时,甚至在它第一次运行NSTimer之前,它就崩溃了,在控制台中输出:“libc++abi.dylib:终止为NSException类型的未捕获异常”。我已经想了好几天了,但是找不到解决办法,欢迎任何帮助,谢谢 编辑:代码位于iAction中,其目的是根据数组simulatedUniverse[universeCounter]中相应整数的值,将集合视图中某些单元格的颜色更改为白色或黑色。在我添加NSTimer之前,它正在工作,但由于屏幕更新太快,我只能看到显示的最后一个图案,很抱

当我运行这段代码时,甚至在它第一次运行NSTimer之前,它就崩溃了,在控制台中输出:“libc++abi.dylib:终止为NSException类型的未捕获异常”。我已经想了好几天了,但是找不到解决办法,欢迎任何帮助,谢谢

编辑:代码位于iAction中,其目的是根据数组simulatedUniverse[universeCounter]中相应整数的值,将集合视图中某些单元格的颜色更改为白色或黑色。在我添加NSTimer之前,它正在工作,但由于屏幕更新太快,我只能看到显示的最后一个图案,很抱歉之前没有添加此图案

控制台输出: 2016-03-06 23:44:54.935 Digiverse[33095:261291]-[Digiverse.SimulatorViewController paintUniverse]:发送到实例0x7f91c504c6c0的无法识别的选择器 2016-03-06 23:44:54.942 Digiverse[33095:261291]*由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:'-[Digiverse.SimulatorViewController paintUniverse]:未识别的选择器发送到实例0x7f91c504c6c0' *第一次抛出调用堆栈: ( 0 CoreFoundation 0x0000000105f92e65例外预处理+165 1 libobjc.A.dylib 0x0000000107CD2DB objc_异常_抛出+48 2 CoreFoundation 0x0000000105f9b48d-[NSObject(NSObject)不识别选择器:+205 3 CoreFoundation 0x0000000105ee890a\uuuuuuuuuuuuuuu转发+970 4 CoreFoundation 0x0000000105ee84b8\u CF\u转发\u准备\u 0+120 5基金会0x000 000 010637 80d1 <强> nFiffTime+ 83 6 CoreFoundation 0x0000000105ef2c84\uuuu CFRUNLOOP\u正在调用\u OUT\u到\u计时器\u回调\u函数+20 7 CoreFoundation 0x0000000105ef2831\uuu CFRunLoopDoTimer+1089 8 CoreFoundation 0x0000000105eb4241_u CFRunLoopRun+1937 9 CoreFoundation 0x0000000105eb3828 CFRunLoopRunSpecific+488 10图形服务0x000000010a5a8ad2 GSEventRunModal+161 11 UIKit 0x00000001067af610 UIApplicationMain+171 12 Digiverse 0x0000000105da524d干管+109 13 libdyld.dylib 0x00000001087db92d开始+1 14???0x0000000000000001 0x0+1 ) libc++abi.dylib:以NSException类型的未捕获异常终止 (lldb)

let simAlgorithm=UniverseSimulationAlgorithm()
func checkPopPlaces(strPlaces:[字符串]?)->[Int]?{
变量填充位置:[Int]?
如果strPlaces!==[]{
如果尺寸小于7{
populatedPlaces=零
}
否则{
populatedPlaces=[]
}
}
否则{
populatedPlaces=[]
用于填充StringPlaces中的str{
populatedPlaces!.append(Int(str)!)
}
}
返回人口稠密的地方
}
var simulatedUniverse:[[Int]]{
返回simAlgorithm.simulateUniverse(大小、填充位置:checkPopPlaces(填充的StringPlaces))
}
var universeCounter=0
func paintUniverse(universarray:[[Int]],var uniCounter:Int,trueSize:Int){
变量placeCounter=0
如果uniCounter
崩溃日志中最重要的信息是

由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:'-[Digiverse.SimulatorViewController paintUniverse]:未识别的选择器发送到实例0x7f91c504c6c0'

计时器声明行中的选择器
paintUniverse
要求在类的顶层有一个不带参数的方法
func paintUniverse()

函数
paintUniverse
有三个参数,无论如何都不能用作计时器选择器

计时器选择器可以没有任何参数:

选择器:“paintUniverse”
->
func paintUniverse()

或者一个参数必须是
NSTimer
实例,并且
选择器必须有一个尾随冒号:


选择器:“paintUniverse:
->
func paintUniverse(计时器:NSTimer)

@matt很抱歉缺少上下文,请检查编辑,这是什么意思?崩溃的行:“class AppDelegate:UIResponder,UIApplicationLegate{”.并且控制台的整个输出在edit@matt我错了,你最后的答案很有效,非常感谢。
let simAlgorithm = UniverseSimulationAlgorithm()

func checkPopPlaces ( strPlaces: [String]? ) -> [Int]? {

    var populatedPlaces: [Int]?

    if strPlaces! == [] {

        if size < 7 {
            populatedPlaces = nil
        }
        else {
            populatedPlaces = []
        }

    }
    else {

        populatedPlaces = []

        for str in populatedStringPlaces! {
            populatedPlaces!.append(Int(str)!)
        }

    }

    return populatedPlaces

}

var simulatedUniverse: [[Int]] {

    return simAlgorithm.simulateUniverse( size, populatedPlaces: checkPopPlaces(populatedStringPlaces))

}

var universeCounter = 0

func paintUniverse ( universeArray: [[Int]], var uniCounter: Int, trueSize: Int ) {

    var placeCounter = 0

    if uniCounter < universeArray.count {

        for place in universeArray[uniCounter] {

            if place == 1 {
                self.realCollectionView.cellForItemAtIndexPath(returnTheRightCell(placeCounter, rightSize: trueSize ))?.contentView.backgroundColor = UIColor.whiteColor()
            }
            else {
                self.realCollectionView.cellForItemAtIndexPath(returnTheRightCell(placeCounter, rightSize: trueSize ))?.contentView.backgroundColor = UIColor.blackColor()
            }

            placeCounter++

        }

        uniCounter++
    }
    else {
        timer.invalidate()
    }

}

@IBAction func startButtonPressed(sender: AnyObject) {

    timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: "paintUniverse", userInfo: nil, repeats: true)

}