Latest 0.0.1
Homepage https://github.com/bannzai/Enumerable
License MIT
Platforms ios 9.0
Authors

Enumrable can get all the elements of Enum.

Usage

Currently only support Int.

Define YourEnum.

enum YourEnum: Int, Enumerable {
  case one
  case two
  case three
  case four
}

Get all elemnts.

print(YourEnum.elements) // one, two, three, four
print(YourEnum.count) // 4

It is particularly compatible with TableView and CollectionView.

enum RowType: Int, Enumerable {
  case one
  case two
  case three
  case four
}

public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
  return RowType.count
}

public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
  guard let item = RowType(rawValue: indexPath.item) else {
    fatalError("out of section type: (indexPath.section), model has sections: (String(describing: model?.sections))")
  }
  switch item {
    case .one:
    case two:
  ...
  }
  ...
}

License

Enumerable is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "Enumerable",
    "version": "0.0.1",
    "summary": "Swift Enum can enumerable.",
    "description": "Enumrable can get all the elements of Enum.",
    "homepage": "https://github.com/bannzai/Enumerable",
    "license": "MIT",
    "authors": {
        "bannzai": "[email protected]"
    },
    "source": {
        "git": "https://github.com/bannzai/Enumerable.git",
        "commit": "e27286afd3c824d57d3287f1ff38242fdcf7b602"
    },
    "source_files": "Enumerable/*.swift",
    "social_media_url": "https://twitter.com/_bannzai_",
    "platforms": {
        "ios": "9.0"
    },
    "swift_version": "4.1"
}

Pin It on Pinterest

Share This