Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

_cmd in Swift language [duplicate]

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.

like image 558
LongNV Avatar asked Jun 30 '14 05:06

LongNV


1 Answers

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"
like image 195
Nate Cook Avatar answered Nov 12 '22 12:11

Nate Cook