Created
November 7, 2024 14:11
-
-
Save lucianoschillagi/b569780b5559162d03833d512a9da5fc to your computer and use it in GitHub Desktop.
Enumerations with Associated Values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
// Enumerations with Associated Values | |
enum OrderStatus { | |
case pending(orderID: Int, isAnOffer: Bool) | |
case shipped(orderID: Int, trackingNumber: String, isAnOffer: Bool) | |
case delivered(orderID: Int, date: String, signature: String?, isAnOffer: Bool) | |
} | |
// Usage examples | |
let order1 = OrderStatus.pending(orderID: 101, isAnOffer: false) | |
let order2 = OrderStatus.shipped(orderID: 102, trackingNumber: "1Z999AA10123456784", isAnOffer: true) | |
let order3 = OrderStatus.delivered(orderID: 103, date: "2024-11-03", signature: nil, isAnOffer: true) | |
dump(order1) | |
dump(order2) | |
dump(order3) | |
// https://dc4p.store/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment