majdjamaleddine@gmail.com
4 years ago
Hello Brian,
First I would like to thank you for these well drafted codes.
Secondly, I would like to ask you whether the below would match the concept of MVVM.
Under CardViewModel, I included:
static func userToCardViewModel(user: User) -> CardViewModel {
let attributtesName: [NSAttributedString.Key: Any] = [
.font: UIFont.systemFont(ofSize: 34, weight: .heavy)
]
let attributesAge: [NSAttributedString.Key: Any] = [
.font: UIFont.systemFont(ofSize: 24, weight: .regular)
]
let attributesProfession: [NSAttributedString.Key: Any] = [
.font: UIFont.systemFont(ofSize: 20, weight: .regular)
]
let attributedText = NSMutableAttributedString(string: "")
attributedText .append(NSAttributedString(string: user.name, attributes: attributtesName))
attributedText.append(NSAttributedString(string: " \(user.age)", attributes: attributesAge))
attributedText.append(NSAttributedString(string: "\n \(user.profession)", attributes: attributesProfession))
return CardViewModel(imageName: user.imageName, attributedString: attributedText, textAlignment: .left)
}
Under Home controller, I included:
fileprivate func setupDummyCards() {
users.forEach { (user) in
let cardViewModel = CardViewModel.userToCardViewModel(user: user)
let cardView = CardView(frame: .zero)
cardView.cardViewModel = cardViewModel
cardsDeckView.addSubview(cardView)
cardView.fillSuperview()
}
}
Thanks