objc编码规范

常量实例以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;

转载于:https://my.oschina.net/dake/blog/196758

1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值