<?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 Daniel Tavares on Medium]]></title>
        <description><![CDATA[Stories by Daniel Tavares on Medium]]></description>
        <link>https://medium.com/@DanielTavares?source=rss-39c24fbc5bff------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*I8uz8WIsL_GfzCrD.jpg</url>
            <title>Stories by Daniel Tavares on Medium</title>
            <link>https://medium.com/@DanielTavares?source=rss-39c24fbc5bff------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 20:52:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@DanielTavares/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[Quickly open selected text in Xcode Playground for rapid development (Mac OS)]]></title>
            <link>https://medium.com/@DanielTavares/quickly-open-selected-text-in-xcode-playground-for-rapid-development-mac-os-56cd07030ef9?source=rss-39c24fbc5bff------2</link>
            <guid isPermaLink="false">https://medium.com/p/56cd07030ef9</guid>
            <category><![CDATA[development]]></category>
            <category><![CDATA[swift-programming]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[playground]]></category>
            <category><![CDATA[rapid-development]]></category>
            <dc:creator><![CDATA[Daniel Tavares]]></dc:creator>
            <pubDate>Thu, 24 Oct 2019 11:19:55 GMT</pubDate>
            <atom:updated>2019-10-24T11:19:55.692Z</atom:updated>
            <content:encoded><![CDATA[<h3>Quickly open any selected text in Xcode Playground for rapid swift development (Mac OS)</h3><p>The other day I was reviewing a PR from a colleague and I was wondering if the code could be optimised/improved.</p><p>The usual step I take is</p><ol><li>Open playground</li><li>Copy+Paste code</li><li>Start coding</li></ol><p>So I thought of automating this a little to help speed up the process of quickly trying out some code.</p><p><strong>Tools used</strong></p><p><strong><em>Playground</em></strong></p><p><a href="https://github.com/JohnSundell/Playground">JohnSundell/Playground</a></p><p><strong><em>Automator</em></strong></p><p><a href="https://developer.apple.com/library/archive/documentation/LanguagesUtilities/Conceptual/MacAutomationScriptingGuide/MakeaSystem-WideService.html">Making a Systemwide Service</a></p><p><strong>How to</strong></p><ol><li>Install Playground</li></ol><pre>$ git clone https://github.com/JohnSundell/Playground.git<br>$ cd Playground<br>$ mv Sources/Playground.swift Sources/main.swift<br>$ swift build -c release<br>$ cp -f .build/release/Playground /usr/local/bin/playground</pre><p>2. Setup work flow in Automator</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EKXSddxv9go_Y4eV3qeCVQ.png" /></figure><p>3. Create a new Keyboard Shortcut</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xewh06YIOlhSTvQUi91lWg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qM8EV6bLrTJ-UsWqEE0QtA.png" /></figure><p>4. Enjoy!</p><p><strong>Behind the scenes</strong></p><blockquote>Playground allows you to run `playground -c` from the command line which takes code from the pasteboard and open a new playground.</blockquote><p><strong>See it in action</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tE9rlwmLj--tj0I31L7Mlw.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=56cd07030ef9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Useful Swift Optional Extension]]></title>
            <link>https://medium.com/@DanielTavares/useful-swift-optional-extension-dc6d5e985bb4?source=rss-39c24fbc5bff------2</link>
            <guid isPermaLink="false">https://medium.com/p/dc6d5e985bb4</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[iphone-app-development]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Daniel Tavares]]></dc:creator>
            <pubDate>Tue, 28 Jun 2016 22:55:02 GMT</pubDate>
            <atom:updated>2016-06-28T22:55:02.680Z</atom:updated>
            <content:encoded><![CDATA[<p>Let’s say you have an optional array that contains user preference items. For simplicity lets just assume they are strings.</p><pre>var preferences: [String]?</pre><p>When ever you want to check if we have anything in that array you would do:</p><pre>/// Version 1<br>if let userPreferences = preferences where !userPreferences.isEmpty {<br>    print(&quot;Do something with preferences&quot;)<br>}</pre><p>You first unwrap that array and check if it’s not empty, then the print can be called.</p><pre>/// Version 2<br>let isEmpty = preferences?.isEmpty ?? true<br>if !isEmpty {<br>    print(&quot;Do something with preferences&quot;)<br>}</pre><p>Or you could do the above, it’s a matter of preference.</p><p>One thing that you start to notice is that you have to either unwrap the array first and then check for isEmpty or start adding default values in case the array is nil.</p><p>Because of all of those verbose checks I decided to write an extension on Optional to do that check for us.</p><p>Swift optional is just an enum so It can be easily extended. (Great article for <a href="https://www.objc.io/issues/16-swift/power-of-swift/">some more info https://www.objc.io/issues/16-swift/power-of-swift/)</a></p><p>If you look at the Optional declaration you will notice that it was a Generic value called Wrapped which is an associated value for the case Some(Wrapped)</p><pre>/// A type that can represent either a `Wrapped` value or `nil`, the absence<br>/// of a value.<br>public enum Optional&lt;Wrapped&gt; : _Reflectable, NilLiteralConvertible {<br>    case None<br>    case Some(Wrapped)<br>    /// Construct a `nil` instance.<br>    public init()<br>    /// Construct a non-`nil` instance that stores `some`.<br>    public init(_ some: Wrapped)<br>    /// If `self == nil`, returns `nil`.  Otherwise, returns `f(self!)`.<br>    @warn_unused_result<br>    public func map&lt;U&gt;(@noescape f: (Wrapped) throws -&gt; U) rethrows -&gt; U?<br>    /// Returns `nil` if `self` is `nil`, `f(self!)` otherwise.<br>    @warn_unused_result<br>    public func flatMap&lt;U&gt;(@noescape f: (Wrapped) throws -&gt; U?) rethrows -&gt; U?<br>    /// Create an instance initialized with `nil`.<br>    public init(nilLiteral: ())<br>}</pre><p>With that knowledge in mind we can create an extension and constrain Wrapped to a specific type. The type we are looking for is CollectionType</p><pre>extension Optional where Wrapped: CollectionType</pre><p>This allows us to call all methods that CollectionType provides (.isEmpty), inside our extension. Full implementation below</p><pre>extension Optional where Wrapped: CollectionType {<br>    func nilOrEmptyCollection() -&gt; Bool {<br>        guard let value = self else { return true }<br>        return value.isEmpty<br>    }<br><br>    func hasElements() -&gt; Bool {<br>        return !nilOrEmptyCollection()<br>    }<br>}</pre><p>Now we can easily do this and save us alot of typing:</p><pre>if preferences.hasElements() {<br>    print(&quot;Do whatever here....&quot;)<br>}</pre><p>Please note that we are not calling any methods on the array as you will need to unwrap it first. This is simply an easier way to check if it has elements and it’s not nil</p><p>Hopefully someone finds this useful. Full gist below</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1e7fa7d83284dc1664e500fd59155ee3/href">https://medium.com/media/1e7fa7d83284dc1664e500fd59155ee3/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dc6d5e985bb4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Apple Watch ⌚ / WatchKit / UI Elements / Features / Cheat sheet]]></title>
            <link>https://medium.com/watchkit-programming/apple-watch-watchkit-ui-elements-features-cheat-sheet-74ead66467b4?source=rss-39c24fbc5bff------2</link>
            <guid isPermaLink="false">https://medium.com/p/74ead66467b4</guid>
            <dc:creator><![CDATA[Daniel Tavares]]></dc:creator>
            <pubDate>Tue, 09 Dec 2014 11:30:21 GMT</pubDate>
            <atom:updated>2015-07-01T06:45:37.324Z</atom:updated>
            <content:encoded><![CDATA[<p>For the past week I have been looking at the <a href="https://developer.apple.com/watchkit/">WatchKit SDK</a> released by Apple.</p><p>My aim was to find out all the limitations and have a look at what can be achieved with this new/young API.</p><p>I was very surprised to find out that not a lot was <em>exposed</em> to the developers and It feels like we regressed quite a lot in terms of programming.</p><blockquote><strong>There are no getters and the extension should keep track of the state change of its elements</strong></blockquote><p>The root class is WKIterfaceObject and the only properties you can change is <strong><em>Hidden / Alpha / Width / Height</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/910/1*T6ktTDjOUU7xtUSPpK5UCg.png" /></figure><blockquote><strong>You cannot create any elements dynamically!</strong></blockquote><p>The most useful object is <strong><em>WKInterfaceGroup</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*clj4_kxNnSeq1cS1HSmNKw.png" /><figcaption>WKInterfaceGroup</figcaption></figure><p>You can add UI Elements inside the group and set the layout to be either Horizontal or Vertical.</p><blockquote><strong><em>There are no overlaps between elements (e.g. You cannot add a label on top of an image)</em></strong></blockquote><blockquote><strong>Everything has to be created Up-Front in a storyboard</strong></blockquote><p>Some elements have background images. <strong>WKInterfaceGroup</strong>, <strong>WKInterfaceButton</strong>, <strong>WKInterfaceController</strong> all have background images.</p><p>The Apple Watch relies heavily on animated <strong>UIImages</strong> to simulate animations. James Frost created a library on github that generates images from UIViews.</p><p><a href="https://github.com/frosty/Flipbook">frosty/Flipbook</a></p><p>I’ve recently converted the code into Objective-C if anyone is interested.</p><p><a href="https://github.com/vibrazy/FlipbookObj-C">vibrazy/FlipbookObj-C</a></p><p>Below is what I’ve compiled so far about WatchKit, I’ve taken screenshots from the WatchKit catalog / Storyboard / Interface of each Element. I hope this is useful to developers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*asQeXATBOvMKcP1AlXvmOw.png" /><figcaption>WatchKit Cheat Sheet</figcaption></figure><p>I would suggest to all developers to sit down with designers and start creating mockups for existing client apps. That way you can start educating designers of what you can/cannot do with Apple Watch. It’s a very useful exercise that will benefit any company.</p><p>Thank you all!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=74ead66467b4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/watchkit-programming/apple-watch-watchkit-ui-elements-features-cheat-sheet-74ead66467b4">Apple Watch ⌚ / WatchKit / UI Elements / Features / Cheat sheet</a> was originally published in <a href="https://medium.com/watchkit-programming">WatchKit Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>