Created
April 11, 2019 06:28
-
-
Save fahied/d4a99e12914eb3edb074663828240907 to your computer and use it in GitHub Desktop.
Get URL from Xcode asset catalogs
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
import UIKit | |
//It basically just gets image from assets, saves its data to disk and return file URL. | |
class AssetExtractor { | |
static func createLocalUrl(forImageNamed name: String) -> URL? { | |
let fileManager = FileManager.default | |
let cacheDirectory = fileManager.urls(for: .cachesDirectory, in: .userDomainMask)[0] | |
let url = cacheDirectory.appendingPathComponent("\(name).png") | |
guard fileManager.fileExists(atPath: url.path) else { | |
guard | |
let image = UIImage(named: name), | |
let data = UIImagePNGRepresentation(image) | |
else { return nil } | |
fileManager.createFile(atPath: url.path, contents: data, attributes: nil) | |
return url | |
} | |
return url | |
} | |
} |
mauriciochirino
commented
Mar 29, 2021
•
it is url to cache not to .xcassets catalog
it is url to cache not to .xcassets catalog
it is url to cache not to .xcassets catalog
it is url to cache not to .xcassets catalog
it is url to cache not to .xcassets catalog
it is url to cache not to .xcassets catalog
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment