vds_ios/VDS/Classes/BundleManager.swift
Matt Bruce 8501819658 added icon / images / etc... first cut
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
2023-01-10 13:11:33 -06:00

62 lines
1.4 KiB
Swift

//
// BundleManager.swift
// VDS
//
// Created by Matt Bruce on 1/9/23.
//
import Foundation
import UIKit
public class BundleManager {
public static var shared = BundleManager()
public var bundles: [Bundle] = []
private var paths: [String] = []
private init(){
bundles.append(Bundle(for: Self.self))
}
private func updateBundles() {
bundles.removeAll()
bundles.append(Bundle(for: Self.self))
paths.forEach({ path in
if let bundle = Bundle(path: path) {
bundles.append(bundle)
}
})
}
public static func register(_ path: String) {
if !shared.paths.contains(where: {$0 == path}) {
if let bundle = Bundle(path: path) {
shared.paths.append(path)
shared.bundles.append(bundle)
}
}
}
}
extension BundleManager {
public func image(for name: String) -> UIImage? {
var foundImage: UIImage?
if let image = UIImage(named: name) {
foundImage = image
} else {
for bundle in bundles {
if let image = UIImage(named: name, in: bundle, with: nil) {
foundImage = image
break
}
}
}
return foundImage
}
}