数组和Swift
发布时间:2020-12-14 05:45:56 所属栏目:百科 来源:网络整理
导读:我正在尝试处理Swift中的应用程序,我使用数组面临以下错误: fatal error: Array index out of range 当应用程序为索引0处的数组赋值时,会出现这种情况: class DrawScene: SKScene { init(size: CGSize) { super.init(size: size) } var line = SKShapeNode
|
我正在尝试处理Swift中的应用程序,我使用数组面临以下错误:
fatal error: Array index out of range 当应用程序为索引0处的数组赋值时,会出现这种情况: class DrawScene: SKScene {
init(size: CGSize) {
super.init(size: size)
}
var line = SKShapeNode()
var path = CGPathCreateMutable()
var touch: UITouch!
var pts = [CGPoint]()
override func touchesBegan(touches: NSSet,withEvent event: UIEvent) {
/* Called when a touch begins */
touch = touches.anyObject() as UITouch!
self.pts[0] = touch.locationInNode(self) <-- Error appears here
drawLine()
}
一些想法? (我正在使用xcode 6 Beta 4)
你的数组最初是空的.
if self.pts.isEmpty {
self.pts.append(touch.locationInNode(self))
}
else {
self.pts[0] = touch.locationInNode(self)
}
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
