数组和Swift

前端之家收集整理的这篇文章主要介绍了数组和Swift前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试处理Swift中的应用程序,我使用数组面临以下错误: @H_403_1@fatal error: Array index out of range

当应用程序为索引0处的数组赋值时,会出现这种情况:

@H_403_1@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)

你的数组最初是空的. @H_403_1@if self.pts.isEmpty { self.pts.append(touch.locationInNode(self)) } else { self.pts[0] = touch.locationInNode(self) }

猜你在找的Swift相关文章