Question : Swift enum Associated Values
Answered by : samer-saeid
enum Laptop { // associate value case name(String) ...
}
Source : | Last Update : Thu, 23 Jun 22
Question : enum Associated Values Swift
Answered by : samer-saeid
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)
Source : | Last Update : Thu, 23 Jun 22
Question : Swift enum With Associated Values
Answered by : samer-saeid
enum Distance { // associate value case km(String) ...
}
Source : | Last Update : Thu, 23 Jun 22
Question : Swift enum with Associated Values
Answered by : samer-saeid
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)
Source : | Last Update : Thu, 23 Jun 22