Emcee

Форк
0
/
TypedResourceLocation.swift 
36 строк · 1.1 Кб
1
import ResourceLocation
2

3
public protocol ResourceLocationType {
4
    static var name: String { get }
5
}
6

7
/// This is just a wrapper around ResourceLocation, but it provides a type safety for it
8
public struct TypedResourceLocation<T: ResourceLocationType>: Codable, Hashable, CustomStringConvertible, RepresentableByResourceLocation {
9
    public let resourceLocation: ResourceLocation
10
    
11
    public init(_ resourceLocation: ResourceLocation) {
12
        self.resourceLocation = resourceLocation
13
    }
14

15
    public init?(_ resourceLocation: ResourceLocation?) {
16
        guard let resourceLocation = resourceLocation else {
17
            return nil
18
        }
19

20
        self.resourceLocation = resourceLocation
21
    }
22
    
23
    public init(from decoder: Decoder) throws {
24
        let container = try decoder.singleValueContainer()
25
        resourceLocation = try container.decode(ResourceLocation.self)
26
    }
27
    
28
    public func encode(to encoder: Encoder) throws {
29
        var container = encoder.singleValueContainer()
30
        try container.encode(resourceLocation)
31
    }
32
    
33
    public var description: String {
34
        return "<\(T.name): \(resourceLocation)>"
35
    }
36
}
37

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.