---
title: "Swift and enums #2"
slug: swift-and-enums-2
section: tech
date: 2015-08-06T07:53:00.000Z
canonical: https://roland.leth.ro/blog/tech/swift-and-enums-2
---

Continuing where we left off [last time](/tech/blog/swift-and-enums-1), is another little trick I like to use with `enums`:

```swift
func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, referenceSizeForFooterInSection section: NSInteger) -> CGSize {
  if .products == Section(rawValue: section), conditionOne, !conditionTwo {
    return CGSize(width: 10, height: 20)
  }
  else if .shippingDetails == Section(rawValue: section), anotherCondition {
    return CGSize(width: 10, height: 40)
  }

  return .zero
}
```

I think this makes the code easier to read at a glance: I can quickly scan the left side of the `if`s until I find what I'm looking for, and after that I can check for other conditions, if any. Sure, this could have been written like:

```swift
  switch Section(rawValue: section)! {
  case .products where conditionOne, conditionTwo:
    return CGSize(width: 10, height: 20)
  case .shippingDetails where anotherCondition:
    return CGSize(width: 10, height: 40)
  default: .zero
  }
```

But in case you don't want to write a `switch`, for whatever reason, making the `if` blocks look more like one might be a big plus to readability.