参见英文答案 >
What is the swift equivalent to _cmd?2
> Is there a Swift alternative for NSLog(@“%s”,__PRETTY_FUNCTION__)11
我以前的问题被标记为重复.我试图编辑我的问题,但我不能删除重复的标签,所以我必须创建一个新的标签
What is the swift equivalent to _cmd?
> Is there a Swift alternative for NSLog(@“%s”,__PRETTY_FUNCTION__)11
我以前的问题被标记为重复.我试图编辑我的问题,但我不能删除重复的标签,所以我必须创建一个新的标签
What is the swift equivalent to _cmd?
我想获取当前的方法名称,使用类似于这一个格式的消息
[NSExeception raise:NSInternalInconsistencyException format:@"You must override %@ in a subclass",NSStringFromSelector(_cmd)]
此外,我想使用_cmd作为键来设置关联对象.有人知道在Swift中相当于_cmd我真的很感激.
解决方法
没有_cmd,但是可以使用__FUNCTION__来获取当前函数的名称,大部分时间可以用于代替选择器.
func myUnimplementedMethod() { println("You must override \(__FUNCTION__) in a subclass") } myUnimplementedMethod() // prints "You must override myUnimplementedMethod() in a subclass"