Created
September 28, 2014 23:21
-
-
Save ronaldmannak/b2a126fe746732a730f9 to your computer and use it in GitHub Desktop.
Trying to solve conflicting names of functions and properties in Swift. How do I call the function position() from within a class that has a property with the same name?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SpriteKit | |
func position(number: Int)->Int { | |
return number | |
} | |
class node: SKNode { | |
// Note: SKNode has a property called position (a CGPoint) | |
func test() { | |
// Attempting to call function position | |
let i = position(2) // Compiler Error: not identical to CGPoint | |
let i: Int = position(2) // Nope, doesn't work either | |
} | |
} |
Is your function just a global function, or is it encapsulated in any way? If it's encapsulated, you can use the namespace it's in:
class MyCustomClass {
class func position(number: Int)->Int {
return number
}
}
class node: SKNode {
// Note: SKNode has a property called position (a CGPoint)
func test() {
// Attempting to call function position
let i = MyCustomClass.position(2)
}
}
@NatashaTheRobot it is a global function
You should be able to call it as Swift.position(2), but it's not working...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can also extend SKNode: