Slather logo

Coverage for "ItemKind.swift" : 85.71%

(24 of 28 relevant lines covered)

ChatLayout/Classes/Core/Model/ItemKind.swift

1
//
2
// ChatLayout
3
// ItemKind.swift
4
// https://github.com/ekazaev/ChatLayout
5
//
6
// Created by Eugene Kazaev in 2020-2021.
7
// Distributed under the MIT license.
8
//
9
10
import Foundation
11
import UIKit
12
13
/// Type of the item supported by `ChatLayout`
14
public enum ItemKind: CaseIterable, Hashable {
15
16
    /// Header item
17
    case header
18
19
    /// Cell item
20
    case cell
21
22
    /// Footer item
23
    case footer
24
25
    init(_ elementKind: String) {
4x
26
        switch elementKind {
4x
27
        case UICollectionView.elementKindSectionHeader:
2x
28
            self = .header
2x
29
        case UICollectionView.elementKindSectionFooter:
2x
30
            self = .footer
2x
31
        default:
!
32
            preconditionFailure("Unsupported supplementary view kind")
!
33
        }
4x
34
    }
4x
35
36
    /// Returns: `true` if this `ItemKind` is equal to `ItemKind.header` or `ItemKind.footer`
37
    public var isSupplementaryItem: Bool {
3x
38
        switch self {
3x
39
        case .cell:
1x
40
            return false
1x
41
        case .header, .footer:
2x
42
            return true
2x
43
        }
3x
44
    }
3x
45
46
    var supplementaryElementStringType: String {
2x
47
        switch self {
2x
48
        case .cell:
!
49
            preconditionFailure("Cell type is not a supplementary view")
!
50
        case .header:
1x
51
            return UICollectionView.elementKindSectionHeader
1x
52
        case .footer:
1x
53
            return UICollectionView.elementKindSectionFooter
1x
54
        }
2x
55
    }
2x
56
57
}