当我在类声明自动完成 block 的类名占位符中输入 Color 时,弹出了一个颜色选择器。它允许我在源代码中直接放置一个彩色小方 block 。
我试图用谷歌搜索它,但找不到任何合适的结果,所以我想问一下这个功能的用途以及如何在源代码中使用这些方 block 。它们可以用作标识吗?作为类名?你能设置例如的值吗? SKColors
使用这些方 block ?怎么回事?
使用 Xcode 8.2.1
最佳答案
这是“颜色文字”功能。它类似于 Image literals, described elsewhere on Stack Overflow .
您基本上得到一个颜色选择器并选择一种颜色,该颜色将在一个小方 block 中预览。
引用自Apple :
Literals are the actual values of your data represented in their native format, directly within the Xcode editor. For instance, there’s no need to type “myImage.jpg” in the editor – just drag your image from the Finder and the actual image will appear in-line with your code. Instead of showing RGB values to indicate color, the playground will render a color swatch. Literals in playgrounds behave similarly to code you would otherwise hand-author in regular Swift code, but are rendered in a much more useful manner.
关于swift - Xcode Swift 编辑器中的这个颜色功能是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44605150/