Add a color, file, or image literal to a playground

You can create literals in your playground code when the value of a color, file, or image does not need to change. You can use the same literal in multiple places in your playground. The types of literals are:

Literal

Description

Color

A UIColor or NSColor color value.

File

An NSURL reference to a file.

Image

A UIImage or NSImage reference to an image file.

Add a color literal

  1. Place the insertion point in the code where you want to add the color literal.

  2. Choose Editor > Insert Color Literal.

  3. Double-click the color well that appears, then choose a color from the color picker.

Add a file literal

  1. Place the insertion point in the code where you want to add the file literal.

  2. Choose Editor > Insert File Literal.

  3. In the sheet that appears, select a file, then click Open.

Adding a file literal to a playground page adds it to the page’s Resources folder; otherwise, it is added to the playground Resources folder.

Add an image literal

  1. Place the insertion point in the code where you want to add the image literal.

  2. Choose Editor > Insert Image Literal.

  3. In the sheet that appears, select a file, then click Open.

Adding an image literal to a playground page adds it to the page’s Resources folder; otherwise, it is added to the playground Resources folder.

Alternatively, you can drag an image file to the source editor.

Copying and moving literals