<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by HammyAssassin on Medium]]></title>
        <description><![CDATA[Stories by HammyAssassin on Medium]]></description>
        <link>https://medium.com/@hammyassassin?source=rss-2118c84365e8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*_dpx8UvMJO2-qoH66rDt_g.png</url>
            <title>Stories by HammyAssassin on Medium</title>
            <link>https://medium.com/@hammyassassin?source=rss-2118c84365e8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 11:48:53 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hammyassassin/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[WFH, RTO and Engineering ICs]]></title>
            <link>https://hammyassassin.medium.com/wfh-rto-and-engineering-ics-71ccaaf17a3f?source=rss-2118c84365e8------2</link>
            <guid isPermaLink="false">https://medium.com/p/71ccaaf17a3f</guid>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[engineering-mangement]]></category>
            <category><![CDATA[leadership]]></category>
            <category><![CDATA[work-from-home]]></category>
            <dc:creator><![CDATA[HammyAssassin]]></dc:creator>
            <pubDate>Mon, 14 Aug 2023 14:47:04 GMT</pubDate>
            <atom:updated>2023-08-14T14:47:04.134Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7kj72DZRjoua7svzzXk_uQ.jpeg" /></figure><h3>Introduction</h3><p>I am in an auspicious position to comment on “Remote Working” vs. “Return to Office” and how they relate to the role of engineering ICs and Managers. I spent most of my career as an IC in the office. WFH was sporadic and a novelty.</p><p>I was an IC during the first 3–4 months of the pandemic. I settled into a routine and got to know the beneficial impact it had on <a href="https://randsinrepose.com/archives/anti-flow/">Flow</a>, focus, and just how much I found the office a distracting, albeit fun, environment.</p><p>I moved to a management role during this time too. I was aware how much harder it would be as a result of not being able to connect socially to my team. And it was. I underestimated it.</p><p>Despite this, I have learnt that if I want the most value from my teams, I should embrace complexity in how we all work. At the team level as well as at an individual level. There is no one size fits all.</p><p>Leaders need to take pause and think about how best their teams work, and not how they themselves best work. Asking what it is that they are trying to accomplish by a policy of RTO.</p><h3>The Manager</h3><p>A manager’s day is rooted around conversations. Casual, formal, closed-door, open-door, water cooler, coffee machine, ad-hoc desk conversations. This is not to suggest leaders don’t need Flow and time to focus. We really do &amp; it’s something we should strive to work into our schedules. The <a href="http://www.paulgraham.com/makersschedule.html">Makers Schedule, Managers Schedule</a> is flawed in its descriptions of engineering managers and ICs in teams.</p><p>As leaders, our role is to enable and empower our teams to do their best work.</p><p>We’re multipliers.</p><p>Our value shows in how well our teams work. The quality of their work. The speed of their work. Their agility. Their performance. Maximizing our teams performance involves leaders listening to how their teams work, and coupling it with observed and measured data.</p><h3>The Engineering IC</h3><p>As Engineering Managers and Leaders, we want our ICs to be able to get in and out of Flow states quickly. We encourage agility, speed to change, comfort with ambiguity etc. No matter how good our ICs get at this, it comes at a cost. Interrupting ICs several times a day will have an impact on their Flow state and thus their ability to deliver a roadmap.</p><p>Engineering ICs, especially below staff level ICs, need time to focus, write, research, build and test the products we sell. Giving them the scope to do this is critical.</p><p>None of this is to say they can work without collaboration and connection to their contemporaries. There’s an argument that they should connect with them more than us. But there are a myriad of ways for them to accomplish this, the office being just one.</p><h3>The Office</h3><p>The open office is one that was <a href="https://www.newyorker.com/business/currency/the-open-office-trap">originally designed for communication and idea flow</a> in the 50’s, before the creation of the Internet, around the time the <a href="https://www.npr.org/2013/10/23/239241106/happy-birthday-copy-machine-happy-birthday-copy-machine#:~:text=Inventor%20Chester%20Carlson%20used%20static,dramatic%20change%20in%20the%20workplace">photocopier first came to market</a>, let alone applications like Zoom, Slack, Miro and the hundreds of other collaborative cloud based tools. The office can still solve some problems for us, just not as a one size fits all approach. Rethinking and Reimaging how offices are used will be a rewarding task for any EM.</p><h3>An Old Problem Solved Many Times Over</h3><p>Nowadays communication and collaboration, the original problems solved by the open office, have been solved in other ways. Ways that allow engineering ICs to stay in Flow for longer. To customize what kind of distractions they enable.</p><h3>Conclusion</h3><p>The push for RTO from senior tech leaders highlights a disconnect and a lack of understanding of how engineering ICs work, lending evidence to an existing suspicion and distrust of managers’ motives in RTO “<a href="https://en.wikipedia.org/wiki/Scientific_method">experiments</a>”.</p><p>Managers and Leaders who are advocating for a RTO, need to recognise that this way of working doesn’t suit everyone and in fact decreases productivity as well as work satisfaction among a group critical to the success of the business.</p><p>Embracing the complexity of multiple ways of working, listening with empathy to your teams, building trust and collectively engaging with the problem will ultimately pay dividends in the success of your company.</p><p>I’ll finish with a note of caution for Leaders from “<a href="https://www.amazon.co.uk/Staff-Engineer-Leadership-Beyond-Management/dp/B097CMGFHD/ref=sr_1_1?keywords=staff+engineer+will+larson&amp;qid=1691779336&amp;sprefix=staff+engineer+will+%2Caps%2C129&amp;sr=8-1">Staff Engineer: Leadership Beyond the Management Track</a>” by Will Larson. Critical reading for any Engineering Manager.</p><blockquote>It’s surprisingly common for a new senior leader to join a company and immediately drive a strategy shift that fundamentally misunderstands the challenges at hand. The ghosts of their previous situation hold such a firm grasp on their understanding of the new company that they misjudge the familiar as the essential.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=71ccaaf17a3f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Extending UIKit with Combine, MVVM and Unit Tests]]></title>
            <link>https://hammyassassin.medium.com/extending-uikit-with-combine-mvvm-and-unit-tests-597f47c76630?source=rss-2118c84365e8------2</link>
            <guid isPermaLink="false">https://medium.com/p/597f47c76630</guid>
            <category><![CDATA[combine]]></category>
            <category><![CDATA[mvvm]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[reactive-programming]]></category>
            <category><![CDATA[uikit]]></category>
            <dc:creator><![CDATA[HammyAssassin]]></dc:creator>
            <pubDate>Sun, 04 Apr 2021 19:07:20 GMT</pubDate>
            <atom:updated>2021-04-06T17:25:09.187Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0_oMeh1f-9HG9fq41_H9wQ.png" /></figure><p><em>Simple Combine Publisher &amp; Subscription for UIKit’s UITextField with MVVM and Unit Tests.</em></p><p>In a previous article I wrote about getting to know ReactiveCocoa 5, with MVVM and Unit Tests. The premise was a pretty basic login screen and provided a good jumping off point to see some uses of a reactive library.</p><p>Here we’ll take a similar approach, but with Combine and UIKit. While building a screen like this in SwiftUI is easy, you may already have an existing UIKit app that you want to introduce Combine too. Or even start replacing some RxSwift or ReactiveCocoa.</p><p>ReactiveCocoa provides continuousTextValues for any UITextField. You can couple this value to other UI updates to create a UI that provides plenty of feedback to the end user. Combine doesn’t provide us with such a function. But that provides us with a chance to write our own <strong>Publisher</strong> and <strong>Subscription</strong> .</p><h4>Architecture</h4><p>The application has a simple MVVM-C architecture. A Coordinator will create the LoginViewController and can update it with a LoginViewModel. The view model will handle any UI or display-logic and the Coordinator will handle any navigation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/421/1*m6thm-SdPB4OyEex1WTOoA.png" /><figcaption>MVVM-C</figcaption></figure><p>Instead of using the delegate callbacks to know when text is changing in a UITextField, we create a custom publisher for the UIControl events and and subscribe to this publisher in our LoginViewController.</p><h4>ControlPublisher</h4><p>Let’s start with the ControlPublisher. This isn’t as scary as it seems.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e4d483badf7430ab395aa9f55f6c7d70/href">https://medium.com/media/e4d483badf7430ab395aa9f55f6c7d70/href</a></iframe><p>A custom publisher needs to implement the receive(subscriber: s) function and define an Output and a Failure.</p><p>Since ControlPublisher is based on UIControl events it will never end so we can set our Failure typealias to Never.</p><p>Value is the emitted Value for the KeyPath provided.</p><p>There are some stored properties, the UIControl, the KeyPath whose value will be emitted, and the events we want to emit them on.</p><p>In order to handle the receive(subscriber: s)function, we need a <strong>Subscription</strong>.</p><h4>ControlSubscription</h4><p>ControlSubscription is a <em>little</em> more complicated. In the Combine world it’s important to remember that the <strong>Publisher</strong> doesn’t hold a reference to a Subscriber or Vice Versa. When a <strong>Subscriber</strong> subscribes to a Publisher, the Publisher creates a <strong>Subscription</strong> for that Subscriber, and the Subscription sends new values to the Subscriber.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3049f5b295fb5ee516e63265d4e1e94f/href">https://medium.com/media/3049f5b295fb5ee516e63265d4e1e94f/href</a></iframe><p>Let’s break down some of the parts here.</p><ul><li>Our standard Subscription methods are request(_ demand: Subscribers.Demand) and cancel()</li><li>request(_ demand: Subscribers.Demand) checks if we have sent the initial value, and if not, sends it to the subscriber.</li><li>cancel() removes our Subscription as a target on the UIControl and sets the subscriber to nil.</li><li>init sets private properties and add the Subscription as a target on the control for the given event.</li><li>handleEvent() is called when the Control.Event happens and calls receive on the subscriber.</li></ul><p>phew.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/0*Mj4iNyK-8lCTyjp5.jpg" /></figure><p>Now that ControlSubscription is finished, our receive function in ControlPublisher creates an instance of ControlSubscription and provides it to our Subscriber .</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/aae1bbbc51ab00f6229e30da1c06b691/href">https://medium.com/media/aae1bbbc51ab00f6229e30da1c06b691/href</a></iframe><h4>Extending UIKit</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/df1e51693732c7d333f3717aca03a836/href">https://medium.com/media/df1e51693732c7d333f3717aca03a836/href</a></iframe><p>An extension to UITextField with a computed property textPublisher is created. Similar to the UITextField text property, it’s a publisher with an optional String value and Never ends.</p><h4>LoginViewModel</h4><p>Any view controller logic is here. i.e. when a password doesn’t satisfy a certain length, the password UTextField should have a red background color &amp; only when the password and username field passes validation should we display the login button.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3a8561835295e33739935306174cd98a/href">https://medium.com/media/3a8561835295e33739935306174cd98a/href</a></iframe><h4>LoginViewController</h4><p>LoginViewController is basic — just the way we like it. We set up the subviews and lay them out with anchors.</p><p>There is a viewModel property and a subscriptions Set&lt;AnyCancellable&gt; that stores any subscriptions the view controller is subscribed to.</p><p>Since our UITextField properties now have a Combine based publisher, we don’t need to add targets or special handling of their text values. The publishers are sent to our view model the subscription is stored in our view controller.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9befac8f400ae525fa935ebfa27593bd/href">https://medium.com/media/9befac8f400ae525fa935ebfa27593bd/href</a></iframe><p>In viewDidLoad we setup our bindings with whatever view model we have.</p><h4>Testing</h4><p>For us to test our view model API, we just need a way to easily create publishers. Combines CurrentValueSubjects can be used.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cb2abf5c8eb6796138ae8ef30ccc8828/href">https://medium.com/media/cb2abf5c8eb6796138ae8ef30ccc8828/href</a></iframe><h4>Closing</h4><p>Thanks for taking the time to read this article. Hopefully it helps you understand some of how Combine works the same way writing this helped me! I hope it enables you to bring these reactive programming techniques to your app.</p><h4>Further Resources</h4><p>The code featured here are parts of a <a href="https://github.com/HamstringAssassin/CombineLogin">sample project</a>. The sample app has been extended with a button ControlEvent that is similar to ControlPublisher but doesn’t take a KeyPath .</p><p><a href="https://github.com/HamstringAssassin/CombineLogin">HamstringAssassin/CombineLogin</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=597f47c76630" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Scalable Material Design Cards with UICollectionViews]]></title>
            <link>https://hammyassassin.medium.com/a-dynamic-material-design-card-for-ios-1fc2cfd2c311?source=rss-2118c84365e8------2</link>
            <guid isPermaLink="false">https://medium.com/p/1fc2cfd2c311</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[material-design]]></category>
            <category><![CDATA[uitableviewcell]]></category>
            <category><![CDATA[uicolectionview]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[HammyAssassin]]></dc:creator>
            <pubDate>Mon, 27 Jan 2020 11:30:30 GMT</pubDate>
            <atom:updated>2020-06-14T17:06:32.656Z</atom:updated>
            <content:encoded><![CDATA[<h3>Intro</h3><p>Cards are an important part of mobile and web development. They allow us to group meaningful content or information together. When applications need to display large amounts of content to the user, Cards allow us to display it clearly and concisely and allow us to separate groups of information visually. It can help improve navigation in our applications, allowing the user to interact with either the Card or its contents in very customizable ways.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7HZNSxqgrrWfC7Ub_w-VWw.png" /><figcaption>Two Cards with different numbers of Items</figcaption></figure><p>Cards can be deceivingly difficult to construct. In the screenshot above there are 4 distinct components.</p><ul><li>Title text</li><li>Image and text</li><li>Text</li><li>Footer</li></ul><p>Items can appear in a Card more than once — We could have N Image and text views in a Card. It has no fixed arrangement — the text could be above the Image and text. Our simple text can be of variable height. Each item is contained in a view with a border and a shadow. And finally, a Card can be of variable height with possibly a fixed max height. With these requirements in mind, we need to think about how to construct these items so they are reusable, have a flexible layout, and more importantly, easily extendable should a new item be designed.</p><p>With some initial investment in developing an architecture for your Cards, you can easily expand the UI when needed. We don&#39;t want to be modifying the flow every time a new part of the card shows up. We want to build modular, reusable components that are data-driven.</p><h4>Protocols</h4><p>In this project, I have defined a few helpful protocols.</p><p>Cell ViewModel CardViewModelProtocol CardItemViewModel</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a41f0065d05720d0963f4b4227b10022/href">https://medium.com/media/a41f0065d05720d0963f4b4227b10022/href</a></iframe><p>These are simple protocols that help define some of the relationships between objects, and allow us to generalize some methods. For example, all table view and collection view cells that conform to cell implement updateWith(viewModel: ViewModel?) . In each of the implementations, we perform an optional cast to the expected type, otherwise return. This is one of the powerful uses of protocols and optionality in Swift.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/16ca3c1de5dff80729f3abb3cd58cfaf/href">https://medium.com/media/16ca3c1de5dff80729f3abb3cd58cfaf/href</a></iframe><h4>A side note on MVVM</h4><p>MVVM (Model-View-ViewModel) is a common iOS architecture. It&#39;s quite lightweight in terms of defined classes and objects and is a great way to remove some of the business logic from our views and View Controllers. These classes can get large with layout code, property definitions, and lifecycle method implementations let alone including business logic. If you’d like to learn more about MVVM, here are some great articles.</p><ul><li><a href="https://www.raywenderlich.com/34-design-patterns-by-tutorials-mvvm">Design Patterns by Tutorials: MVVM</a></li><li><a href="https://www.objc.io/issues/13-architecture/mvvm/">Introduction to MVVM</a></li></ul><p>I’ve used it in this sample app but feel free to avoid it if you prefer.</p><h4>CollectionTableCell</h4><p>The CollectionTableCell is the UITableViewCell that will contain a UICollectionView. If we want to display a single Card — We will be displaying a UITableView with a single Cell.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*74rOyhObRSAMHIoe3yXq9Q.png" /><figcaption>A single CollectionTableCell, containing a UICollectionView</figcaption></figure><p>For every Card, we will display a CollectionTableCell. Their data source is a CardViewModel. CardViewModel contains an array of ItemViewModels — Its data-source. Each of these is displayed using a custom UICollectionViewCell. This is the root of our reusability and data-driven architecture. When the data-source changes, our Card will change. The order, number, and contents of each item is defined by this data-source.</p><p>Each ItemCell is registered in our UICollectionView. When a new ItemCell is created it needs to be registered with CollectionTableCell.</p><p>The estimatedItemSize in our CardFlowLayout is set to .automaticSize. This allows our cells to be sized with Auto Layout.</p><p>Contained in each Cell is a CollectionContainer UIView. This allows us to add a drop shadow to the Card. CollectionContainer has a bottom constraint to the ContentView of +20. This creates the spacing between cards.</p><p>This spacing constraint is reflected in systemLayoutSizeFitting(<strong>_</strong> targetSize: CGSize, withHorizontalFittingPriority horizontalFittingPriority: UILayoutPriority, verticalFittingPriority: UILayoutPriority) -&gt; CGSize. Any constraints added to the Cell should be reflected in this method.</p><h4>CardFlowLayout</h4><p>Now is a good time to explore CardFlowLayout. The requirements for how the cells in the Collection View are laid out is simple. They need to fill the width of the Collection View regardless of landscape or portrait. Once the width of the item is set and using .automaticSize , Auto Layout will determine the height of each Item.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5395f72c3dae675cec8cafad3b2eccdd/href">https://medium.com/media/5395f72c3dae675cec8cafad3b2eccdd/href</a></iframe><h4>CardViewModel</h4><p>CardViewModel is initialized with a Card model. For the example project, A TitleItemViewModel and an ImageItemViewModel is injected as the first and second objects in the data-source array. Each Item model in our Card is used to create anItemCellViewModel. Finally, a FooterItemViewmodel is appended.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3362fb0a2aa24a469453618e00b564c6/href">https://medium.com/media/3362fb0a2aa24a469453618e00b564c6/href</a></iframe><h4>CardItemCell</h4><p>CardItemCell is a parent class of all the items in our CollectionView. It simply overrides preferredLayoutAttributesFitting(<strong>_</strong> layoutAttributes: UICollectionViewLayoutAttributes) -&gt; UICollectionViewLayoutAttributes and returns the layout attributes for the cell.</p><h4>Items</h4><p>CardItems are simply custom UICollectionViewCells and their corresponding ViewModel. There&#39;s no limit to the number of Item types used in a Card. In the case of the sample application, 4 CardItems have been defined. TextItemCell, a TitleItemCell, FooterItemCell and an ImageItemCell.</p><p>Each Item has a Xib to help with Auto Layout. As each of these are subclasses of CardItemCell we don’t need to override preferredLayoutAttributesFitting(<strong>_</strong> layoutAttributes: UICollectionViewLayoutAttributes) -&gt; UICollectionViewLayoutAttributes. Each Item implements the Cell protocol so that A ViewModel can easily be injected.</p><p>For example, the ImageItemCell and ViewModel are below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4dc93bb5c4dff90f177a8cd3286e0a61/href">https://medium.com/media/4dc93bb5c4dff90f177a8cd3286e0a61/href</a></iframe><h4>Full Project</h4><p>You can find the full project here.</p><p><a href="https://github.com/HamstringAssassin/CardCollection">HamstringAssassin/CardCollection</a></p><p>There are some useful protocols and extensions that are used that are not included in the code snippets above.</p><h4>Future</h4><p>There’s a lot more to be extended and improved here — the contents of each of the CardItemCells can be extracted to UIViews. So the layout can be used anywhere. Coupled with the fact that the views don’t contain any logic, we can see how we can quickly implement design changes by either quickly adding a new View, or by safely modifying an existing one. We would only need a single CardItemCell, and its contentView could be determined by the ViewModel.</p><p>The size of the CollectionTableCells could be cached and only invalidated when something changes their size such as a rotation.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1fc2cfd2c311" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Up and Running with Server Side Swift: Part 4 — Models and Routers]]></title>
            <link>https://hammyassassin.medium.com/up-and-running-with-server-side-swift-part-4-models-and-routers-2bc083fc9fa?source=rss-2118c84365e8------2</link>
            <guid isPermaLink="false">https://medium.com/p/2bc083fc9fa</guid>
            <category><![CDATA[perfect]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[server-side-swift]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[HammyAssassin]]></dc:creator>
            <pubDate>Mon, 19 Mar 2018 13:28:08 GMT</pubDate>
            <atom:updated>2018-03-19T13:28:08.556Z</atom:updated>
            <content:encoded><![CDATA[<h3>Up and Running with Server Side Swift: Part 4 — Models and Routers</h3><p><em>Ive wanted a basic, browser based todo list for a while. Something free of any distractions. Building this with Swift, and getting to know some of the libraries involved seemed like a great place to start.</em></p><p><em>This is a 4 part series outlining how to set up the project, getting started with routing, setting up the database and finally creating the model and controllers of our application. To see part 1 click </em><a href="https://medium.com/@HammyAssassin/up-and-running-with-server-side-swift-part-1-to-do-list-project-setup-cbf84b22364b"><em>here</em></a><em>.</em></p><h3>Introduction</h3><p>In this final part, I will outline the project structure, the model, modelAPI and RouteController used in the app.</p><h3>Models and Some Housekeeping</h3><p>Ive decides to split my project up into the following classes.</p><ul><li>A model object: This will be a representation of our database object. This will perform any database actions.</li><li>modelAPI object: This will take requests and interact with the model and return something usable to the router.</li><li>RouteController: which will handle the routing of our application</li><li>main: which, all going well, will be nice and short and wont really do anything other than set up our DB.</li></ul><p>This keeps responsibilities nicely grouped together.</p><h4>Model</h4><p>So, at this point, we need to decide on what our model should look like. For the sake of the tutorial, i’m going to assume that it simply has an id, a description, a priority and a value for if it should be visible or not.</p><p>We need to override two methods…</p><pre>override func table() -&gt; String<br>override func to(_ this: StORMRow)</pre><p>This allows us to identify the table that the model corresponds to, and translates our DB object into an application model we can use.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0a37fa58e94e4d28f749e6161fe3e657/href">https://medium.com/media/0a37fa58e94e4d28f749e6161fe3e657/href</a></iframe><p>We’re storing priority in the DB, but our model has itemColor to help with coloring the priority icon. After that there are some other helper methods to convert out model into something we can use in our router. We also have static methods to help with creating, updating and deleting items in the database.</p><h4>ModelAPI</h4><p>ListItemAPI, will handle requests from the Router and have access to the model to perform some meaningful tasks. In a lot of the cases, its methods are returning String? and this in turn is being returned in the response body.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/58ea9a6e9f6fece7ab43baf4aab3fdcb/href">https://medium.com/media/58ea9a6e9f6fece7ab43baf4aab3fdcb/href</a></iframe><h4>Router</h4><p>We will create a class called TodoListRouter that will handle any request made to localhost:8080/todolist. We will have 4 routes to create.</p><pre>Route(method: .get, uri: &quot;/todolist&quot;, handler: indexView)<br>Route(method: .post, uri: &quot;/todolist&quot;, handler: addItem)<br>Route(method: .post, uri: &quot;/todolist/{id}/delete&quot;, handler: delete)<br>Route(method: .post, uri: &quot;/todolist/{id}/complete&quot;, handler: complete)</pre><p>We have a post and get to /todolist which we’ll use to display the list of items, or create a new one. We can delete an item and also mark it as complete.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7bcd1cdffeb925834d734a1e9c636ae6/href">https://medium.com/media/7bcd1cdffeb925834d734a1e9c636ae6/href</a></iframe><h4>Housekeeping</h4><p>Ive also extended HTTPResponse with 2 methods. A standard completed header and an internal server error.</p><p>We will be dealing with a lot of dictionaries, and arrays of dictionaries, so its useful to create a couple of typealiases to avoid confusion.</p><pre>typealias JSONDictionary = [String: Any]<br>typealias JSONArray = [JSONDictionary]</pre><h4>HTML</h4><p>The html page is pretty basic. It uses bootstrap and includes a form to add new items and the main list of items.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/70272ff1d447391fccddde6b2fe4847d/href">https://medium.com/media/70272ff1d447391fccddde6b2fe4847d/href</a></iframe><h3>Conclusion</h3><p>If you want to download the whole project and take it for a spin just follow this <a href="https://github.com/HamstringAssassin/WhatsNext">link</a>.</p><p>Theres loads more to do, but thats a basic server up and running with swift and serving a basic todo list that we can create, delete and update items.</p><p>Be sure to check out the perfect documentation for more example projects as well as the amazing R<a href="https://videos.raywenderlich.com/courses/77-server-side-swift-with-perfect/lessons/1">ay Wenderlich video series</a> on server side swift with Perfect.</p><h3>Further work and improvements</h3><p>A basic feature I will add to the app will be a way to update items as part of the list.</p><p>Another feature would be a createdOn timestamp and a completedOn timestamp included in the database.</p><p>Some more improvements would be to generalise the methods being used in the model — i’m not entirely happy with the structure of the application. If we had an application with several models, we would have a lot of boilerplate code in the models, and in the modelAPI. I think the next steps would be to find a way to reduce this and to reduce the complexity of the model itself.</p><p>I would also like to reduce the dependancy on PostgresSQL. It would be nice if the application could create a database if its not found. This would help with the idea of being able to run the server locally much more easily.</p><p>Another server side swift library that gets a lot of attention is Vapor. I would like to try recreate the application using <a href="https://github.com/vapor/vapor">Vapor</a>.</p><p>Finally, The server is ran with Xcode so id like to get it running on on Linux.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2bc083fc9fa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Up and Running with Server Side Swift: Part 3 — postgrSQL and StORM]]></title>
            <link>https://hammyassassin.medium.com/up-and-running-with-server-side-swift-part-3-postgrsql-and-storm-bdd80742dd19?source=rss-2118c84365e8------2</link>
            <guid isPermaLink="false">https://medium.com/p/bdd80742dd19</guid>
            <category><![CDATA[server-side-swift]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[perfect]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[HammyAssassin]]></dc:creator>
            <pubDate>Mon, 19 Mar 2018 13:27:27 GMT</pubDate>
            <atom:updated>2018-03-19T13:27:27.199Z</atom:updated>
            <content:encoded><![CDATA[<h3>Up and Running with Server Side Swift: Part 3 — postgrSQL and StORM</h3><p><em>Ive wanted a basic, browser based todo list for a while. Something free of any distractions. Building this with Swift, and getting to know some of the libraries involved seemed like a great place to start.</em></p><p><em>This is a 4 part series outlining how to set up the project, getting started with routing, setting up the database and finally creating the model and controllers of our application. To see part 1 click </em><a href="https://medium.com/@HammyAssassin/up-and-running-with-server-side-swift-part-1-to-do-list-project-setup-cbf84b22364b"><em>here</em></a><em>.</em></p><h3>Introduction</h3><p>Our application will use a postgrSQL database, and a library called StORM to access it. Below, we’ll set up the database and the user the application will use to access it.</p><h3>Installing postgrSQL</h3><p>first, update brew.</p><pre>brew update</pre><p>Then install libxml2 as its a dependency for Perfect.</p><pre>brew install libxml2</pre><p>Next, install postgres.</p><pre>brew install postgres</pre><p>Ok, so now we need to start postgresql server, so that you can create databases, users etc.</p><pre>brew services start postgresql</pre><p>If theres an issue you can replace start here with restart or stop.</p><p>Our application will need a user to access the database. So lets create one.</p><pre>createuser -D -P todolist</pre><p>Above we see the command to create a user. -D means that they cannot create databases. -P means that they requite a password. Finally, todolist is the name of the user. This can be anything you want. Once you hit enter on the above command, you’ll be asked to enter a password and password confirmation. This is the password for the user todolist_password</p><p>Next, lets create a database for the todolist users to access.</p><pre>createdb -O todolist todolist_database</pre><p>We have the command to create a database above, assigned the user todolist as the databases owner, -O and given the database a name, todolist_database.</p><p>Finally, lets access the database as the todolist user.</p><pre>psql -d todolist_database -U todolist</pre><p>If you want to quit, just type /q and hit enter.</p><h3>StORM</h3><p>Lets add StORM as a dependancy to access our DB. Update package.swift with the following dependancy.</p><pre>.package(url: &quot;https://github.com/SwiftORM/Postgres-StORM.git&quot;, from: &quot;3.0.0&quot;)</pre><p>and dont forget to add PostgresStORM as a target dependancy. Run swift package update and swift package generate-xcodeproj back in our terminal and we should be ready to add import PostgresStORM into our Main.swift.</p><h3>Next up…</h3><p>Now that we have the database setup, the next part will tackle some basic database actions and will set up routes to perform these actions via a webpage. We’ll also create a model for our database object that our application can interact with. Click this <a href="https://medium.com/@HammyAssassin/up-and-running-with-server-side-swift-part-4-models-and-routers-2bc083fc9fa">link</a> to see more.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bdd80742dd19" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Up and Running with Server Side Swift: Part 2 — Perfect Mustache]]></title>
            <link>https://hammyassassin.medium.com/up-and-running-with-server-side-swift-part-2-perfect-mustache-113b829ad05c?source=rss-2118c84365e8------2</link>
            <guid isPermaLink="false">https://medium.com/p/113b829ad05c</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[perfect]]></category>
            <category><![CDATA[server-side-swift]]></category>
            <dc:creator><![CDATA[HammyAssassin]]></dc:creator>
            <pubDate>Mon, 19 Mar 2018 13:25:13 GMT</pubDate>
            <atom:updated>2018-03-19T13:25:13.631Z</atom:updated>
            <content:encoded><![CDATA[<h3>Up and Running with Server Side Swift: Part 2 — Perfect Mustache</h3><p><em>Ive wanted a basic, browser based todo list for a while. Something free of any distractions. Building this with Swift, and getting to know some of the libraries involved seemed like a great place to start.</em></p><p><em>This is a 4 part series outlining how to set up the project, getting started with routing, setting up the database and finally creating the model and controllers of our application. To see part 1 click </em><a href="https://medium.com/@HammyAssassin/up-and-running-with-server-side-swift-part-1-to-do-list-project-setup-cbf84b22364b"><em>here</em></a><em>.</em></p><h3>Introduction</h3><p>Now that we have a web server up and running, serving us text, lets see if we can get it to serve up some HTML. We’ll also want to inject some values from our swift code into our HTML. To do this we’re going to use perfect Mustache.</p><p><a href="https://github.com/PerfectlySoft/Perfect-Mustache">PerfectlySoft/Perfect-Mustache</a></p><h3>Getting Mustache</h3><p>We need to add Perfect Mustache to our list of project dependencies. So in Package.swift add the following.</p><pre>.package(url: “https://github.com/PerfectlySoft/Perfect-Mustache.git&quot;, from: “3.0.0”)</pre><p>Remember to add PerfectMustache to the list of target dependancies.</p><p>Back at our terminal, we’ll update our project with</p><pre>swift package update<br>swift package generate-xcodeproj</pre><p>To make sure everything is ok, add import PerfectMustache to the list of imports in Main.swift and build and run.</p><h3>Adding HTML Files</h3><p>We now need to add some HTML files to our project. Add a file, hello.html to our webroot directory and add some HTML.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/80d1c694c49d9b7bac90f4325595c263/href">https://medium.com/media/80d1c694c49d9b7bac90f4325595c263/href</a></iframe><p>The server needs a route for this new html, and in order for us to use Mustache, we need to create a type that conforms to the MustachePageHandler protocol. This has one method that needs implimenting, func extendValuesForResponse(context contxt: MustacheWebEvaluationContext, collector: MustacheEvaluationOutputCollector)</p><p>This handles the data that will be used to fill in any of the mustache template.</p><p>The type also has a property that can be passed to the template to render.</p><p>Our Main.swift will look something like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2e86c1d7d2346e2ceaae6c08bb87ad48/href">https://medium.com/media/2e86c1d7d2346e2ceaae6c08bb87ad48/href</a></iframe><p>We’ve added a route for the URI /helloMustache. The response and request are handled by a method called helloMustache(request: HTTPRequest, response: HTTPResponse). Here we call mustacheRequest and pass in a value for name in a variable of type MustacheEvaluationContext.MapType(). This is just a typealias for [String:any].</p><p>Build and Run, navigate to localhost:8080/helloMustache and you should see the HTML with the values passed in from your swift code. Pretty cool eh!</p><h3>Next up…</h3><p>So now our basic swift webserver is not only serving us just text, but serving us actual HTML files, and we are able to pass in some new computed values from our swift code. Next up, we’ll take a look at some database actions with postgrSQL and StORM. Click this <a href="https://medium.com/@HammyAssassin/up-and-running-with-server-side-swift-part-3-postgrsql-and-storm-bdd80742dd19">link</a> to see more.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=113b829ad05c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Up and Running with Server Side Swift: Part 1 — To Do list Project Setup]]></title>
            <link>https://hammyassassin.medium.com/up-and-running-with-server-side-swift-part-1-to-do-list-project-setup-cbf84b22364b?source=rss-2118c84365e8------2</link>
            <guid isPermaLink="false">https://medium.com/p/cbf84b22364b</guid>
            <category><![CDATA[perfect]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[server-side-swift]]></category>
            <dc:creator><![CDATA[HammyAssassin]]></dc:creator>
            <pubDate>Mon, 19 Mar 2018 13:24:16 GMT</pubDate>
            <atom:updated>2018-03-23T13:07:07.071Z</atom:updated>
            <content:encoded><![CDATA[<h3>Up and Running with Server Side Swift: Part 1 — To Do list Project Setup</h3><p><em>Ive wanted a basic, browser based todo list for a while. Something free of any distractions. Building this with Swift, and getting to know some of the libraries involved seemed like a great place to start.</em></p><p><em>This is a 4 part series outlining how to set up the project, getting started with routing, setting up the database and finally creating the model and controllers of our application.</em></p><h3>Introduction</h3><p>Part 1 will outline a basic project setup including using swift package manager, and get us started using Swift to return some text in the response from the server.</p><h3>Project setup</h3><p>To start, lets make a directory for our project, and navigate to it.</p><pre>mkdir WhatsNext<br>cd WhatsNext</pre><p>Next, we’ll use swift package manager to create a swift executable package.</p><pre>swift package init --type executable</pre><p>Now, generate an xcode project.</p><pre>swift package generate-xcodeproj</pre><p>Open the project and switch to the second target. Build and Run and you should see “Hello, world!” printed in the console.</p><pre>open WhatsNext.xcodeproj</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*hZS-cfHLwrqUzx35hwE60A.png" /></figure><h3>Server Setup with Perfect</h3><p>Add perfect-HTTPServer as a dependancy of your project. Open Package.swift and add the following to your dependancies.</p><pre>.package(url: &quot;https://github.com/PerfectlySoft/Perfect-HTTPServer.git&quot;, from: &quot;3.0.0&quot;)</pre><p>Also add &quot;PerfectHTTPServer&quot; as a dependancy to your target. If you are using swift 3, you might encounter issues with the syntax above. You can find out more <a href="https://swift.org/blog/swift-package-manager-manifest-api-redesign/">here</a>.</p><p>Your final Package.swift should look like this…</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/036117aa5f663529b3e683d3fa1bf7e4/href">https://medium.com/media/036117aa5f663529b3e683d3fa1bf7e4/href</a></iframe><p>Now, head back to the terminal and update your projects dependancies and regenerate the xcodeproj.</p><pre>swift package update <br>swift package generate-xcodeproj</pre><p>Assuming no issues add the following imports to the top of main.swift and build and run.</p><pre>import PerfectLib<br>import PerfectHTTP<br>import PerfectHTTPServer</pre><h3>A server needs to Serve Something</h3><p>So our web server needs to serve up a directory or files. For the sake of simplicity, we will create a folder in our project called webroot, and add a single file there for our project to serve.</p><pre>mkdir webroot<br>touch webroot/hello.txt<br>swift package regenerate-xcodeproj</pre><p>Add some placeholder text to know that the file is being served.</p><p>Next up, we need to create our server in main.swift . We create a server, set its port and documentRoot, start it and catch any exceptions that it will throw, such as if the port is already in use.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d50ef64ba637499ca831f0897029d222/href">https://medium.com/media/d50ef64ba637499ca831f0897029d222/href</a></iframe><p>Before we run, we need to set the document root of the target to be the project directory. To do this select the second target then edit sceme -&gt; run -&gt; options and tick working directory and supply the directory of the project.</p><p>Build and run, open a browser and navigate to localhost:8080 . You should see The file /index.html was not found.</p><p>We need to add a route to the server, so it knows where to look and what to do when this URL is requested. We do this by adding a route to the server as below. In this case, we’ll also add a method to read the contents of the file we added to the webroot directory and handle any errors that might occur, if the file doesnt exist.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1b81b2cdf4025c8ddc57a0876f31f5b7/href">https://medium.com/media/1b81b2cdf4025c8ddc57a0876f31f5b7/href</a></iframe><p>Build, run and navigate to localhost:8080 again and you should see whatever text you added to your txt file.</p><p>You can add as many routes as you like to your server, each with different URLs.</p><h3>Next up…</h3><p>So now we are one step closer to our todo list. We have a basic swift web server up and running. Next, we’ll move onto serving up some HTML pages and injecting some computed values into our HTML using Mustache. Click this <a href="https://medium.com/@HammyAssassin/up-and-running-with-server-side-swift-part-2-perfect-mustache-113b829ad05c">link</a> to see more.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cbf84b22364b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting to know ReactiveCocoa, MVVM and Unit Tests]]></title>
            <link>https://hammyassassin.medium.com/getting-to-know-reactivecocoa-mvvm-and-unit-tests-6ee173e122c1?source=rss-2118c84365e8------2</link>
            <guid isPermaLink="false">https://medium.com/p/6ee173e122c1</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[HammyAssassin]]></dc:creator>
            <pubDate>Tue, 18 Apr 2017 08:09:18 GMT</pubDate>
            <atom:updated>2017-04-18T08:09:18.230Z</atom:updated>
            <content:encoded><![CDATA[<h4>Introduction</h4><p>In trying to get to know the new ReactiveCocoa 5 framework, I decided to take the Ray Wenderlich tutorial (<a href="https://www.raywenderlich.com/62699/reactivecocoa-tutorial-pt1">here</a>) and rewrite it with swift and RAC 5.</p><p>If you haven’t read it, I would highly suggest diving in. Its a fun tutorial and it gives a better introduction to ReactiveCocoa than I ever could.</p><p>This was also an opportunity to rewrite the starter application architecture to follow the MVVM pattern and tackle some unit tests with an application heavily dependent on RAC 5. I also decided to use PureLayout to build my views in code to avoid storyboards.</p><h4>Tools Used</h4><p><strong>MVVM: </strong>A way to structure and break your application apart into manageable, clean and testable classes. It consists of three parts. A Model, a View and a ViewModel. Its a popular architecture for iOS applications. It can help reduce the size of ViewControllers and can make some aspects of an application much easier to test.</p><p><strong>ReactiveCocoa 5: </strong>RAC 5 is the latest iteration of a well established iOS and MAC framework that allows objects observe changes to an object.</p><p><a href="https://github.com/ReactiveCocoa/ReactiveCocoa">ReactiveCocoa/ReactiveCocoa</a></p><p><strong>Quick / Nimble: </strong>BDD libraries for testing an iOS application.</p><ul><li><a href="https://github.com/Quick/Quick">GitHub - Quick/Quick: The Swift (and Objective-C) testing framework.</a></li><li><a href="https://github.com/Quick/Nimble">GitHub - Quick/Nimble: A Matcher Framework for Swift and Objective-C</a></li></ul><p><strong>PureLayout: </strong>A framework for writing clean and readable Auto Layout constraints in code.</p><p><a href="https://github.com/PureLayout/PureLayout">PureLayout/PureLayout</a></p><h4>Project</h4><p>A lot of my RAC code lives in my views. Thats where all the binding happens and unfortunately, thats where a lot of side effects happen. Such as in the case of this project, a border color update based on if a password is valid or not. Or maybe showing or hiding a label based on the number of characters entered into a textField. These are all problems that ReactiveCocoa helps solve for us, but can leave us with another issue of testing.</p><h4><em>Initial Project and Getting Started</em></h4><p>The starter project at <a href="https://www.raywenderlich.com/62699/reactivecocoa-tutorial-pt1">https://www.raywenderlich.com/62699/reactivecocoa-tutorial-pt1</a> is written in Objective-C. I tried to re-write it in Swift, and once I started getting into the tutorial, I wrote the RAC code with the latest version. Ive highlighted some of the differences below.</p><h4><strong>Differences with ReactiveCocoa 5</strong></h4><p>An early part of the tutorial involves printing the text entered into a UITextField to the console with ReactiveCocoa.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4a3aa847948cf9824310d33e31eeb904/href">https://medium.com/media/4a3aa847948cf9824310d33e31eeb904/href</a></iframe><p>This can be accomplished with ReactiveCocoa 5 as follows.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3db4f596848eaf4904ce7d107f3e66e5/href">https://medium.com/media/3db4f596848eaf4904ce7d107f3e66e5/href</a></iframe><p>The background color of the password UITextField needs to be set based on if the password entered is valid or not. We transform the signal to a UIColor.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3747ffb1d2359e291edc291ffabbfb4d/href">https://medium.com/media/3747ffb1d2359e291edc291ffabbfb4d/href</a></iframe><p>This can be expressed with ReactiveCocoa 5 as below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/50b004af3ded4733c522dd964299c950/href">https://medium.com/media/50b004af3ded4733c522dd964299c950/href</a></iframe><p>With our viewModel function looking like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6ea29f091de774844b179af4607caccc/href">https://medium.com/media/6ea29f091de774844b179af4607caccc/href</a></iframe><h4><em>Moving to MVVM</em></h4><p>The ViewController has a ViewModel. This is what determines how the view behaves. Business logic such as field validation can be kept here. In the case of this app, we are also keeping the valid username and password logic here, although this could arguably be placed somewhere else.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b20c945b4118965a2e72a2d6c7851b85/href">https://medium.com/media/b20c945b4118965a2e72a2d6c7851b85/href</a></iframe><p>Our ViewModel API only contains 3 public functions. These are used in its ViewController to set how it should be displayed. These are what our unit tests will be focused on.</p><p>The UITextField background color needs to be clear if the password length &gt; 3 and yellow if not.</p><p>This is the part of the application that is tested, and all that is needed to test it is a signal with a String value, and to confirm the output value.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6ea29f091de774844b179af4607caccc/href">https://medium.com/media/6ea29f091de774844b179af4607caccc/href</a></iframe><h4><em>Testing</em></h4><p>Testing the viewModel should be straightforward as all the public functions have simple inputs and outputs, that need to be verified. We create signals in our spec for both the username and the password. During our test, we assign the output of the viewModel function being tested to a variable. We then send a new value to the observer and verify the correct result.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0f77b7d62ac636f2cfa06e20389943fa/href">https://medium.com/media/0f77b7d62ac636f2cfa06e20389943fa/href</a></iframe><p>There are definitely alternative ways to test ReactiveCocoa code and i’ve found checking out the ReactiveCocoa unit tests is a great place to start.</p><p>You can checkout the completed project here:</p><p><a href="https://github.com/HamstringAssassin/RWReactivePlaygroundSwift">HamstringAssassin/RWReactivePlaygroundSwift</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6ee173e122c1" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>