My previous question was marked duplicate. I tried to edit my question, but I can't remove duplicate tag, so I have to create a new one What is the swift equivalent to _cmd?
I want to get current method name to use in a format message similar to this one
[NSExeception raise:NSInternalInconsistencyException format:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)]
Also, I want to use _cmd as key to set associated object. Does anyone know the equivalent of _cmd in Swift I really appreciate.
There's no _cmd
, but you can use __FUNCTION__
to get the name of the current function, which can be used in place of selectors most of the time.
func myUnimplementedMethod() {
println("You must override \(__FUNCTION__) in a subclass")
}
myUnimplementedMethod()
// prints "You must override myUnimplementedMethod() in a subclass"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With