Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jacobsapps/bb9982f29158398455a5395b9dc18c5a to your computer and use it in GitHub Desktop.
Save jacobsapps/bb9982f29158398455a5395b9dc18c5a to your computer and use it in GitHub Desktop.
extension CardEntity {
static func from(_ card: Card) -> CardEntity {
CardEntity(
id: card.id,
title: card.stats.title,
emoji: card.stats.type.emoji,
hexColor: card.stats.type.hexClor,
rarity: String(describing: card.stats.rarity),
stats: card.stats.stats.map { StatEntity(name: $0.name, value: $0.value) },
image: card.image
)
}
func toCard() -> Card? {
guard let image = UIImage(data: imageData) else { return nil }
let cardStats = CardStats(
title: title,
type: ElementalType(emoji: emoji, hexClor: hexColor),
stats: stats.map { Stat(name: $0.name, value: $0.value) },
rarity: Rarity(rawValue: rarity) ?? .rare
)
return Card(id: id, image: image, stats: cardStats)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment