Xcode and #pragma mark

本文介绍如何利用#pragma mark指令来整理Xcode中的源代码,通过添加标记帮助开发者更好地组织和导航大型实现文件。文章展示了如何创建分隔符及不同代码段的标签,并提醒了一些设置上的注意事项。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

转载自:http://macdevelopertips.com/xcode/xcode-and-pragma-mark.html

I’ve started using#pragma markdirectives in my code to help with organization as my implementation files grow. #pragma mark is simple to use, for example, insert the following to call out initialization code:

#pragma mark -
#pragma mark Initialization

Once this is in place, the Functions Menu (in the navigation bar) which shows a list of locations within a source file (e.g. definitions of classes, functions and methods) will display a new marker with the label "Initialization." The code in line 1 will add a line separator inside the Functions Menu, in this example, with the line appearing above the "Initialization" marker.

The figure that follows shows an example of how you might use #pragma mark to divide up various sections of your code.

Two notes:

  1. You cannot have a space after the "-" in the#pragma mark -
  2. If your code does not appear as expected (e.g. the separator does not appear), check that ‘Sort list alphabetically’ isnotchecked in the Code Sense preference settings.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值