I am doing some learning things in swift. And I am using version Swift 4.
I am trying to do some method overriding thing.
class cricket {
func print() {
print("Super class called")
}
}
class tennis : cricket {
override func print() {
print("Sub class called")
}
}
let circInstance = cricket()
circInstance.print()
let tennisInstance = tennis()
tennisInstance.print()
But, If I would run above program in my playground of Xcode, Getting following error at print statements.
error: MyPlayground.playground:508:15: error: argument passed to call that takes no arguments
print("Super class called")
~^~~~~~~~~~~~~~~~~~~~~
error: MyPlayground.playground:514:15: error: argument passed to call that takes no arguments
print("Sub class called")
~^~~~~~~~~~~~~~~~~~~
Any suggestions?
You have a name conflict with the local method. You have to use the qualified name:
Swift.print("Super class called")
Otherwise you are trying to call self.print()
which takes no arguments.
Swift.
here is the name of the Swift Standard Library module that contains the print function.