{"id":14057,"date":"2016-04-03T17:04:51","date_gmt":"2016-04-03T21:04:51","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=14057"},"modified":"2016-04-03T17:04:51","modified_gmt":"2016-04-03T21:04:51","slug":"protocol-oriented-mvvm","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2016\/04\/03\/protocol-oriented-mvvm\/","title":{"rendered":"Protocol-Oriented MVVM"},"content":{"rendered":"<p><a href=\"https:\/\/realm.io\/news\/doios-natasha-murashev-protocol-oriented-mvvm\/\">Natasha Murashev<\/a>:<\/p>\n<blockquote cite=\"https:\/\/realm.io\/news\/doios-natasha-murashev-protocol-oriented-mvvm\/\">\n<p>Instead of having that huge configure method, you can take out every part of it and put it into a <code>SwitchWithTextCellProtocol<\/code> for that cell. That got me really excited. This way, I can have my view model conform to this protocol, and set all these properties right there. Now, I don&rsquo;t have to have this huge configure method, but I still have a way to ensure that every single property is actually set.<\/p>\n<p>[&#8230;]<\/p>\n<p>With protocol extensions in Swift 2.0, you can do the same thing with default values. If there is a certain color that&rsquo;s relevant for most cells, you can just extend it and set that color. Any view model that implements this doesn&rsquo;t have to set the color anymore.<\/p>\n<p>[&#8230;]<\/p>\n<p>Instead of tying my protocols to the actual cell, I can tie it to a more generic <code>TextPresentable<\/code>. This way, any view that has a label, not just cells, can conform to the text presentable protocol.<\/p>\n<\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Natasha Murashev: Instead of having that huge configure method, you can take out every part of it and put it into a SwitchWithTextCellProtocol for that cell. That got me really excited. This way, I can have my view model conform to this protocol, and set all these properties right there. Now, I don&rsquo;t have to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"","apple_news_api_id":"","apple_news_api_modified_at":"","apple_news_api_revision":"","apple_news_api_share_url":"","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[31,30,373,71,901],"class_list":["post-14057","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-ios","tag-mac","tag-mvvm","tag-programming","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/14057","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=14057"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/14057\/revisions"}],"predecessor-version":[{"id":14058,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/14057\/revisions\/14058"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=14057"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=14057"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=14057"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}