为什么可以';我不能在func Swift中使用self吗
我试图在一个函数中将SKSpriteNodes添加到视图中,但Xcode不允许我这样做。它给了我一个错误“使用未解析的标识符'self'” Nas 要使func能够使用“self”,它必须是类的一部分 “self”指的是应用方法(或用Swift术语:“func”)的当前实例。如果func是在全局级别定义的,那么If不是类的一部分,因此它不能与类的实例相关联为什么可以';我不能在func Swift中使用self吗,swift,Swift,我试图在一个函数中将SKSpriteNodes添加到视图中,但Xcode不允许我这样做。它给了我一个错误“使用未解析的标识符'self'” Nas 要使func能够使用“self”,它必须是类的一部分 “self”指的是应用方法(或用Swift术语:“func”)的当前实例。如果func是在全局级别定义的,那么If不是类的一部分,因此它不能与类的实例相关联 因此,在该上下文中不可能使用“self”。确保该方法出现在类的开括号和右括号中 甲级 { //您需要在这里定义一个方法 } //你可以在这里
因此,在该上下文中不可能使用“self”。确保该方法出现在类的开括号和右括号中 甲级 { //您需要在这里定义一个方法 } //你可以在这里申报
func indicate() {
if test == 0 {
var large = ((CGFloat(largest)*54) - 29) - selectedNode.position.x
var small = selectedNode.position.x - ((CGFloat(smallest)*54) - 29)
indicatorRight.position = CGPointMake(selectedNode.position.x + large, selectedNode.position.y)
indicatorRight.userInteractionEnabled = true
indicatorRight.zPosition = 0.5
indicatorLeft.position = CGPointMake(selectedNode.position.x - small, selectedNode.position.y)
indicatorLeft.userInteractionEnabled = true
indicatorLeft.zPosition = 0.5
println(indicatorLeft.position)
// println(smallest)
self.addChild(indicatorRight)
self.addChild(indicatorLeft)
}
}