Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SWIFT

Swift enum with Associated Values

enum Distance {
  
  // associate value
  case km(String)
  case miles(String)
}

// pass string value to km
var dist1 = Distance.km("Metric System")
print(dist1)

// pass string value to miles
var dist2 = Distance.miles("Imperial System")
print(dist2)
 
PREVIOUS NEXT
Tagged: #Swift #enum #Associated #Values
ADD COMMENT
Topic
Name
1+2 =