Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
229 views
in Technique[技术] by (71.8m points)

swift - Swift中的#pragma mark?(#pragma mark in Swift?)

In Objective C, I can use #pragma mark to mark sections of my code in the symbol navigator.

(在Objective C中,我可以使用#pragma mark在符号导航器中标记我的代码部分。)

Since this is a C preprocessor command, it's not available in Swift.

(由于这是一个C预处理器命令,因此在Swift中不可用。)

Is there a stand-in for this in Swift, or do I have to use ugly comments?

(在Swift中是否有替代,或者我是否必须使用丑陋的评论?)

  ask by Arbitur translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use // MARK:

(你可以使用// 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 eg 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.

(由于扩展可以实现协议,因此您可以将所有表视图委托方法放在扩展中,并将代码分组到比#pragma mark能够更加语义的级别。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...