Search
 
SCRIPT & CODE EXAMPLE
 

SWIFT

Swift enum Associated Values

enum Laptop {
  
  // associate value 
  case name(String)
  ...
}
Comment

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)
Comment

Swift enum With Associated Values

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

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)
Comment

PREVIOUS NEXT
Code Example
Swift :: swift uibutton text resets to default 
Swift :: how request prefix of string in swift 
Swift :: Swift Find Number of Array Elements 
Swift :: Swift Closed Range 
Swift :: Memberwise Initializer Swift 
Swift :: Swift Check if two sets are equal 
Swift :: swift split an array into chunks 
Swift :: swift writing to ios logs 
Swift :: swift collectionview ispagingenabled change page size 
Swift :: swiftui show custom loading spinner 
Swift :: Compare AnyObjects en Swift 
Swift :: swift uicollectionview reloaddata completion 
Swift :: swift get last element of array 
Ruby :: 2 decimal places ruby 
Ruby :: find records created in a particular month rails 
Ruby :: eager load polymorphic rails 
Ruby :: simple form for rails dates 
Ruby :: PG::DatatypeMismatch: ERROR: column "price" cannot be cast automatically to type numeric HINT: You might need t 
Ruby :: add timezone in rails 
Ruby :: rails find_by order 
Ruby :: ruby substring remove 
Ruby :: how to generate a controller in rails 
Ruby :: rails render partial 
Ruby :: iterate over array ruby 
Ruby :: timeout in rails 
Ruby :: ruby rails find data field type 
Ruby :: create table index unique rails 
Ruby :: Ruby Regular Expressions 
Ruby :: rails link_to example 
Ruby :: rails assets video not found video_tag 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =