swwiftii
swwiftii

Reputation: 27

What means image literal or rather the word literal?

What means image literal or rather the word literal?

like in Xcode on the top bar there's an option called image literal

Upvotes: 1

Views: 189

Answers (1)

vacawama
vacawama

Reputation: 154603

A literal is a value that is directly represented in the code.

Examples:

let i = 3                  // 3 is an Integer Literal
let arr = ["a", "b", "c"]  // ["a", "b", "c"] is an Array Literal

Swift has other literals such as Color Literals and Image Literals. Those are special compiler directives which directly encode the color or reference to an image.

This allows the Xcode editor to do special things such as show a color literal directly in the code as a color splotch instead of just showing confusing/meaningless floating point numbers. And it allows you to select the color by double clicking on the color splotch to bring up the standard color picker.

// Paste this into Xcode.  The color will be shown directly
let color = #colorLiteral(red: 0.3411764801, green: 0.6235294342, blue: 0.1686274558, alpha: 1)

colorLiteral in Playground

Upvotes: 4

Related Questions