Srdan Rasic wrote a good post on creating wrappers around value objects (like Strings, say) and custom-glue them to an application’s interface. It’s a technique I have used in my book on Mac architecture at one point but which seems to be tremendously useful for virtually anything view-related once you get to a high enough level of abstraction.
It’s weird that articles related to programming are so hard to quote. Instead of a quotation, let the resulting code illustrates what he has to say:
class ArticleViewController {
var bodyTextView: UITextView
var titleLabel: UILabel
var dateLabel: UILabel
var thumbnailImageView: UIImageView
var viewModel: ArticleViewViewModel {
didSet {
viewModel.title.bindAndFire {
[unowned self] in
self.titleLabel.text = $0
}
viewModel.body.bindAndFire {
[unowned self] in
self.bodyTextView.text = $0
}
viewModel.date.bindAndFire {
[unowned self] in
self.dateLabel.text = $0
}
viewModel.thumbnail.bindAndFire {
[unowned self] in
self.thumbnailImageView.image = $0
}
}
}
}
So now when viewModel’s properties change, the view controller will update the corresponding interface component. Sweet.
Exploring Mac App Development Strategies –
Patterns & Best Practices for Clean Software Architecture on the Mac. Don’t worry about big software design decisions anymore. Take on Mac app development with solid principles, guided by extensive examples and explanation. Buy the book now!
Like I promised last weekend, I am going to write about the process of cleaning up the already rotten source code of Calendar Paste. In order to break massive view controllers into manageable pieces and un-tangle everything, I have to make sure that I don’t break the current implementation. Calendar Paste didn’t have any automated tests in place. To change this fact is my first priority.
I have just pushed the current code of Calendar Paste 2 for iPhone to GitHub. I did this in part because I don’t fear anybody stealing it anyway, and also because I want to work on two machines this weekend without setting up my own server.
I have used DEVONthink myself a few years ago, but I think Marko’s expertise has far outpassed everything I ever knew about the app. I hope he’ll show us the various preview and link building scripts he created, too, because they make his workflow truly unique.
This weekend, I have just released my book on Mac software architecture. It’s called “Exploring Mac App Development Strategies”. In this book, I discuss how one can adopt practices for designing clean code and use it in spite of Apple’s rather invasive framework suggestions.
I’m adding a file monitoring feature to the Word Counter. This is a huge change to the application’s source code. To tackle this problem with style, I mulled things over for a while and considered my existing application’s design. I wanted to try out a few new things, so it was a no-brainer to start a sample project from scratch and fiddle with it.