cleaning things up and getting it working with the header background

This commit is contained in:
talksik
2021-12-14 17:23:08 -08:00
parent 08458a764b
commit 532f8cd50a
2 changed files with 15 additions and 7 deletions
+9 -2
View File
@@ -77,14 +77,21 @@ struct RemoteImage_Previews: PreviewProvider {
}
class NirvanaImage {
static func getAverageColor(url:URL) -> UIColor? {
if let data = try? Data(contentsOf: url) {
static func getAverageColor(url:String) -> UIColor? {
guard let parsedURL = URL(string: url) else {
fatalError("Invalid URL: \(url)")
}
if let data = try? Data(contentsOf: parsedURL) {
if let image = UIImage(data: data) {
print("got the average color of image \(image.averageColor)")
return image.averageColor
} else {
print("failed to get image average color")
return nil
}
}
print("failed to get image average color")
return nil
}
}