Skip to content

Instantly share code, notes, and snippets.

@SlappyAUS
Created January 14, 2021 07:43
Show Gist options
  • Save SlappyAUS/75e57ed04295a8b0d5027b206af7f0d6 to your computer and use it in GitHub Desktop.
Save SlappyAUS/75e57ed04295a8b0d5027b206af7f0d6 to your computer and use it in GitHub Desktop.
Working With Bundles #swift #bundles
// MARK: - Emoji Packs
extension Emoji {
private func getEmojiFileName(for pack: String) -> String {
let strArr = codePoints
.compactMap({ String(format:"%04X", UInt32($0)) })
.joined(separator: "-")
.lowercased()
return strArr + ".svg"
}
private func getFileExt(for pack: String) -> String {
return "png"
}
private func getBundle(for pack: String) -> Bundle? {
if let bundlePath = Bundle.main.path(forResource: pack, ofType: "bundle") {
let bundle = Bundle(path: bundlePath)
return bundle
} else {
AppLogging.instance.info("\(#function): Bundle path not found for pack: \(pack)")
return nil
}
}
func getImage(for pack: String) -> Image? {
if let packBundle = getBundle(for: pack) {
let fileName = getEmojiFileName(for: pack)
let ext = getFileExt(for: pack)
if let path = packBundle.path(forResource: fileName, ofType: ext) {
let emojiImage = UIImage.init(contentsOfFile: path)!
return Image(uiImage: emojiImage)
}
else {
AppLogging.instance.info("\(#function): Could not find url: \(fileName) - \(ext)")
}
} else {
AppLogging.instance.info("\(#function): Pack bundle not found: \(pack)")
}
return nil
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment