Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature [RM66] Cell Short Description #68

Merged
merged 1 commit into from
Aug 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic should not. be in view layer. This should reside in ViewModel

if let c = character as? ShortCharacterDescription {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try not to use one letter variables, Usually there will be setting in swift lint that will prevent you from that. you can use char or. event `character.

return c.shortDescription
}

return character.description
}
}

struct CharacterCellImage: View {
Expand Down