Jekyll2021-09-17T03:41:12+00:00https://www.paulweichhart.com/feed.xmlThe education of Paul WeichhartWrite like nobody is readingPaul WeichhartIntroducing Set Your Intention2021-03-03T00:00:00+00:002021-03-03T00:00:00+00:00https://www.paulweichhart.com/2021/03/03/Introducing-Set-Your-Intention<p>I’m happy to finally share more details about the project I have been working on over the last couple of months. This week I released the 1st Version of the standalone Watch App <strong>Set Your Intention</strong> on the App Store & open sourced the Code on <a href="https://github.com/paulweichhart/Intention" target="_blank">GitHub</a>.</p>
<p><img src="/img/set-your-intention.svg" class="set-your-intention-icon" alt="Intention App Icon" /></p>
<p>Similar to the concept of Activity rings for physical health, <strong>Set Your Intention</strong> makes it easy to monitor your mental well being. Simply set your daily Intention & keep track of your Mindful Minutes through Apple Health and the supported circular Complication.
You can use your preferred Meditation App — with support for Apple Health — on your iPhone or Watch and the App will visualise your progress.</p>
<p>With this project I wanted to get more insights on Apple Health, Combine, MVVM, SwiftUI & Watch development. I have also planned to introduce new features over the next couple of months & document the progress on my Blog. First I want to add more accessibility features like dynamic type, translations and labels.
I will also look into refactoring some rough edges of the App by writing Tests first, since Apple added support for XCTest unit and UI tests with the release of <a href="https://developer.apple.com/documentation/xcode-release-notes/xcode-12_5-beta-release-notes#Testing" target="_blank">Xcode 12.5</a>. An update to my existing Posts about MVVM & SwiftUI Coordinators with examples from the App is also pending.</p>
<p>You can find more infos about the App on the <a href="https://www.paulweichhart.com/intention.html">Project Page</a> or download the App on the <a href="https://apps.apple.com/at/app/set-your-intention/id1541545532">App Store</a>. Something to add or like to know? Drop me 280 characters on twitter <a href="https://www.twitter.com/paulweichhart" target="_blank">@paulweichhart</a></p>Paul WeichhartI’m happy to finally share more details about the project I have been working on over the last couple of months. This week I released the 1st Version of the standalone Watch App Set Your Intention on the App Store & open sourced the Code on GitHub.Coordinators in SwiftUI2020-10-03T00:00:00+00:002020-10-03T00:00:00+00:00https://www.paulweichhart.com/2020/10/03/Coordinators-in-SwiftUI<p>Similar to Massive View Controllers, SwiftUI Views can grow exponentially & have way too much responsibility. Moving any functionality to a separate Layer is a welcoming choice.</p>
<p>The Coordinator Design Pattern aims to solve one part of the problem by moving the presentation related code to a distinct class. It is also one of the most underrated Patterns when it comes to developing iOS Apps. <a href="https://twitter.com/khanlou" target="_blank">Soroush Khanlou</a> wrote an excellent <a href="https://khanlou.com/2015/01/the-coordinator/" target="_blank">article</a> why you should introduce Coordinators in your Application. I tried to map his recommendations in the following example code.</p>
<h2 id="navigating-in-swiftui">Navigating in SwiftUI</h2>
<p>I did some experiments and looked into a couple of different approaches — in the end I chose the following setup:</p>
<ul>
<li>The Coordinator acts as a Factory for creating the Views</li>
<li>I used an <code class="language-plaintext highlighter-rouge">enum</code> for the different destinations (similar to the recommendation in Soroush’s article)</li>
<li>The switch is implemented inside a <code class="language-plaintext highlighter-rouge">View</code> in order to avoid having <code class="language-plaintext highlighter-rouge">AnyView</code> & therefore a decreased Performance</li>
<li>The <code class="language-plaintext highlighter-rouge">View</code> is an inline <code class="language-plaintext highlighter-rouge">struct</code> and not exposing any API</li>
<li>The Coordinator is an <code class="language-plaintext highlighter-rouge">@EnvironmentObject</code> added to the root <code class="language-plaintext highlighter-rouge">View</code> to give Subviews access to it</li>
</ul>
<script src="https://gist.github.com/paulweichhart/0bed2f8e2b7e85f6ea38863b04710a07.js"></script>
<p>The inline <code class="language-plaintext highlighter-rouge">struct</code> can also be replaced with a dedicated <code class="language-plaintext highlighter-rouge">func</code> for each Destination that returns the <code class="language-plaintext highlighter-rouge">View</code>.</p>
<p>In the <code class="language-plaintext highlighter-rouge">View</code> the Coordinator can be called as follows:</p>
<script src="https://gist.github.com/paulweichhart/fde28aa3b57e09e699b559bee34b23b7.js"></script>
<p>I also created a Repository on <a href="https://github.com/paulweichhart/Portfolio">Github</a> to make the code examples more readable. Something you would like to know or wanted to add? Drop me 280 characters on twitter <a href="https://www.twitter.com/paulweichhart" target="_blank">@paulweichhart</a></p>Paul WeichhartSimilar to Massive View Controllers, SwiftUI Views can grow exponentially & have way too much responsibility. Moving any functionality to a separate Layer is a welcoming choice.MVVM with SwiftUI and Combine2020-09-13T00:00:00+00:002020-09-13T00:00:00+00:00https://www.paulweichhart.com/2020/09/13/MVVM-SwiftUI<p>Since I first read about the architectural pattern MVVM in Ash Furrow’s fantastic Book “<a href="https://leanpub.com/iosfrp" target="_blank">Functional Reactive Programming on iOS</a>”, I got struck by the Design.
I really liked the separation of concerns, the promise of small independent layers & the possibility to easily test the ViewModel.
Since then I researched this topic, read several Articles and studied different Repositories how to bring this pattern to iOS (<a href="https://docs.microsoft.com/en-us/archive/msdn-magazine/2009/february/patterns-wpf-apps-with-the-model-view-viewmodel-design-pattern" target="_blank">also by the Inventor and Microsoft Developer Josh Smith</a>).</p>
<p>While you can easily create a <code class="language-plaintext highlighter-rouge">ViewModel</code> & move much of the Views responsibility to a separate level, the binding of each Layer is the key concept of this Architecture. I experimented with a Closure based approach and several Reactive Libraries like ReactiveCocoa, ReactiveSwift & RxSwift in the past, however these Libraries only bring the Concept of “A Stream of values over time” to iOS. Pretty soon you will find yourself introducing several new Libraries that wrap Apple Frameworks — Networking or CoreData for example.
This changed however with the introduction of Combine and SwiftUI at WWDC 2019.</p>
<h2 id="getting-started-with-combine">Getting Started with Combine</h2>
<p>Since its introduction I wanted to write about MVVM and after finishing <a href="https://www.donnywals.com" target="_blank">Donny Wals</a> awesome Book “<a href="https://practicalcombine.com" target="_blank">Practical Combine</a>” I was finally able to create an Example. The App simply fetches & renders a List of 5 Shares. The <code class="language-plaintext highlighter-rouge">Textfield</code> enables searching the List for available Shares.</p>
<p>I tried to implement the following key features:</p>
<ul>
<li>Moving all of the View’s logic & <code class="language-plaintext highlighter-rouge">State</code> into the <code class="language-plaintext highlighter-rouge">ViewModel</code></li>
<li>Avoid using <code class="language-plaintext highlighter-rouge">Never</code> and handle Errors accordingly in the View</li>
<li>Create a separate <code class="language-plaintext highlighter-rouge">NetworkLayer</code> that fetches & decodes the <code class="language-plaintext highlighter-rouge">Model</code></li>
<li>Make small reusable Views</li>
</ul>
<div class="mvvm simulator" alt="Portfolio Example App iOS Simulator"></div>
<h2 id="show-me-the-code">Show me the Code</h2>
<p>The following <a href="https://gist.github.com/paulweichhart/21f4aad6f5741c6013450acac4f4ab0e" target="_blank">Example</a> uses some new features that are currently only available with the Xcode 12 Beta.</p>
<script src="https://gist.github.com/paulweichhart/21f4aad6f5741c6013450acac4f4ab0e.js"></script>
<p>Something to add or like to know? Drop me 280 characters on twitter <a href="https://www.twitter.com/paulweichhart" target="_blank">@paulweichhart</a></p>Paul WeichhartSince I first read about the architectural pattern MVVM in Ash Furrow’s fantastic Book “Functional Reactive Programming on iOS”, I got struck by the Design. I really liked the separation of concerns, the promise of small independent layers & the possibility to easily test the ViewModel. Since then I researched this topic, read several Articles and studied different Repositories how to bring this pattern to iOS (also by the Inventor and Microsoft Developer Josh Smith).Thinking in SwiftUI2020-07-23T00:00:00+00:002020-07-23T00:00:00+00:00https://www.paulweichhart.com/2020/07/23/thinking-in-swiftui<p>As much as I love SwiftUI & the possibilities it provides for Apple Developers, thinking in SwiftUI — especially in the beginning — can be really challenging. If you aren’t used to writing code in a declarative manner, or do a lot of <code class="language-plaintext highlighter-rouge">UIKit</code> & <code class="language-plaintext highlighter-rouge">SwiftUI</code> development at the same time, it can be frustrating.
Luckily Apple provided a very good Session at this years WWDC called <a href="https://developer.apple.com/videos/play/wwdc2020/10040/" target="_blank">Data Essentials in SwiftUI</a>.</p>
<h2 id="where-is-truth">Where is “truth”?</h2>
<p>Not only does it explain the basic concept of data flow in SwiftUI, it also teaches one important lesson you should ask yourself while writing code:</p>
<blockquote>
<p><strong>Where is “truth”?</strong></p>
</blockquote>
<p>If you haven’t had the chance to watch it yet, I can highly recommend it for every Developer getting started in SwiftUI as well as seasoned SwiftUI people.</p>
<p>Apple also introduced a new <a href="https://developer.apple.com/documentation/swiftui/state-and-data-flow" target="_blank">State and Data Flow Guide</a>. The Documentation gives more insights & examples for the existing & also new Property Wrappers <code class="language-plaintext highlighter-rouge">State</code>, <code class="language-plaintext highlighter-rouge">ObservedObject</code>, <code class="language-plaintext highlighter-rouge">ObservableObject</code> & <code class="language-plaintext highlighter-rouge">StateObject</code>.</p>
<h2 id="memory-lane-wwdc-2014">Memory lane WWDC 2014</h2>
<p>Alongside the Data Essentials Session, I can also highly recommend a Talk by former Apple Engineer <a href="https://twitter.com/andy_matuschak" target="_blank">Andy Matuschak</a> called <a href="http://devstreaming.apple.com/videos/wwdc/2014/229xx77tq0pmkwo/229/229_hd_advanced_ios_architecture_and_patterns.mov?dl=1" target="_blank">Advanced iOS Application Architecture and Patterns</a> from WWDC 14.</p>Paul WeichhartAs much as I love SwiftUI & the possibilities it provides for Apple Developers, thinking in SwiftUI — especially in the beginning — can be really challenging. If you aren’t used to writing code in a declarative manner, or do a lot of UIKit & SwiftUI development at the same time, it can be frustrating. Luckily Apple provided a very good Session at this years WWDC called Data Essentials in SwiftUI.High performance SwiftUI2019-06-22T00:00:00+00:002019-06-22T00:00:00+00:00https://www.paulweichhart.com/2019/06/22/High-performance-SwiftUI<p>After trying SwiftUI & looking through tutorials from <a href="https://developer.apple.com/tutorials/swiftui" target="_blank">Apple</a>, <a href="https://www.hackingwithswift.com/quick-start/swiftui/" target="_blank">Paul Hudson</a> & others, I have to say I couldn’t be more excited.
I was able to work with React during the last two years & seeing this library being sherlocked with first party support from Apple is truly amazing. SwiftUI is not only more expressive, easier to write and maintain, it also works seamlessly with Apple’s own Combine framework.</p>
<h2 id="the-case-for-react-native">The case for React (Native)</h2>
<p><a href="https://ashfurrow.com/blog/the-case-for-react-native/" target="_blank">Ash Furrow</a> wrote some time ago why React (Native) is awesome — you shouldn’t use it because of the multi platform support, but because it handles state so elegant. Like Ash, I would advise everyone to read through the <a href="https://reactjs.org/tutorial/tutorial.html" target="_blank">React Tutorial</a> & especially through <a href="https://reactjs.org/docs/thinking-in-react.html" target="_blank">Thinking in React</a> — it teaches the fundamentals on how to write reusable components and applications. Basically everything can & should be a component (or View in SwiftUI).</p>
<h2 id="applying-everything-to-swiftui">Applying everything to SwiftUI</h2>
<p>By reading through various SwiftUI tutorial however, most demonstrated to put the whole UI into a single <code class="language-plaintext highlighter-rouge">View</code>. Knowing that React only re–renders components whose <code class="language-plaintext highlighter-rouge">state</code> or <code class="language-plaintext highlighter-rouge">props</code> (equivalent of properties in SwiftUI) changed, I was curious to see if SwiftUI handles changes the same way. Here is a playground Gist to provide a proof of concept.</p>
<script src="https://gist.github.com/paulweichhart/e0288e1ca482018820054385e2d90046.js"></script>
<p>Looking at the code it makes sense that <code class="language-plaintext highlighter-rouge">View</code>s themselves are re–rendered if their state or properties changed, since they are represented as <code class="language-plaintext highlighter-rouge">struct</code>s. But nothing stops us from extracting Subviews into distinct, reusable <code class="language-plaintext highlighter-rouge">View</code>s, that are only re–rendered in case of changes.</p>
<p>While it is more convenient & reduces the amount of boilerplate code to place every Subview into a single hierarchy, I wouldn’t advise to do so. While re–rendering isn’t expensive for Text, it could be for having a Map View for example.</p>
<h2 id="the-future-is-reactive">The future is reactive</h2>
<p>The concept of React and therefore SwiftUI is easy to understand & learn. <del>While SwiftUI is still in Beta as of my writing, it already features a full set of tools & works really well.</del> (I’ve updated the gist to work with Xcode 11.1). I’m really looking forward to use SwiftUI & Combine in the future.</p>
<p>Something to add or say? Drop me some characters on twitter <a href="https://twitter.com/paulweichhart/" target="_blank">@paulweichhart</a></p>Paul WeichhartAfter trying SwiftUI & looking through tutorials from Apple, Paul Hudson & others, I have to say I couldn’t be more excited. I was able to work with React during the last two years & seeing this library being sherlocked with first party support from Apple is truly amazing. SwiftUI is not only more expressive, easier to write and maintain, it also works seamlessly with Apple’s own Combine framework.Programming in Swift2018-06-23T00:00:00+00:002018-06-23T00:00:00+00:00https://www.paulweichhart.com/2018/06/23/Programming-in-Swift<p>This article doesn‘t aim to teach any [new, shiny, fancy] things about Apple’s Swift programming language — instead it’s a short recap of my journey of programming in Swift so far.</p>
<h2 id="how-it-all-started">How it all started</h2>
<p>I started learning Objective-C in my spare time some years ago. Back when I had the chance to play with the iPhone 3G for the first time, I instantly wanted to write apps for this new device. So I bought several books on iOS development, took the Stanford iOS course & worked through the chapters. However, Objective-C never really grew on me. Working with strings, for example, seemed unnecessary complex compared to other languages (it still is with Swift, but for a good reason). Using pointers for objects also showed the age of the language.</p>
<h2 id="functional-programming">Functional programming</h2>
<p>But things changed for good with the release of Swift. The language features some really great functionalities like tuples, generics & optionals — already known & loved from other programming languages.
However, one thing didn’t catch my attention during the presentation of Chris Lattner: Swift is not only a object oriented but also a functional programming language.
The awesome people at objc.io, for example, immediately jump shipped Objective-C and showcased what was possible and released <a href="https://www.objc.io/blog/archive/" target="_blank">functional swift snippets</a> & even released an entire book called „<a href="https://www.objc.io/books/functional-swift/" target="_blank">Functional Swift</a>“ covering the basics of functional programming in Swift.</p>
<h2 id="applying-functional-concepts">Applying functional concepts</h2>
<p>My journey started by using more & more <code class="language-plaintext highlighter-rouge">lets</code> instead of <code class="language-plaintext highlighter-rouge">vars</code> (Xcode also encourages you to do this). I also tried to write smaller more concise functions & reuse or combine them.
The next step involved applying higher order functions in my code base. It took quite some time to feel comfortable but they are now spread all over my files. This <a href="http://reactivex.io/learnrx/" target="_blank">interactive Playground</a> really helped a lot grasping the benefits of using them.
Currently I try to avoid global declarations & do my best to adopt to the new challenge of organizing my classes with way more functions.</p>
<h2 id="book--video-recommendations">Book & Video Recommendations</h2>
<p>If you, like me, didn‘t have the chance to learn this programming paradigm, I can‘t recommend the book „Functional Swift“ enough. It introduces the reader to concepts and methodologies known from other languages. Another helpful resource for learning functional programming is picking up a new language like Haskell or Closure. I also started reading „Learn a Haskell for great good“ & learned quite a lot. It teaches the basics of functional programming very well and encourages the reader to try new approaches for solving problems.</p>
<p>There is also a Video series called „<a href="https://www.pointfree.co/" target="_blank">Point Free</a>“ teaching the fundamentals of functional programming in Swift.
<a href="https://twitter.com/mbrandonw" target="_blank">Brandon Williams</a> & <a href="https://twitter.com/stephencelis" target="_blank">Stephen Celis</a> really do an awesome job explaining the fundamentals & mathematical concepts behind functional programming.</p>
<p>Another great book I’m currently reading is called „<a href="https://github.com/MostlyAdequate/mostly-adequate-guide" target="_blank">Professor Frisby’s mostly adequate guide to functional programming</a>“ which is available for free on Github.</p>
<h2 id="wishlist">Wishlist</h2>
<p>While it is great that Swift enables us to use functional programming, however due to the Objective-C legacy, object oriented programming is still the way to go when programming for iOS. Many frameworks like Core Data aren’t capable of using it through the whole codebase.
But I can’t wait for new language features introduced in the near future!</p>Paul WeichhartThis article doesn‘t aim to teach any [new, shiny, fancy] things about Apple’s Swift programming language — instead it’s a short recap of my journey of programming in Swift so far.Doo — Wop That Thing2017-07-21T00:00:00+00:002017-07-21T00:00:00+00:00https://www.paulweichhart.com/2017/07/21/the-education-of-paul-weichhart<p>After reading Jeffrey Zeldman’s fantastic post „<a href="https://alistapart.com/column/the-love-you-make" target="_blank">The love you make</a>“, I wanted to spend more time on writing again. I shared my thoughts — mostly about music & photography — many years before, but lost the interest after all. Now I wanted to give it another shot. However, this time it’s all about digital adventures.
After weighting the benefits & downsides of hosting my own blog on Github via Jekyll, getting a Ghost Blog, setting up a WordPress Blog or publishing on Medium, <del>I picked the latter. I’m a huge fan of this platform & spend several hours each week reading articles on this site or the companion iOS App. Furthermore, everybody was raving about the great experience of publishing on here.</del> I chose Jekyll (for good this time).</p>
<h2 id="write-like-nobody-is-reading">Write like nobody is reading</h2>
<p>I find it very difficult to write. First, english isn’t my first language & second, I’m a really uncertain at choosing words & getting the grammar right. It takes me quite long to get Emails (even in my mother tongue), tweets or messages ready & out. So I hope this will improve over time. Another great benefit I hope to get of this endeavor of writing & publishing my thoughts & experience, is the resulting documentation of my own progress.
So, what’s this all about? I narrowed the topics, I want to write about, down to lessons learned, current adventures & things I enjoy. I’m trying to write & publish articles about design & development on a regular basis — stuff like Photoshop, Web & iOS development, great books, helpful tools & so on…</p>
<p>Something to add or say? Drop me 140 characters on twitter <a href="https://www.twitter.com/paulweichhart" target="_blank">@paulweichhart</a></p>Paul WeichhartAfter reading Jeffrey Zeldman’s fantastic post „The love you make“, I wanted to spend more time on writing again. I shared my thoughts — mostly about music & photography — many years before, but lost the interest after all. Now I wanted to give it another shot. However, this time it’s all about digital adventures. After weighting the benefits & downsides of hosting my own blog on Github via Jekyll, getting a Ghost Blog, setting up a WordPress Blog or publishing on Medium, I picked the latter. I’m a huge fan of this platform & spend several hours each week reading articles on this site or the companion iOS App. Furthermore, everybody was raving about the great experience of publishing on here. I chose Jekyll (for good this time).