<?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 Emanuel on Medium]]></title>
        <description><![CDATA[Stories by Emanuel on Medium]]></description>
        <link>https://medium.com/@emaleavil?source=rss-40b9e808d31d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ZsbQDygL-TY2hyiRtQEY5Q.jpeg</url>
            <title>Stories by Emanuel on Medium</title>
            <link>https://medium.com/@emaleavil?source=rss-40b9e808d31d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 00:04:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@emaleavil/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[Refactoring. A first example.]]></title>
            <link>https://medium.com/@emaleavil/refactoring-a-first-example-32a2709c82b8?source=rss-40b9e808d31d------2</link>
            <guid isPermaLink="false">https://medium.com/p/32a2709c82b8</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[refactoring]]></category>
            <category><![CDATA[tips]]></category>
            <dc:creator><![CDATA[Emanuel]]></dc:creator>
            <pubDate>Mon, 01 Jul 2019 18:51:35 GMT</pubDate>
            <atom:updated>2019-07-01T18:51:35.628Z</atom:updated>
            <content:encoded><![CDATA[<p>This is a note to remember all the important tips listed in the Martin Fowler’s book <strong>“Refactoring: Improving the design of existing code”.</strong></p><p>All the tips extracting in this note corresponds to <em>first chapter</em>.</p><ul><li>When you have to add a feature to a program but the code is not structured in a convenient way, first refactor the program to make it easy to add the feature, then add the feature.</li><li>Before you start refactoring, make sure you have a <strong>solid suite of tests</strong>. These tests must be self-checking.</li><li>Refactoring changes the program in small steps, so if you make a mistake, it is easy to find where the bug is.</li><li><strong>Good code should clearly comunicate what it is doing</strong>.</li><li>Breaking a large function into smaller ones only adds value if the names are good.</li><li>If your refactoring introduces performance slow-downs, finish refactoring and do performance tunning afterwards.</li><li><strong>CAMPING RULE</strong>: Always leave the code base healthier than when you found it.</li><li><strong>The true test of good code is how easy it is to change it</strong>.</li><li>The key to effective refactoring is that you go faster when you take tiny steps. The code is never broken and you can compose those small steps into substancial changes.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=32a2709c82b8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Live Data in Swift?? Really?? Beginner implementation.]]></title>
            <link>https://medium.com/@emaleavil/live-data-in-swift-really-beginner-implementation-14ebef68d7e9?source=rss-40b9e808d31d------2</link>
            <guid isPermaLink="false">https://medium.com/p/14ebef68d7e9</guid>
            <category><![CDATA[binding]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[reactive-programming]]></category>
            <dc:creator><![CDATA[Emanuel]]></dc:creator>
            <pubDate>Fri, 08 Feb 2019 19:00:53 GMT</pubDate>
            <atom:updated>2022-02-22T15:49:35.895Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi everyone, first of all I wanna say that I am not an iOS developer. I started my learnings on this platform and I want to share my first implementation with all of yours to receive feedback and improve it.</p><p>To start I did a simple application which retrieves data from an JSON API. After few years working with <strong>MVVM</strong> pattern and architecture components on Android I thought that I need something similar to LiveData on iOS. LiveData is an lifecycle aware observable that takes into account the android view state to notify only if the activity is in its visible state.</p><p>I called this class observable:</p><pre><strong>class</strong> Observable&lt;T: Equatable&gt; {</pre><pre><strong>  private</strong> <strong>let</strong> thread : DispatchQueue</pre><pre><strong>  var</strong> property : T? {</pre><pre><strong>    willSet</strong>(newValue) {</pre><pre><strong>      if</strong> <strong>let</strong> newValue = newValue,  property != newValue {</pre><pre>          thread.async {<br>            <strong>self</strong>.observe?(newValue)<br>          }<br>      }</pre><pre>   }<br>  }</pre><pre><strong> var</strong> observe : ((T) -&gt; ())?</pre><pre><strong> init</strong>(<strong>_</strong> value: T? = <strong>nil</strong>, thread dispatcherThread: DispatchQueue =     DispatchQueue.main) {</pre><pre><strong>    self</strong>.thread = dispatcherThread<br>    <strong>self</strong>.property = value<br> }<br>}</pre><p>This class has two properties: <strong>property</strong> and <strong>observe</strong>. <strong>Property</strong> is where we store the value and <strong>observe</strong> is a closure that is used to observe changes in our stored value.</p><p>Ok, Why don’t I show you and example of using it?</p><p>Inside our ViewModel, remember that we are using MVVM pattern, we are going to modify our property value after our service returns data from network.</p><pre><strong>class</strong> HeroesViewModel {</pre><pre><strong>  var</strong> data = Observable&lt;[HeroeCellViewModel]&gt;()</pre><pre><strong> func</strong> fetch() -&gt; Void {<br><br>   useCase.call { [weak <strong>self</strong>] (heroes) -&gt; Void <strong>in<br>     guard</strong> <strong>let</strong> weakSelf = <strong>self</strong> <strong>else</strong> { <strong>return</strong> }</pre><pre><strong>      if</strong> <strong>let</strong> heroes = heroes {<br>        weakSelf.data.property = heroes<br>      }<br>    }<br>  }<br>}</pre><p>Finally, we want that our View observe changes in our property and reacts to it.</p><pre><strong>class</strong> HeroesViewController: UIViewController {</pre><pre><strong>   @IBOutlet</strong> <strong>weak</strong> <strong>var</strong> heroesTableView: UITableView!</pre><pre><strong>   @IBOutlet</strong> <strong>weak</strong> <strong>var</strong> activityIndicator: UIActivityIndicatorView!</pre><pre><strong>   let</strong> viewModel = {…}()</pre><pre><strong>   override</strong> <strong>func</strong> viewDidLoad() {<br>    <strong>super</strong>.viewDidLoad()<br>    <strong>self</strong>.setObservers()<br>    <strong>self</strong>.viewModel.fetch()<br>   }<br>}</pre><pre><strong>fileprivate</strong> <strong>extension</strong> HeroesViewController {<br>   <strong>func</strong> setObservers() {<br>     viewModel.data.observe = { <strong>_</strong> <strong>in             <br>        self</strong>.heroesTableView.reloadData()<br>     }<br>   }<br>}</pre><p>I hope that you can help me to improve it. All of your comments will be well received. Thanks.</p><p><strong><em>Note:</em></strong><em> I want to apologize about my english.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=14ebef68d7e9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Testing that views are showing data from preferences]]></title>
            <link>https://medium.com/@emaleavil/testing-that-views-are-showing-data-from-preferences-eeca9dd4dff?source=rss-40b9e808d31d------2</link>
            <guid isPermaLink="false">https://medium.com/p/eeca9dd4dff</guid>
            <category><![CDATA[preference]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[test-rule]]></category>
            <dc:creator><![CDATA[Emanuel]]></dc:creator>
            <pubDate>Fri, 26 May 2017 09:07:39 GMT</pubDate>
            <atom:updated>2017-05-29T12:33:39.343Z</atom:updated>
            <content:encoded><![CDATA[<p>In this little tutorial I show you how to create a custom test rule to retrieve data from shared preferences and check if views are currently displaying that data when your activity is shown.</p><p>Imagine that we are testing our LoginActivity that contains EditText to username and password and we want to store our username on preferences.</p><p>Our test must check that if we has an stored username the EditText should display our stored value.</p><p>As I said previously, we need to create a custom test rule and override beforeActivityLaunched() method. To create a rule we need a class that extends ActivityTestRule.</p><pre>public class LoginActivityTestRule&lt;T extends Activity&gt; extends ActivityTestRule&lt;T&gt; {</pre><p>The following we need to do is implement constructors :</p><pre>public LoginActivityTestRule(Class&lt;T&gt; activityClass) {<br>  this(activityClass,false,true);<br>}<br><br>public LoginActivityTestRule(Class&lt;T&gt; activityClass, boolean initialTouchMode) {<br>  this(activityClass, initialTouchMode,true);<br>}<br><br>public LoginActivityTestRule(Class&lt;T&gt; activityClass, boolean initialTouchMode,<br>    boolean launchActivity) {<br>  super(activityClass, initialTouchMode, launchActivity);<br>  this.context = InstrumentationRegistry.<em>getTargetContext</em>();<br>  this.editor = PreferenceManager.<em>getDefaultSharedPreferences</em>(this.context).edit();<br>}</pre><p>As you can see in the last constructor we are retrieving the app context from InstrumentationRegistry class. At this point you can think why am I not using our activity context to retrieve shared preferences. There is a good reason about that if you go to the implementation code of ActivityRule class you can see that activity context it’s not created until launchActivity() method is called then if you try to use context calling getActivity() method you´ll get a NullPointerException.</p><p>Well, after this little explanation, we are going to override our beforeActivityLaunched() method. On it we are going to store our preferences that we are use to fill the views.</p><pre>@Override protected void beforeActivityLaunched() {<br>  super.beforeActivityLaunched();<br>  <br>... put your data here, e.g : <br>editor.putString(&quot;username&quot;,&quot;USERNAME&quot;)</pre><pre>  editor.commit();<br>}</pre><p>And finally, we need to create our test :</p><pre>@RunWith(AndroidJUnit4.class)<br>public class LoginActivityTest {<br><br>  @Rule<br>  public LoginActivityTestRule&lt;LoginActivity&gt; activity = new LoginActivityTestRule&lt;LoginActivity&gt;(LoginActivity.class);</pre><pre>....</pre><pre>@Test<br>  public void store_checkbox_checked_should_store_user() throws Exception {<br>    <em>onView</em>(<em>withId</em>(R.id.<em>chkRemember</em>)).check(<em>matches</em>(<em>isChecked</em>()));<br>    <em>onView</em>(<em>withText</em>(&quot;USERNAME&quot;)).check(<em>matches</em>(<em>isDisplayed</em>()));<br>  }<br>}</pre><p>Hope that post help you! And if you see something wrong feel free to tell me.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eeca9dd4dff" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>