Skip to content

Instantly share code, notes, and snippets.

@tarunon
Created October 4, 2018 06:48
Show Gist options
  • Save tarunon/d1c6a06b3d1f4c53c1e3e5f5eaa508b1 to your computer and use it in GitHub Desktop.
Save tarunon/d1c6a06b3d1f4c53c1e3e5f5eaa508b1 to your computer and use it in GitHub Desktop.
How to solve Bundle things in microframeworks
public struct BundleReference<T: NSObjectProtocol> {
static var _bundle: Bundle {
return Bundle(for: T.self)
}
}
public protocol BundleReferencable {
associatedtype Referenced: NSObjectProtocol
static var bundle: BundleReference<Referenced>.Type { get }
}
public extension NSObjectProtocol {
public static var bundle: BundleReference<Self>.Type { return BundleReference<Self>.self }
}
extension NSObject: BundleReferencable {}
public extension BundleReference {
public struct Image: _ExpressibleByImageLiteral {
var image: UIImage
public init(imageLiteralResourceName path: String) {
image = UIImage(named: path, in: BundleReference._bundle, compatibleWith: nil)!
}
}
public func image(_ image: Image) -> UIImage {
return image.image
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment