Created
October 4, 2018 06:48
-
-
Save tarunon/d1c6a06b3d1f4c53c1e3e5f5eaa508b1 to your computer and use it in GitHub Desktop.
How to solve Bundle things in microframeworks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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