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
// Become a sponsor:
10
// https://github.com/sponsors/ekazaev
11
//
12
13
import Foundation
14
import UIKit
15
16
/// Type of the item supported by `CollectionViewChatLayout`
17
public enum ItemKind: CaseIterable, Hashable {
18
19
    /// Header item
20
    case header
21
22
    /// Cell item
23
    case cell
24
25
    /// Footer item
26
    case footer
27
28
    init(_ elementKind: String) {
!
29
        switch elementKind {
!
30
        case UICollectionView.elementKindSectionHeader:
!
31
            self = .header
!
32
        case UICollectionView.elementKindSectionFooter:
!
33
            self = .footer
!
34
        default:
!
35
            preconditionFailure("Unsupported supplementary view kind.")
!
36
        }
!
37
    }
!
38
39
    /// Returns: `true` if this `ItemKind` is equal to `ItemKind.header` or `ItemKind.footer`
40
    public var isSupplementaryItem: Bool {
!
41
        switch self {
!
42
        case .cell:
!
43
            return false
!
44
        case .header, .footer:
!
45
            return true
!
46
        }
!
47
    }
!
48
49
    var supplementaryElementStringType: String {
!
50
        switch self {
!
51
        case .cell:
!
52
            preconditionFailure("Cell type is not a supplementary view.")
!
53
        case .header:
!
54
            return UICollectionView.elementKindSectionHeader
!
55
        case .footer:
!
56
            return UICollectionView.elementKindSectionFooter
!
57
        }
!
58
    }
!
59
60
}