在我的编程课程介绍中,大多数内容都分为带注释的部分,如下所示:
@interface ClassA : NSObject
{
@protected
NSMutableArray *_objects
}
/* constructors */
+(id) initWithObjects: (NSMutableArray *) objects;
-(id) initWithObjects: (NSMutableArray *) objects;
/* properties */
@property(nonatomic, strong) NSMutableArray *objects;
/* methods */
- (void) haveFunWithObjects;
我发现这是一种组织事物的有用方式,但有时候,我需要在一个相当深奥的代码部分的前面插入或插入文档,并附上一个简短的描述,然后我感到困惑的是我应该如何记录它:
@interface NDTuple : NSObject
{
@protected
NSMutableArray *_components;
NSUInteger _dim;
}
/* constructors */
/* This constructor initializes the components array to elements all of 0 */
+(id) initToZeroForDim: (NSUInteger) dim;
-(id) initToZeroForDim: (NSUInteger) dim;
+(id) initWithComponents: (NSMutableArray *)components;
-(id) initWithComponents: (NSMutableArray *)components;
/* properties */
@property(nonatomic, strong) NSMutableArray *components;
@property(nonatomic, assign) NSUInteger dim;
/* methods */
- (NDTuple *) minus: (NDTuple *) subTuple;
- (void) replaceComponentAtIndex: (NSUInteger) index withComponent:(id)anObject;
- (id) componentAtIndex:(NSUInteger) index;
也许这不是最好的例子,但我真正想问的是,是否有更好的方法将代码拆分为常用部分?
答案 0 :(得分:0)
您可以使用#pragma mark
分隔各个部分。当您下拉文件中的符号列表时,Xcode将显示这些值。
示例:
#pragma mark Constructors
你甚至可以:
#pragma mark -
在符号下拉列表中显示一行。