objc编码规范

objc编码规范,第1张

概述常量实例以k开头。 双下划线开头和结尾的macro是编译器保留的 naming methods: Don’t use “and” to link keywords that are attributes of the receiver. If the method describes two separate actions, use “and” to link them. Use “get” o 常量实例以k开头。 双下划线开头和结尾的macro是编译器保留的
naming methods: Don’t use “and” to link keywords that are attributes of the receiver. If the method describes two separate actions,use “and” to link them.
Use “get” only for methods that return objects and values indirectly. You should use this form for methods only when multiple items need to be returned. delegate methods: Start the name by IDentifying the class of the object that’s sending the message // 下面就是tableVIEw类在delegate object中的回调函数,sending是tableVIEw类 - (BOol)tableVIEw:(NStableVIEw *)tableVIEw shouldSelectRow:(int)row; Use “dID” or “will” for methods that are invoked to notify the delegate that something has happened or is about to happen.
Although you can use “dID” or “will” for methods that are invoked to ask the delegate to do something on behalf of another object,“should” is preferred.

Collection Methods

For objects that manage a collection of objects (each called an element of that collection),the convention is to have methods of the form:

- (voID)addElement:(elementType)anObj;

- (voID)removeElement:(elementType)anObj; - (NSArray *)elements;

The following are some qualifications and refinements to this guIDeline:

If the collection is truly unordered,return an NSSet object rather than an NSArray object.
If it’s important to insert elements into a specific location in the collection,use methods similar to the following instead of or in addition to the ones above:

- (voID)insertLayoutManager:(NSLayoutManager *)obj atIndex:(int)index; 
- (voID)removeLayoutManagerAtIndex:(int)index;

There are a couple of implementation details to keep in mind with collection methods:

These methods typically imply ownership of the inserted objects,so the code that adds or inserts them must retain them,and the code that removes them must also release them.
If the inserted objects need to have a pointer back to the main object,you do this (typically) with a set... method that sets the back pointer but does not retain.

names of most private methods in the Cocoa frameworks have an underscore prefix (for example, _fooData ) to mark them as private. From this fact follow two recommendations.

Don’t use the underscore character as a prefix for your private methods. Apple reserves this convention.
If you are subclassing a large Cocoa framework class (such as NSVIEw or UIVIEw) and you want to be absolutely sure that your private methods have names different from those in the superclass,you can add your own prefix to your private methods. The prefix should be as unique as possible,perhaps one based on your company or project and of the form "XX_". So if your project is called Byte Flogger,the prefix might be BF_addobject:

Function name:

Functions have some general naming rules that you should follow:

Function names are formed like method names,but with a couple exceptions:  They start with the same prefix that you use for classes and constants. The first letter of the word after the prefix is cAPItalized. Most function names start with verbs that describe the effect the function has:
 NSHighlightRect 
      NSDeallocateObject
Property name: If the name of a declared property is expressed as an adjective,however,the property name omits the “is” prefix but specifIEs the conventional name for the get accessor,for example:
     @property (assign,getter=isEditable) BOol editable;
Enumerated constants
typedef enum _NSMatrixMode 
{ NSRadioModeMatrix NSHighlightmodeMatrix NSListModeMatrix NSTrackModeMatrix 
} NSMatrixMode; 总结

以上是内存溢出为你收集整理的objc编码规范全部内容,希望文章能够帮你解决objc编码规范所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1053046.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存