Images.swift 2.92 KB
Newer Older
1
// Generated using SwiftGen, by O.Halligon — https://github.com/SwiftGen/SwiftGen
2

3
#if os(OSX)
4
  import AppKit.NSImage
5
6
7
8
9
10
  typealias AssetColorTypeAlias = NSColor
  typealias Image = NSImage
#elseif os(iOS) || os(tvOS) || os(watchOS)
  import UIKit.UIImage
  typealias AssetColorTypeAlias = UIColor
  typealias Image = UIImage
11
12
#endif

Kateryna Kostiuk's avatar
Kateryna Kostiuk committed
13
// swiftlint:disable superfluous_disable_command
14
// swiftlint:disable file_length
15
16
17
18
19
20

@available(*, deprecated, renamed: "ImageAsset")
typealias AssetType = ImageAsset

struct ImageAsset {
  fileprivate var name: String
21
22

  var image: Image {
23
24
25
26
27
28
29
30
31
32
    let bundle = Bundle(for: BundleToken.self)
    #if os(iOS) || os(tvOS)
    let image = Image(named: name, in: bundle, compatibleWith: nil)
    #elseif os(OSX)
    let image = bundle.image(forResource: name)
    #elseif os(watchOS)
    let image = Image(named: name)
    #endif
    guard let result = image else { fatalError("Unable to load image named \(name).") }
    return result
33
34
35
  }
}

36
37
38
39
40
41
42
struct ColorAsset {
  fileprivate var name: String

  #if swift(>=3.2)
  @available(iOS 11.0, tvOS 11.0, watchOS 4.0, OSX 10.13, *)
  var color: AssetColorTypeAlias {
    return AssetColorTypeAlias(asset: self)
43
  }
44
  #endif
45
}
46
47
48

// swiftlint:disable identifier_name line_length nesting type_body_length type_name
enum Asset {
49
  static let addPerson = ImageAsset(name: "add_person")
50
  static let backgroundRing = ImageAsset(name: "background_ring")
Kateryna Kostiuk's avatar
Kateryna Kostiuk committed
51
  static let device = ImageAsset(name: "device")
52
53
54
55
56
57
58
  static let icContactPicture = ImageAsset(name: "ic_contact_picture")
  static let logoRingBeta2Blanc = ImageAsset(name: "logo-ring-beta2-blanc")

  // swiftlint:disable trailing_comma
  static let allColors: [ColorAsset] = [
  ]
  static let allImages: [ImageAsset] = [
59
    addPerson,
60
    backgroundRing,
Kateryna Kostiuk's avatar
Kateryna Kostiuk committed
61
    device,
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
    icContactPicture,
    logoRingBeta2Blanc,
  ]
  // swiftlint:enable trailing_comma
  @available(*, deprecated, renamed: "allImages")
  static let allValues: [AssetType] = allImages
}
// swiftlint:enable identifier_name line_length nesting type_body_length type_name

extension Image {
  @available(iOS 1.0, tvOS 1.0, watchOS 1.0, *)
  @available(OSX, deprecated,
    message: "This initializer is unsafe on macOS, please use the ImageAsset.image property")
  convenience init!(asset: ImageAsset) {
    #if os(iOS) || os(tvOS)
    let bundle = Bundle(for: BundleToken.self)
    self.init(named: asset.name, in: bundle, compatibleWith: nil)
    #elseif os(OSX) || os(watchOS)
    self.init(named: asset.name)
    #endif
  }
}

extension AssetColorTypeAlias {
  #if swift(>=3.2)
  @available(iOS 11.0, tvOS 11.0, watchOS 4.0, OSX 10.13, *)
  convenience init!(asset: ColorAsset) {
    let bundle = Bundle(for: BundleToken.self)
    #if os(iOS) || os(tvOS)
    self.init(named: asset.name, in: bundle, compatibleWith: nil)
    #elseif os(OSX)
    self.init(named: asset.name, bundle: bundle)
    #elseif os(watchOS)
    self.init(named: asset.name)
    #endif
  }
  #endif
}

private final class BundleToken {}