Skip to content

Commit

Permalink
Merge pull request #68 from novoda/feature/rm-66-cell-short-description
Browse files Browse the repository at this point in the history
Feature [RM66] Cell Short Description
  • Loading branch information
swg99 authored Aug 9, 2021
2 parents 027f8ca + af55595 commit dabd26b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Rick-and-Morty/Rick And Morty/Models/Character.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ protocol Character {
var description: String { get }
}

protocol ShortCharacterDescription {
var shortDescription: String { get }
}

extension Character {
var id: UUID { UUID() }
}
2 changes: 1 addition & 1 deletion Rick-and-Morty/Rick And Morty/Models/Morty.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

struct Morty: Character {
struct Morty: Character, ShortCharacterDescription {
let name: String
let image: String
let shortDescription: String
Expand Down
11 changes: 10 additions & 1 deletion Rick-and-Morty/Rick And Morty/Views/CharacterCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,26 @@ struct CharacterCell: View {

VStack(alignment: .leading, spacing: 8) {
Text(character.name)
Text(character.description)
Text(description(for: character))
}

if imagePosition == .right {
CharacterCellImage(character: character)
}
Spacer()
}
.padding()
}
.buttonStyle(PlainButtonStyle())
}

func description(for character: Character) -> String {
if let c = character as? ShortCharacterDescription {
return c.shortDescription
}

return character.description
}
}

struct CharacterCellImage: View {
Expand Down

0 comments on commit dabd26b

Please sign in to comment.