gpt4 book ai didi

objective-c - 如何在 Objective-C 中创建静态方法?

转载 作者:IT老高 更新时间:2023-10-28 11:48:42 25 4
gpt4 key购买 nike

在 Java 中,我可能有一个类,例如 Utility,我有一个名为 changeToCapitalLetter 的静态方法,所以我可以这样做:

Utility.changeToCapitalLetter(myString);

如何在 Objective C 中做类似的事情?

非常感谢

最佳答案

在 Objective-C 中,你称之为“类方法”,参见 here :

@interface MyClass : NSObject

+ (void)aClassMethod;
- (void)anInstanceMethod;

@end

+很重要;你这样调用方法:[MyClass aClassMethod];

关于objective-c - 如何在 Objective-C 中创建静态方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2691383/

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