gpt4 book ai didi

Swift:如何指定用于静态方法调用的候选类

转载 作者:行者123 更新时间:2023-11-28 14:03:06 24 4
gpt4 key购买 nike

假设我们有两个像这样的 Obj-C 类:

Parent {
+ (void)doSomething {
NSLog(@"%@", [self messageToDisplay]);
}

+ (NSString *)messageToDisplay {
return @"message_parent";
}
}

Child: Parent {
+ (NSString *)messageToDisplay {
return @"message_child";
}
}

还有这个Swift代码:

Child.doSomething()

它会产生这个错误,因为 Swift 不知道要使用哪个候选项,Child 还是 Parent。

Ambiguous use of 'doSomething()' Found this candidate (Child) Found this candidate (Parent)

我们如何指定要使用的候选项?

非常感谢。

最佳答案

好的,知道了。我找到了这个问题的原因。我们在父类中有一个名为 deleteObjectWithId 的 ObjC 方法,在子类中有另一个名为 deleteGroupWithId 的方法(顺便说一句,没用),当从 Swift 调用 delete(withId:) 方法时,实际上有两个候选方法。非常感谢。

关于Swift:如何指定用于静态方法调用的候选类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53336464/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com