Swift语言中的_cmd [英] _cmd in Swift language
问题描述
我之前的问题被标记为重复.我试图编辑问题,但无法删除重复的标签,因此必须创建一个新标签 等于_cmd的快捷键是什么?
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)]
此外,我想使用_cmd作为设置关联对象的键.我真的很感谢有人知道Swift中的_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.
推荐答案
没有_cmd
,但是您可以使用__FUNCTION__
来获取当前函数的名称,该名称可以用来代替大多数的选择器.时间.
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"
这篇关于Swift语言中的_cmd的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!