obsidian/笔记文件/2.笔记/objectc代码前面的+和-是什么意思.md
2025-03-26 00:02:56 +08:00

9 lines
737 B
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ios
在Objective-C中代码前面的加号(+)和减号(-)‌分别表示类方法和实例方法。
‌加号(+)表示类方法可以通过类名直接调用无需实例化对象。类方法通常用于执行与类本身相关的操作如创建类的新实例。类方法相当于Java中的静态方法但并非严格意义上的static方法
‌减号(-)‌:表示实例方法,需要通过实例化的对象来调用。实例方法是与类的实例(对象)相关的方法,用于执行对象的特定操作‌。
综上所述,加号(+)和减号(-)在Objective-C中用于区分类方法和实例方法分别表示可通过类名直接调用和需要通过实例化对象调用的方法。