Slather logo

Coverage for "ItemKind.swift" : 0.00%

(0 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-2022.
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) {
!
26
        switch elementKind {
!
27
        case UICollectionView.elementKindSectionHeader:
!
28
            self = .header
!
29
        case UICollectionView.elementKindSectionFooter:
!
30
            self = .footer
!
31
        default:
!
32
            preconditionFailure("Unsupported supplementary view kind")
!
33
        }
!
34
    }
!
35
36
    /// Returns: `true` if this `ItemKind` is equal to `ItemKind.header` or `ItemKind.footer`
37
    public var isSupplementaryItem: Bool {
!
38
        switch self {
!
39
        case .cell:
!
40
            return false
!
41
        case .header, .footer:
!
42
            return true
!
43
        }
!
44
    }
!
45
46
    var supplementaryElementStringType: String {
!
47
        switch self {
!
48
        case .cell:
!
49
            preconditionFailure("Cell type is not a supplementary view")
!
50
        case .header:
!
51
            return UICollectionView.elementKindSectionHeader
!
52
        case .footer:
!
53
            return UICollectionView.elementKindSectionFooter
!
54
        }
!
55
    }
!
56
57
}