禁止在Swift playground中运行某些代码行

时间:2023-01-23 18:02:10

I am writing a Swift coding test for new iOS candidates that interview at my company, I have decided to utilise Swift playgrounds so that I can include some hands on coding questions.

我正在为我公司采访的新iOS候选人编写一个Swift编码测试,我决定利用Swift游乐场,以便我可以在编码问题上加入一些手。

Some questions will include example code, so I would not like this code to produce anything in the output window. I'd rather not just comment it out as I'd like to utilise the syntax highlighting etc...

一些问题将包括示例代码,因此我不希望此代码在输出窗口中生成任何内容。我不想只是评论它,因为我想利用语法高亮等...

Is there any kind of annotation or equivalent I can add to the code in question to prevent it showing in the output window?

是否有任何类型的注释或等效项我可以添加到相关代码中以防止它显示在输出窗口中?

Many Thanks.

非常感谢。

1 个解决方案

#1


1  

As far as I know there is no annotation to suppress the execution of code in a playground. If you want to keep the syntax highlighting but don't want the code to be executed/produce any output I suggest you just wrap it in a function. That way you have full autocomplete and syntax highlighting support but it does not produce any output in the playground.

据我所知,没有注释可以抑制游乐场中代码的执行。如果你想保持语法高亮,但不希望代码被执行/产生任何输出,我建议你把它包装在一个函数中。这样你就可以获得完全自动完成和语法高亮支持,但它不会在操场上产生任何输出。

func example() {
    print("No output")
}

禁止在Swift playground中运行某些代码行

Other than that you can just use the Example callout Markup. This allows you to format code using markup but without syntax highlighting.

除此之外,您可以使用示例标注标记。这允许您使用标记格式化代码,但不使用语法突出显示。

Hope that helps.

希望有所帮助。

#1


1  

As far as I know there is no annotation to suppress the execution of code in a playground. If you want to keep the syntax highlighting but don't want the code to be executed/produce any output I suggest you just wrap it in a function. That way you have full autocomplete and syntax highlighting support but it does not produce any output in the playground.

据我所知,没有注释可以抑制游乐场中代码的执行。如果你想保持语法高亮,但不希望代码被执行/产生任何输出,我建议你把它包装在一个函数中。这样你就可以获得完全自动完成和语法高亮支持,但它不会在操场上产生任何输出。

func example() {
    print("No output")
}

禁止在Swift playground中运行某些代码行

Other than that you can just use the Example callout Markup. This allows you to format code using markup but without syntax highlighting.

除此之外,您可以使用示例标注标记。这允许您使用标记格式化代码,但不使用语法突出显示。

Hope that helps.

希望有所帮助。