#Swift中的pragma标记? [英] #pragma mark in Swift?
问题描述
在目标C中,我可以使用 #pragma mark
在符号导航器中标记代码的各个部分。由于这是C预处理程序命令,因此在Swift中不可用。在Swift中是否有替代方法?还是我必须使用丑陋的注释?
In Objective C, I can use #pragma mark
to mark sections of my code in the symbol navigator. Since this is a C preprocessor command, it's not available in Swift. Is there a stand-in for this in Swift, or do I have to use ugly comments?
推荐答案
您可以使用 // MARK:
也有人在讨论自由使用无论如何,扩展类可能是更好的做法。由于扩展程序可以实现协议,因此您可以将所有表视图委托方法放在扩展中,并在 #pragma mark
不能提供的语义级别上对代码进行分组。
There has also been discussion that liberal use of class extensions might be a better practice anyway. Since extensions can implement protocols, you can e.g. put all of your table view delegate methods in an extension and group your code at a more semantic level than #pragma mark
is capable of.
这篇关于#Swift中的pragma标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!