Skip to content

Instantly share code, notes, and snippets.

@mbrandonw
Last active May 26, 2025 14:52
Show Gist options
  • Save mbrandonw/f30068eee979348ba32d313cdbaa17f0 to your computer and use it in GitHub Desktop.
Save mbrandonw/f30068eee979348ba32d313cdbaa17f0 to your computer and use it in GitHub Desktop.
enum EnumStyle {
case a
case b
var x: Int {
switch self {
case .a: 1
case .b: 2
}
}
var y: Int {
switch self {
case .a: 3
case .b: 4
}
}
}
// versus
struct StructStyle {
var x: Int
var y: Int
static let a = Foo(x: 1, y: 3)
static let b = Foo(x: 2, y: 4)
}
enum EnumStyle {
case a
case b
var x: Int {
switch self {
case .a: 1
case .b: 2
}
}
var y: Int {
switch self {
case .a: 3
case .b: 4
}
}
+ var z: Int {
+ switch self {
+ case .a: 5
+ case .b: 6
+ }
+ }
}
// versus
struct StructStyle {
var x: Int
var y: Int
+ var z: Int
- static let a = Foo(x: 1, y: 3)
- static let b = Foo(x: 2, y: 4)
+ static let a = Foo(x: 1, y: 3, z: 5)
+ static let b = Foo(x: 2, y: 4, z: 6)
}
enum EnumStyle {
case a
case b
+ case c
var x: Int {
switch self {
case .a: 1
case .b: 2
+ case .c: 3
}
}
var y: Int {
switch self {
case .a: 3
case .b: 4
+ case .c: 5
}
}
}
// versus
struct StructStyle {
var x: Int
var y: Int
static let a = Foo(x: 1, y: 3)
static let b = Foo(x: 2, y: 4)
+ static let c = Foo(x: 3, y: 5)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment