<?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 Glen Yi on Medium]]></title>
        <description><![CDATA[Stories by Glen Yi on Medium]]></description>
        <link>https://medium.com/@glenyi?source=rss-f0aea0a8ec8e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*K0VLgBEUA_DLcLIr.jpeg</url>
            <title>Stories by Glen Yi on Medium</title>
            <link>https://medium.com/@glenyi?source=rss-f0aea0a8ec8e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 21:31:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@glenyi/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[How Remote Working Makes Startups Better]]></title>
            <link>https://medium.com/@glenyi/how-remote-working-makes-startups-better-242edfce35b9?source=rss-f0aea0a8ec8e------2</link>
            <guid isPermaLink="false">https://medium.com/p/242edfce35b9</guid>
            <category><![CDATA[startup]]></category>
            <category><![CDATA[remote-working]]></category>
            <category><![CDATA[digital-nomads]]></category>
            <dc:creator><![CDATA[Glen Yi]]></dc:creator>
            <pubDate>Tue, 10 Mar 2015 13:53:09 GMT</pubDate>
            <atom:updated>2015-09-29T14:25:56.350Z</atom:updated>
            <content:encoded><![CDATA[<p>Lessons learned from one month as a digital nomad</p><p>There’s a term that gets thrown around a lot lately that made me cringe a little every time I heard it. “Digital nomad”… <strong><em>shudder</em></strong>… But it has grown on me since and the concept even more so.</p><p>Now more than ever it’s easier to just pack your bags and choose a destination to work. <a href="http://www.entrepreneur.com/article/241761">Building a product while living in cities such as San Francisco, Seattle, New York or Toronto</a> is expensive and most of all, unnecessary. There are a wealth of products out there that make it easier than ever for the modern entrepreneur to build their dreams from anywhere in the world.</p><p>But what about startups? What if you’re building a dream together as a team? Members can’t just pack-up and work in a foreign country leaving everything behind, can they?</p><h3>#DigitalNomad</h3><p>This is exactly what my coworker <a href="https://twitter.com/duelist">Ian</a> and I decided to do for a month in Chiang Mai, and it was one of the greatest work experiences of my life. At <a href="https://tabpayments.co/">Tab Payments</a> we don’t have an official work policy <em>per se</em>, and it wasn’t without some justified reservations, but it made us all better in the end.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8Fn14G5OM7gAINz5RxS3sA.jpeg" /><figcaption>Doi Suthep, Chiang Mai, Thailand</figcaption></figure><h3>What We Gained</h3><h4>Improved communication</h4><p>Because we couldn’t just start a conversation with the person across the desk, it created the need for different processes. Having part of the team on a different continent forced us to use our communication tools to the fullest. Whether it was posting a link in Slack, creating a task in Asana or liking a comment in Quip, our communication flow became more streamlined and transparent. It may seem counterintuitive, but having periods of remote working can open the lines of communication.</p><h4>Distraction free time</h4><p>This is important for any role but it’s <a href="http://thetomorrowlab.com/2015/01/why-developers-hate-being-interrupted/">particularly important for developers</a>. While in Chiang Mai, I’ve had days with 6 hours straight uninterrupted development time. It felt more productive and more than I would accomplish in 8–10 hours in the office. Other days it was 2–3 hours at one co-space before hopping over to a coffee shop down the road for a change of scenery. It was refreshing and allowed us to work at our own pace, uninterrupted.</p><h4>Timezones</h4><p>People will use your product in different ways and at different times. Having employees spread out among several timezones is a benefit when problems arise. This is particularly helpful if you have an international product and customer service is a big focus of your startup (as it should always be). Admittedly, we only have 2 developers and both of us were in Chiang Mai, so any technical issues on off times could have been difficult to deal with… But luckily nothing major came up during our stay. I still see this as an advantage for most startups out there though. ;)</p><h4>Stimulation</h4><p>This last point is invaluable both to a startup and the individual. I worked in Korea for 5 years then came back to Toronto in 2012. Since coming back, working on my own startup and then joining Tab, I realized I had never taken a real vacation! I’ve gone away on road trips and weekend getaways, but I really needed to get away for a while. The result was that I was more relaxed, productive and creative than I’ve felt in a long while. My list of ideas and backlog of things to learn grew rapidly over the month and I couldn’t be any happier about it.</p><h3>Our Tools</h3><p>Of course, keeping everybody synced up would be rough without the right tools. Here’s some of the major ones we use at Tab and how they help us work better.</p><h4><a href="https://slack.com/">Slack</a></h4><p>The hub through which all our communication flows. And I do mean everything. I’ve loved Slack from the start and it’s a product that’s gotten better and better since launching. Whether it be for private 1 on 1 chats or a little team debate on product features, it’s the best tool out there for team chat. That’s not even getting into the <a href="https://slack.com/integrations">extensive integrations</a> Slack has with other products. While working overseas I would go to Slack first thing in the mornings to see what’s going on in Tab.</p><h4><a href="https://asana.com/">Asana</a></h4><p>Keeps everyone informed and on the same track. I follow all the projects that are relevant to me or I’m interested in so that I can wakeup and check my Asana inbox to see what’s going on. New restaurant signups, internal dashboard requests or even fundraising progress. Asana can be more than just a project management tool and bring higher levels of transparency. I found myself ‘liking’ tasks and comments much more frequently than before to let everybody know that I dig what I see!</p><h4><a href="https://quip.com/">Quip</a></h4><p>I’ll admit, I wasn’t sold on Quip at first. I thought it had a slick mobile interface with great notification and commenting tools. The problem for me was we already used Dropbox for storage and Google Drive for a variety of docs and spreadsheets. I argued that keeping documents consolidated into one place was simpler and hence better. My thoughts changed however once we were working remotely and the immense value of Quip came to light.</p><p>While Slack allows us real-time communication and Asana keeps us organized, Quip makes collaboration a breeze. I can see how our sales playbook is evolving, comment on product requirements and ‘like’ what other people have said. Just as in Asana, a ‘like’ provides strong feedback with the click of a button.</p><h4>Notable Mentions</h4><ul><li><a href="http://www.invisionapp.com/">Invision</a>. We’re very product and design driven. More opportunity for comments and likes.</li><li><a href="https://github.com/">Github</a>. We try to keep our <a href="http://xkcd.com/1296/">commits descriptive</a>. Integrates nicely with Slack.</li><li><a href="https://heroku.com/">Heroku</a>, <a href="https://papertrailapp.com/">Papertrails</a> and <a href="https://fabric.io/">Fabric/Crashlytics</a>. Integrations with Slack let us know when things go wrong.</li><li><a href="https://mixpanel.com/">Mixpanel</a>. While it’s not for communication, they do have good mobile tools so that I could schedule push notifications to our users in EST.</li></ul><h3>The Downsides</h3><p>Yes, remote working is not without its drawbacks.</p><h4>Product planning and strategy</h4><p>At 5 people, Tab is a small team even for a startup. Our long term product roadmap is constantly changing and needs frequent updating. This is the nature of an early stage startup and requires constant communication with the entire team. Working remotely in different timezones makes it tough to keep everyone on the same page but is not impossible. Steer everyone at all times towards that <a href="http://firstround.com/review/heres-the-advice-i-give-all-of-our-first-time-founders/">north star</a>.</p><h4>Team building</h4><p>One of the intangibles. Do anything fun on the weekend? What did you think of Birdman? Where should we go out for lunch? Let’s go out for a drink! A team that eats together stays together afterall. Yes we communicated daily through chat and calls, but it’s not quite the same. It’s why even a 100% remote company like <a href="https://open.bufferapp.com/go-international-retreats-3-times-year/">Buffer has company retreats 3 times a year.</a></p><h4>Serendipity</h4><p>Another hard one to measure but cannot be underestimated. This was highlighted in Eric Schmidt and Jonathan Rosenberg’s book <a href="http://www.amazon.com/How-Google-Works-Eric-Schmidt-ebook/dp/B00HUU13Y0/">“How Google Works”</a> when they claim that one of the ways to build a successful company is to “<a href="http://www.slideshare.net/ericschmidt/how-google-works-final-1/27">foster serendipitous conversations</a>”. Design your work space so that there are as many interactions between employees as possible to just start random conversations. Innovative ideas can strike at anytime from these crossings which is extremely difficult (impossible?) to replicate with a distributed team.</p><p>Downside… not wanting to go back home.</p><h3>How to start?</h3><p>Talk with the team and make sure everybody sees the benefits. Set guidelines on how you’ll keep the lines of communication open and clear. Chat with your team often and hop on calls whenever needed because miscommunications can quickly cause rifts and set backs.</p><p>To know more about remote working, read about <a href="http://joel.is/the-joys-and-benefits-of-working-as-a-distributed-team/">Buffer’s distributed team culture</a>. Not many have built a startup with remote working from the ground up and there’s nobody else doing it quite as right.</p><p>In the end, I’d suggest either throwing darts at a map or head on over to <a href="https://nomadlist.com/">Nomad List</a> and pick a spot. The world awaits.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=242edfce35b9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CoCo Love]]></title>
            <link>https://medium.com/ios-os-x-development/coco-love-f6cd5a30f63e?source=rss-f0aea0a8ec8e------2</link>
            <guid isPermaLink="false">https://medium.com/p/f6cd5a30f63e</guid>
            <dc:creator><![CDATA[Glen Yi]]></dc:creator>
            <pubDate>Tue, 30 Dec 2014 17:05:13 GMT</pubDate>
            <atom:updated>2015-01-05T19:21:57.116Z</atom:updated>
            <content:encoded><![CDATA[<p>Building the “hit” app in Swift. CAEmitterLayer, CAEmitterCell and lazy stored properties.</p><p>If you don’t know what CoCo is all about, check out <a href="http://mashable.com/2014/12/09/nba-warriors-coco/">this article on Mashable</a>. After learning about the Golden State Warrior videos and the <a href="https://www.youtube.com/watch?v=6vYnas6q3Sg">song’s not so subtle innuendos</a>, the inspiration to <a href="https://itunes.apple.com/app/coco-love/id949291854">CoCo Love</a> was born!</p><h3>#ImInLoveWithTheCoCo</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/375/1*IMI_5O9alxV0iMRFzE7P5g.gif" /><figcaption><a href="https://itunes.apple.com/app/coco-love/id949291854">CoCo Love available now on iTunes ☺</a></figcaption></figure><p>Yup, this is it. What’s missing in the gif is that when you open the app or click the snowflake, it plays the CoCo chorus on loop. When you click the baking soda button, well… you can probably guess by now if you know the song.</p><p>As simple as the app is, there’s a couple of cool things going on here. Mainly the implementation for the snowflakes (pro tip: click the snowflake button 5 times to unlock this) and a couple of Swift tricks.</p><h3>Making It Snow</h3><p>The snow effect was <strong><em>vital</em></strong> to making CoCo Love work, so after doing some research I found out that it’s quite simple to implement using 2 classes; <a href="https://developer.apple.com/library/ios/documentation/GraphicsImaging/Reference/CAEmitterLayer_class/index.html">CAEmitterLayer</a> and <a href="https://developer.apple.com/library/mac/documentation/GraphicsImaging/Reference/CAEmitterCell_class/index.html">CAEmitterCell</a>. The CAEmitterLayer class provides a “particle emitter system for Core Animation”. The particles themselves are defined by CAEmitterCell and both classes are highly customizable. First let’s look at the cell.</p><pre>lazy var snowCell: CAEmitterCell = {<br>    let snowCell = CAEmitterCell()<br>    snowCell.contents = UIImage(named: “snowflake”)?.CGImage       <br>    snowCell.scale = 0.06<br>    snowCell.scaleRange = 0.03<br>    snowCell.emissionRange = CGFloat(M_PI_2)<br>    snowCell.lifetime = 20.0<br>    snowCell.birthRate = 15<br>    snowCell.velocity = -30<br>    snowCell.velocityRange = -20<br>    snowCell.yAcceleration = 10<br>    snowCell.spin = -0.5<br>    snowCell.spinRange = 1.0<br>   <br>    return snowCell<br>}()</pre><p>There’s quite a lot of attributes here, most of which are self explanatory. First you set the <em>contents</em> to an image. In this case a snowflake. The original snowflake image is too large, so you can adjust the size with the <em>scale</em> property. Of course things would look too uniform if every snowflake looked and behaved exactly the same, so luckily most of the attributes have a companion <em>range</em> property that specifies the amount the attribute can vary over its lifetime. You can see these being set above with <em>scaleRange</em>, <em>emissionRange</em>, <em>velocityRange</em> and <em>spinRange</em>.</p><p>The <em>emissionRange</em> property defines the angle of a cone in which cells are emitted from the layer. If it’s left at the default value of zero, then the snowflakes would drop straight down without any horizontal variance.</p><p>The <em>lifetime</em> attribute is set to a value high enough in seconds so that the cells don’t disappear while on screen. Finally, <em>birthrate</em> is the spawn rate for the particles defined by cells per second.</p><p>CAEmitterCell does nothing on its own so next we declare and initialize the CAEmitterLayer class.</p><pre>lazy var snowLayer: CAEmitterLayer = {<br>    let snowLayer = CAEmitterLayer()<br>    snowLayer.emitterPosition =<br>            CGPointMake(self.view.bounds.width/2.0, 0)<br>    snowLayer.emitterSize =<br>            CGSizeMake(self.view.bounds.width, 0)<br>    snowLayer.emitterShape = kCAEmitterLayerLine<br>    snowLayer.beginTime = CACurrentMediaTime()<br>    snowLayer.emitterCells = [self.snowCell]<br><br>    return snowLayer<br>}()</pre><p>Pretty straight forward. We create the layer, centre it at the top of the view and set it to the full width of the view controller. There are different shapes the layer can be set as to emit particles using <em>emitterShape</em>, but in this case we just want a simple line for snowflakes to fall from.</p><p>The <em>beginTime</em> attribute might not seem like it’s needed at first but the particle system won’t work quite as expected if you don’t set it to <em>CACurrentMediaTime()</em>. I’ll leave it up to readers to experiment with and find out why. ☺</p><p>Finally before adding the layer to the view we add the <em>snowCell</em> defined earlier to the <em>emitterCells</em> property. Then all we need is the following to make it snow!</p><pre>self.view.layer.addSublayer(self.snowLayer)</pre><p>One thing to mention is that the <em>emitterCells</em> property is an array, so you can add multiple cells all with their own customizations. It’s worth experimenting here to try adding multiple cells with different attributes to get some fun effects.</p><h3><a href="https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Properties.html#//apple_ref/doc/uid/TP40014097-CH14-XID_381">Lazy Stored Properties</a></h3><p>You may have noticed the <em>lazy</em> modifier before the <em>snowCell</em> and <em>snowLayer</em> declarations above. This is a great convenience feature in Swift which initializes the property only when needed. This is simpler to implement than the <a href="http://stackoverflow.com/questions/9119042/why-does-apple-recommend-to-use-dispatch-once-for-implementing-the-singleton-pat">objective-c equivalent</a> which is to use <em>dispatch_once </em>with a static <em>dispatch_once_t</em> predicate.</p><p>Using the <em>lazy</em> modifier here is easy to use and slightly more efficient than without because it initializes the variable only when needed (i.e. when the user clicks the snowflake button 5 times). I personally feel like it makes for cleaner code as well, because all the cell and layer attributes can be set at the top of the view controller along with other property declarations instead of deeper down in the view controller in some event triggered function. This is completely a matter of preference though and <a href="https://twitter.com/glenyi">I’d be interested to hear what other people think</a>.</p><p>It’s also worth noting that you can call <em>self</em> when initializing lazy properties. Normally this isn’t the case because the view controller hasn’t finished initializing yet while properties are being initialized. With <em>lazy</em> properties however, everything is already set and it’s safe to call <em>self</em> in the block. You can read more about initializations from <a href="https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Initialization.html">Apple’s Swift docs</a>.</p><h3>Wrap Up</h3><p>Completing CoCo Love is not hard from here. All that’s needed are some not-so-fancy animations and <a href="https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVAudioPlayerClassReference/index.html">AVAudioPlayer</a> to play the music clips. I did try to make the code as clean and compact as possible, so helper functions are used for all repeated tasks. Here’s all that needs implementing beyond a couple of @IBAction outlets for the buttons:</p><pre>func flashBackground()<br>func startPlayer(player: AVAudioPlayer) <br>func stopPlayer(player:AVAudioPlayer) <br>func animateScale(view: UIView, duration: NSTimeInterval) <br>func removeScale(view: UIView) <br>func makeItSnow() // Add the snowLayer</pre><p>And there you have it. Everything behind making the hit app <a href="https://itunes.apple.com/app/coco-love/id949291854">CoCo Love</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f6cd5a30f63e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ios-os-x-development/coco-love-f6cd5a30f63e">CoCo Love</a> was originally published in <a href="https://medium.com/ios-os-x-development">iOS App Development</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[To blur or not to blur?]]></title>
            <link>https://medium.com/ios-os-x-development/to-blur-or-not-to-blur-bba243ea8d72?source=rss-f0aea0a8ec8e------2</link>
            <guid isPermaLink="false">https://medium.com/p/bba243ea8d72</guid>
            <category><![CDATA[design]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[blur]]></category>
            <dc:creator><![CDATA[Glen Yi]]></dc:creator>
            <pubDate>Thu, 23 Oct 2014 16:43:56 GMT</pubDate>
            <atom:updated>2015-03-03T23:15:01.809Z</atom:updated>
            <content:encoded><![CDATA[<p>A lesson learned on mobile app design. It’s all about context.</p><p>iOS 7 was a radical change in app design when first introduced by Apple back in June 2013. It was a lot of work for app designers and developers alike, which essentially made all apps look flatter with a drop in the use of bezels and gradients. As a result of this, the use of one technique to provide depth and context sky rocketed; blurring.</p><p><a href="https://itunes.apple.com/ca/app/id859232009">Tab’s mobile app</a> uses blurring fairly extensively in various ways. The Nearby Restaurants feed design was the cause of some interesting programming challenges due to how taxing blurring operations can be. It’s currently under going a large overhaul however which will be coming out in the near future as Tab 2.0!</p><p>Now let’s dive right into our first case. Blurring for the sake of blurring.</p><h3>Pretty but expensive</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/315/1*fGepbyPJAbWl-W3Zxq7xPg.gif" /><figcaption>Tab’s Nearby Restaurant feed with real-time blurring</figcaption></figure><p>Tab’s restaurant feed features the closest restaurants to the user. Elegant and beautifully crafted by Tab’s product designer, <a href="https://twitter.com/camerondearsley">Cameron Dearsley</a>.</p><p>What might immediately jump out at you is that the restaurant images feature a darkened blur with text overlay. I personally love blurring and the flavour it provides to apps, but anyone who’s worked with real-time blurring knows that it’s a very expensive operation.</p><p>The above effect was accomplished with 2 asynchronous <a href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/NSOperation_class/index.html">NSOperation</a> queues with a dependancy between them. One to download the restaurant images from our server and another to blur the image as soon as the download is complete. The blurred images were then cached and only blurred again if the image needed to be re-downloaded. Quite a lot of work for a simple effect.</p><p>This resulted in challenges to make the scrolling as smooth as possible and to keep memory usage to a minimum. Table view cells that ended display immediately stopped their blur operations and a limited amount of images were held in memory to avoid memory warnings (particularly challenging on iPhone 4/4s devices!).</p><p>While it was a fun challenge from a programming perspective, it really didn’t serve much purpose here other than to look pretty. A view laid on top with black translucency or a gradient served the same purpose (text readability) with minimal impact on performance.</p><p>So when is it a good time to use blurring in apps?</p><h3>Blurring for context</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/315/1*DpkSWUDoBd8nLD_BZjED2w.gif" /><figcaption>Background blur providing depth</figcaption></figure><p>This gif features Tab’s Account screen. Users can click “Promo” to enter promo codes and get Tab credits. As you can see, the background view is blurred on click and a promo code entry view pops into sight.</p><p>The blur here is key because it really draws the attention of the user to what needs to be focused on. It may be obvious in this case because of the popup animation, but there are many situations where the same concept can be used to provide focus and a layer of depth to the app.</p><p>Time to get into actual ways to implement in-app blurring.</p><h3>UIImageEffects for iOS 7</h3><p>The easiest way to blur in iOS 7 is with an Apple provided class called <a href="https://developer.apple.com/library/ios/samplecode/UIImageEffects/Listings/UIImageEffects_UIImageEffects_h.html">UIImageEffects</a>. UIImageEffects provides a variety of blur effects which can be applied to an input image. You can use the default extra light, light or dark effects, or provide your own parameters for more fine-tuned control.</p><p>To grab a screenshot, simple use UIView’s method <a href="https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/index.html#//apple_ref/occ/instm/UIView/drawViewHierarchyInRect:afterScreenUpdates:">drawViewHierarchyInRect:afterScreenUpdates:</a> to draw a view snapshot in the current context. You can even write a simple UIView category that combines the snapshot method with UIImageEffects like so:</p><pre>- (void)blurViewLightWithCompletion:(void (^)(UIImage *blurredImage))completion<br>{<br>  // Asynchronous snapshot and blur<br>  dispatch_queue_t queue = <br>     dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);<br>  <br>  dispatch_async(queue, ^ {<br>    // Begin image context<br>    UIGraphicsBeginImageContextWithOptions(self.frame.size, NO, 0.0f);<br>    <br>    // Get the snapshot<br>    [self drawViewHierarchyInRect:self.frame afterScreenUpdates:NO];<br>    UIImage *snapshot =<br>      UIGraphicsGetImageFromCurrentImageContext();<br>    <br>    // End graphics context<br>    UIGraphicsEndImageContext();    <br>    <br>    // Blur snapshot image with UIImageEffects<br>    UIImage *blurredImage =<br>      [UIImageEffects imageByApplyingLightEffectToImage:snapshot];</pre><pre>    // Return blurred image on main thread<br>    dispatch_async(dispatch_get_main_queue(), ^{<br>      if (completion) {<br>        completion(blurredImage);<br>      }<br>    });<br>  });<br>}</pre><h3>UIVisualEffectView for iOS 8</h3><p>iOS 8 improves upon this by offering a new view class that requires no code at all! In iOS 7 the only way to blur using Storyboards or a nib was to drop a <a href="https://developer.apple.com/library/ios/documentation/Uikit/reference/UIToolbar_Class/index.html">UIToolbar</a> and setting the translucent property to true. This would blur the contents behind the toolbar, but the control isn’t meant to be resized which is a problem.</p><p>iOS 8 brings in (and rather discreetly) <a href="https://developer.apple.com/library/ios/documentation/uikit/Reference/UIVisualEffectView/index.html#//apple_ref/occ/cl/UIVisualEffectView">UIVisualEffectView</a>, which provides a simple way to drop in a view that automatically blurs the contents behind it. You can get started with no coding at all, so rather than explaining it I made a simple project demonstrating its usage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/240/1*YwCpTUFX8ufQztuExe-LQA.gif" /><figcaption>UIVisualEffectView showing Extra Light, Light and Dark blur effects</figcaption></figure><p><a href="https://github.com/strekfus/VisualEffects">Check it out on github</a>. There’s less than 10 lines of code I added myself, but real-time blurs can easily be accomplished with none. Enjoy!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bba243ea8d72" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ios-os-x-development/to-blur-or-not-to-blur-bba243ea8d72">To blur or not to blur?</a> was originally published in <a href="https://medium.com/ios-os-x-development">iOS App Development</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Float Rating View in Swift]]></title>
            <link>https://medium.com/swift-programming/float-rating-view-in-swift-e740b6b9404d?source=rss-f0aea0a8ec8e------2</link>
            <guid isPermaLink="false">https://medium.com/p/e740b6b9404d</guid>
            <dc:creator><![CDATA[Glen Yi]]></dc:creator>
            <pubDate>Mon, 22 Sep 2014 01:49:16 GMT</pubDate>
            <atom:updated>2014-09-22T01:53:35.044Z</atom:updated>
            <content:encoded><![CDATA[<p>A simple ratings iOS control written in Swift using CALayer masks</p><p>Way back in January at <a href="https://tabpayments.co/">Tab Payments</a> we needed a simple iOS rating view so that users could rate their server and leave a review. After some searching I found a great <a href="http://www.raywenderlich.com/1768/uiview-tutorial-for-ios-how-to-make-a-custom-uiview-in-ios-5-a-5-star-rating-view">tutorial by Ray Wenderlich</a>, whose site has some of the best iOS tutorials I&#39;ve come across. The only problem was it didn&#39;t do float ratings (to show averages) and I didn&#39;t like how it needed a 3rd image for half ratings.</p><p>The solution was to write a control based on that tutorial, which I recently rewrote in Swift. FloatRatingView was the result and the <a href="https://github.com/strekfus/FloatRatingView">full source code with demo project is on github</a>.</p><h3>FloatRatingView</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/315/1*HZkQTTA-Nrl9SbQZyQMpuA.gif" /></figure><p>FloatRatingView is rather simple to use, returns the live float rating to a delegate and only needs 2 images to setup (an empty and full rating image). This was accomplished using the <strong><em>CALayer</em> </strong>class and its optional <strong><em>mask</em> </strong>layer. For full details on how this control works, be sure to check out the tutorial linked above.</p><h3>CALayer and Masks</h3><p>Behind every UIView there is a CALayer class which manages the image based content such as animations, colour and alpha channels. The <strong><em>mask</em> </strong>property of CALayer is completely optional and lets you control how much of the background layer is shown by adjusting the <em>mask’s </em>frame.</p><p>So while the original control used one set of UIImageViews to show the current rating, FloatRatingView actually has 2 sets of UIImageViews laid directly on top of each other. One to show the empty rating images and one on top to show the full rating images.</p><p>The full rating image is then masked to only partially show its image for floating point ratings. All of this is done in a <strong><em>refresh()</em></strong> function which responds to user touches and layout changes. The <em>refresh()</em> function iterates through all the full image views and does 3 things:</p><ol><li>If the rating is greater than the current full image view index, we show the full image view.</li><li>If the rating is less than the current full image view index, we hide the full image view.</li><li>If the rating is a float value somewhere between the current and next full image view index, we create a mask to partially hide it.</li></ol><pre><strong>func </strong>refresh() {<br>  <strong>for </strong>i <strong>in 0..&lt;</strong>self.fullImageViews.count {<br>    <strong>let </strong>imageView <strong>= </strong>self.fullImageViews[i<br>    // Show the full rating image if rating is greater than index<strong><br>    if</strong> self.rating<strong>&gt;=</strong>Float(i<strong>+</strong>1) {<br>      imageView.layer.mask <strong>=</strong> nil<br>      imageView.hidden <strong>=</strong> false<br>    }<br>    // Use a mask CALayer to partially show the full rating image<br>    <strong>else if </strong>self.rating&gt;Float(i) <strong>&amp;&amp; </strong>self.rating<strong>&lt;</strong>Float(i<strong>+1) </strong>{<br>      <em>// Create a mask layer for full image<br>      </em><strong>let </strong>maskLayer <strong>= </strong>CALayer()<br>      // Calculate the mask width as a fraction of the full image<br>      <strong>let</strong> maskWidth = CGFloat(self.rating—Float(i)) <strong>* <br>                      </strong>imageView.frame.size.width<br>      <strong>let</strong> maskHeight = imageView.frame.size.height<br>      // Set the mask frame<br>      maskLayer.frame <strong>= </strong>CGRectMake(0, 0, maskWidth , maskHeight )<br>      // The mask layer needs a colour to show the full image<br>      maskLayer.backgroundColor <strong>= </strong>UIColor.blackColor().CGColor<br>      // Set the full image view&#39;s mask and unhide it<br>      imageView.layer.mask <strong>= </strong>maskLayer<br>      imageView.hidden <strong>= </strong>false<br>    }<br>    // Hide the full rating image if rating is less than index<br>    <strong>else </strong>{<br>      imageView.layer.mask <strong>= </strong>nil<br>      imageView.hidden <strong>= </strong>true<br>    }<br>  }<br>}</pre><p>Originally I had used masks on all the full rating images but found that performance suffered when showing many FloatRatingViews at the same time. Setting the <strong><em>hidden</em></strong> property and only using masks when needed ended up being the way to go.</p><h3>Swift Property Observers</h3><p>One convenient Swift feature used in FloatRatingView is <a href="https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Inheritance.html#//apple_ref/doc/uid/TP40014097-CH17-XID_303"><strong><em>Property Observers</em></strong></a><strong><em>. </em></strong>Whenever a property’s value will be changed or has been changed, we can respond to these events by overriding their respective observers, <strong><em>willSet </em></strong>and <strong><em>didSet. </em></strong>In this case, whenever an empty or full image is set for FloatRatingView we can respond by setting the empty and full UIImageView images.</p><pre><em>/** Sets the empty image (e.g. a star outline) */<br></em><strong>var </strong>emptyImage: UIImage<strong>? </strong>{<br>  <strong>didSet </strong>{<br>    <em>// Update empty image views<br>    </em><strong>for </strong>imageView <strong>in </strong>self.emptyImageViews {<br>      imageView.image <strong>= </strong>emptyImage<br>    }<br>    self.refresh()<br>  }<br>}</pre><pre><em>/** Sets the full image that is overlayed on top of the empty image. Should be same size and shape as the empty image. */<br></em><strong>var </strong>fullImage: UIImage<strong>? </strong>{<br>  <strong>didSet </strong>{<br>    <em>// Update full image views<br>    </em><strong>for </strong>imageView <strong>in </strong>self.fullImageViews {<br>      imageView.image <strong>= </strong>fullImage<br>    }<br>    self.refresh()<br>  }<br>}</pre><p>This is all that’s required to initialize everything. The full rating image views are laid on top of the empty rating image views and are shown or hidden depending on the rating. The function <em>refresh()</em> is then called to update the image view masks.</p><h3><strong>Some Notes on Swift</strong></h3><p>A couple of small things I came across writing FloatRatingView. In Swift, you specify an optional value by placing a question mark (<strong><em>?</em></strong>) right after it, or a forced unwrapped value with an exclamation mark (<strong><em>!</em></strong>). This means you need to watch your spacing when writing equality statements or you’ll get an error.</p><h4>For example</h4><pre>// This works fine<br>if rating&gt;=i {<br>}</pre><pre>// But this won&#39;t compile<br>if rating!=i {<br>}</pre><p>While the above example looks innocent enough, the compiler will think the exclamation mark in the 2nd <em>if-statement</em> is a forced unwrapping. This means it should be written like so:</p><pre>// Mind the spacing<br>if rating != i {<br>  // Do something<br>}</pre><h4>Another example</h4><pre>// 0 is not an optional value<br>let rating = i==0? 0:5</pre><p>This statement looks like something any Objective-C programmer would write and not think twice about. This also gives an error however, as the compiler looks at <strong><em>0? </em></strong>and thinks it’s for an optional value. Again, just need to be mindful of the spacing whenever you’re using question or exclamation marks.</p><pre>// What we actually need<br>let rating = i==0 ? 0:5</pre><h3>That’s all for now!</h3><p>There are some layout functions that aren&#39;t covered here but are fully explained in the Ray Wenderlich tutorial. Feel free to use or fork <a href="https://github.com/strekfus/FloatRatingView">FloatRatingView</a> at anytime or even send a pull request!</p><p>Photo cred for the header once again goes to <a href="http://hubblesite.org/gallery/">NASA’s Hubble Space Telescope</a>. ☺</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e740b6b9404d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swift-programming/float-rating-view-in-swift-e740b6b9404d">Float Rating View in Swift</a> was originally published in <a href="https://medium.com/swift-programming">Swift Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cardano Triplets in Swift]]></title>
            <link>https://medium.com/swift-programming/cardano-triplets-in-swift-114692293795?source=rss-f0aea0a8ec8e------2</link>
            <guid isPermaLink="false">https://medium.com/p/114692293795</guid>
            <dc:creator><![CDATA[Glen Yi]]></dc:creator>
            <pubDate>Sun, 24 Aug 2014 18:31:30 GMT</pubDate>
            <atom:updated>2014-08-25T17:22:58.329Z</atom:updated>
            <content:encoded><![CDATA[<p>Performance comparison between Swift and Objective-C</p><p>Engineers tend to like brain teasers, and one of the problems we came across at work was the <a href="https://projecteuler.net/problem=251">Cardano Triplets problem on Project Euler</a>. I never actually solved it, but it was fun to play around with and it ended up with me running an experiment.</p><h3><strong>Cardano Triplets?</strong></h3><p>A triplet of positive integers, (a, b, c), is a Cardano Triplet if it satisfies the following condition:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/168/1*FMzcYkni5cV14Hx8pVuqDA.gif" /></figure><p>The problem is to find all Cardano Triplets where <strong><em>a + b + c &lt;= 110,000,000</em></strong></p><p>Yes, <em>one hundred and ten million</em>… making this a near impossible problem to solve through brute force.</p><p>I’m sure there is a very elegant mathematical/programming solution to this, but instead of trying to solve for 110,000,000 I thought it would be interesting to write a brute force solution anyways, but in Apple’s new programming language, Swift. Swift is a fairly easy language to pickup and should greatly reduce the barrier to entry for anyone looking to learn iOS development (no more square brackets everywhere!). This experiment led me to do a direct comparison in performance between Swift and Objective-C using the exact same solution.</p><h3>The Solution</h3><p>The brute force solution was done mainly with 2 functions. The first one checks if a triplet is valid.</p><pre><strong>func </strong>isCardanoTriplet(triplet: Triplet) -&gt; Bool<br>{<br>    <strong>let </strong>bc = Double(triplet.b) * sqrt(Double(triplet.c))<br>    <strong>let </strong>cardano = cbrt(Double(triplet.a)+bc) +<br>                  cbrt(Double(triplet.a)-bc)</pre><pre><em>    // Floating point rounding errors…<br>    </em><strong>let </strong>isCardano = (cardano &lt; 1.000001 &amp;&amp; cardano &gt; 0.999999)</pre><pre><strong>    return </strong>isCardano<br>} </pre><p>The second function creates all triplets where <strong><em>a + b + c &lt;= ‘limit’</em></strong>. This is done with a triple nested for-loop, which is where the majority of the computing time takes place.</p><pre>var count = 0<br>for a in 1…limit-2 {<br>    for b in 1…(limit-a-1) {<br>        for c in 1…(limit-a-b) {<br>            let triplet = (a, b, c)<br>            if self.isCardanoTriplet(triplet) {<br>                count++<br>                println(“\(count): \(triplet)”)<br>            }<br>        }<br>    }<br>}</pre><p>Not the most elegant solution but it gets the job done. I wrote a simple app in both Swift and Objective-C with the exact same concept as above to compare their performances in seconds.</p><h3>The Test Setup</h3><p><strong>Hardware</strong>: 2012 MacBook Air (1.8 GHz Intel Core i5, 4GB 1600 MHz DDR3)<br><strong>XCode Versions: </strong>6 Beta4, 6 Beta6<strong><br>XCode</strong> <strong>Simulator</strong>: iPhone 5s</p><p>Lastly, because I didn’t want the apps to run forever, I set the limit to 1000 which correctly returns 149 Cardano Triplets.</p><h3>The Results</h3><h4>Swift</h4><p><strong>XCode 6 Beta4</strong>: 130 seconds<br><strong>XCode 6 Beta6</strong>: 56 seconds</p><h4>Objective-C</h4><p><strong>XCode 6 Beta4</strong>: 8 seconds<br><strong>XCode 6 Beta6</strong>: 8 seconds</p><p>Edit: The above results were run in Debug mode with no optimizations. Turning on -O optimizations quickly closed the gap.</p><h4>Swift</h4><p><strong>XCode 6 Beta6</strong>: (-Os optimization): 8.5 seconds</p><h4>Objective-C</h4><p><strong>XCode 6 Beta6</strong>: (-Os optimization): 6.4 seconds</p><p>This time Swift was only 32.8% slower, a huge relief from the original 600% result! Swift is still in beta and Apple will be continuously optimizing it down the road, but it was still a surprising gap between Swift and Objective-C.</p><p>This shouldn’t deter anyone from learning Swift however as it will ultimately be the future of iOS development. I also find it very refreshing to work with after years of C++ and Objective-C. Just don’t expect to solve any <a href="https://projecteuler.net/">Project Euler</a> problems in record time using Swift.</p><p>The full code for the project can be found <a href="https://github.com/strekfus/CardanoTriplets">on my github</a>, so feel free to fork it and try it out for yourself!</p><p>And oh ya, header photo cred to <a href="http://hubblesite.org/gallery/">NASA’s Hubble Space Telescope</a>. ☺</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=114692293795" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swift-programming/cardano-triplets-in-swift-114692293795">Cardano Triplets in Swift</a> was originally published in <a href="https://medium.com/swift-programming">Swift Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>