Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SWIFT

enum Associated Values Swift

enum Laptop {

  // associate string value
  case name(String)

  // associate integer value  
  case price (Int)
}

// pass string value to name
var brand = Laptop.name("Razer")
print(brand)

// pass integer value to price
var offer = Laptop.price(1599)
print(offer)
 
PREVIOUS NEXT
Tagged: #enum #Associated #Values #Swift
ADD COMMENT
Topic
Name
3+4 =