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 :: vibrations in ios swift 
Swift :: swift closure 
Swift :: string to decimal swift 
Swift :: swift await async 
Swift :: swift Equatable 
Swift :: .next() enum swift 
Ruby :: How to find database name in rails console 
Ruby :: how to check if data is an array or not ruby 
Ruby :: hashwithindifferentaccess ruby 
Ruby :: brew update ruby 
Ruby :: ruby current date and time 
Ruby :: How can I rename a database column in a Ruby on Rails migration? 
Ruby :: rails link_to class 
Ruby :: ruby intersection of two arrays 
Ruby :: max keys from hash ruby 
Ruby :: rails g model 
Ruby :: edit file terminal mac 
Ruby :: auto load path rails 
Ruby :: ruby pop array 
Ruby :: rails check routes in console 
Ruby :: rails clear log files 
Ruby :: Seconds to HH:MM in Ruby 
Ruby :: rails server stop pid 
Ruby :: ruby case statement multiple conditions 
Ruby :: rails optional reference 
Ruby :: ruby is method defined 
Ruby :: rails 
Ruby :: unlocking all the artifacts 
Ruby :: devise signout via get with https 
Ruby :: diff between .. and ... in ruby 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =