如何在Objective-C中创建静态方法? [英] How can I make a static method in Objective-C?

查看:119
本文介绍了如何在Objective-C中创建静态方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In Java, I may have a class, for example, Utility and I have a static method called changeToCapitalLetter, so I can do something like this:

Utility.changeToCapitalLetter(myString);

如何在Objective C中执行类似的操作?

How can I do the similar thing in Objective C?

非常感谢

推荐答案

在Objective-C中,你打电话这个类方法,请参见此处

In Objective-C, you call this "class methods", see here:

@interface MyClass : NSObject

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

@end

+ 是重要的事情;你调用这样的方法: [MyClass aClassMethod];

The + is the important thing; you call the method like this: [MyClass aClassMethod];

这篇关于如何在Objective-C中创建静态方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆