Я запускаю Swift 2 в Xcode 7. Я просмотрел пару примеров отладки этой ошибки после того, как их приложение разбилось, но не может понять, как отлаживать это с помощью моего собственного приложения. Хотя я не полностью им удобен, после включения некоторых точек останова, я думаю, что ошибка находится в верхней части кода. Ниже мой код, и любая помощь будет замечательной! Я новичок, поэтому ничего сложного, спасибо, спасибо.Как отлаживать завершение с неперехваченным исключением типа NSException
import UIKit
class ViewController: UIViewController {
func randomPoint() -> CGPoint {
let randomPoint: CGPoint = CGPoint(x:CGFloat(arc4random()%320),y:CGFloat(arc4random()%568))
return randomPoint
}
func randomColor() -> UIColor {
let red = CGFloat(drand48())
let green = CGFloat(drand48())
let blue = CGFloat(drand48())
return UIColor(red: red, green: green, blue: blue, alpha: 1.0)
}
func spawnEnemy() {
let enemy: UIButton = UIButton(frame: CGRect(x: 160, y: 160, width: 50, height: 50))
enemy.backgroundColor = randomColor()
enemy.center = randomPoint()
enemy.addTarget(self, action: Selector("buttonPushed:"), forControlEvents: UIControlEvents.TouchUpInside)
self.view.addSubview(enemy)
}
func buttonPushed(sender : UIButton) {
sender.backgroundColor = UIColor.whiteColor()
}
override func viewDidLoad() {
super.viewDidLoad()
NSTimer.scheduledTimerWithTimeInterval(0.5, target: self, selector: Selector("spawnEnemy:"), userInfo: nil, repeats: true)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
ошибки я получил:
2016-02-12 08:31:47.665 app[84179:14802824] -[app.ViewController spawnEnemy:]: unrecognized selector sent to instance 0x7fc7c94474a0
2016-02-12 08:31:47.687 app[84179:14802824] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[app.ViewController spawnEnemy:]: unrecognized selector sent to instance 0x7fc7c94474a0'
*** First throw call stack:
(
0 CoreFoundation 0x0000000107ed0e65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000109c10deb objc_exception_throw + 48
2 CoreFoundation 0x0000000107ed948d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x0000000107e2690a ___forwarding___ + 970
4 CoreFoundation 0x0000000107e264b8 _CF_forwarding_prep_0 + 120
5 Foundation 0x00000001082b60d1 __NSFireTimer + 83
6 CoreFoundation 0x0000000107e30c84 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
7 CoreFoundation 0x0000000107e30831 __CFRunLoopDoTimer + 1089
8 CoreFoundation 0x0000000107df2241 __CFRunLoopRun + 1937
9 CoreFoundation 0x0000000107df1828 CFRunLoopRunSpecific + 488
10 GraphicsServices 0x000000010c4e3ad2 GSEventRunModal + 161
11 UIKit 0x00000001086ed610 UIApplicationMain + 171
12 app 0x0000000107cf343d main + 109
13 libdyld.dylib 0x000000010a71992d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Пожалуйста, укажите фактическое содержание сообщения об ошибке в своем вопросе. Рассказывать, где это происходит в коде, также может помочь много. – Moritz
Хорошо, я отредактирую его –
Из описания тега iOS: http://www.raywenderlich.com/10209/my-app-crashed-now-what-part-1 – rmaddy