ExprissibleByLiteral Protocol in swift : Part 1

The swift standard library types such as Int, Double, Arrays, Dictionary etc are conform to the ExprissibleByLiteral protocol.

You can initialize the variable or constant of any of these types by assigning literal.

  • Int
// Type inferred as 'Int'
let count = 50
  • Double
// Double Literal
let price = 20.4
// A floating-point value initialized using an integer literal
let
heightDouble: Double = 1
  • Array
// An array of 'Int'
let numbers = [20, 23, 24, 34, 56]

The List of protocols are available in swift

  • ExpressibleByArrayLiteral
  • ExpressibleByDictionaryLiteral
  • ExpressibleByIntegerLiteral
  • ExpressibleByFloatLiteral
  • ExpressibleByBooleanLiteral
  • ExpressibleByNilLiteral
  • ExpressibleByStringLiteral
  • ExpressibleByExtendedGraphemeClusterLiteral
  • ExpressibleByUnicodeScalarLiteral

We will be continue the tutorial on the next series. Go To Part 2