ios – _cmd在Swift语言

参见英文答案 > 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?

我想获取当前的方法名称,使用类似于这一个格式的消息

[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"

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...