<?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 Jinha Park on Medium]]></title>
        <description><![CDATA[Stories by Jinha Park on Medium]]></description>
        <link>https://medium.com/@jjuou2?source=rss-9b8f5f9360bb------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*FDGcPX_8Nom9W4pjurdKxQ.jpeg</url>
            <title>Stories by Jinha Park on Medium</title>
            <link>https://medium.com/@jjuou2?source=rss-9b8f5f9360bb------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 10:14:49 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jjuou2/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[What’s new in Swift]]></title>
            <link>https://medium.com/@jjuou2/whats-new-in-swift-a4db033904bf?source=rss-9b8f5f9360bb------2</link>
            <guid isPermaLink="false">https://medium.com/p/a4db033904bf</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[wwdc-2021]]></category>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[wwdc]]></category>
            <dc:creator><![CDATA[Jinha Park]]></dc:creator>
            <pubDate>Tue, 13 Jul 2021 15:12:04 GMT</pubDate>
            <atom:updated>2021-07-13T15:12:04.827Z</atom:updated>
            <content:encoded><![CDATA[<blockquote><em>🗂WWDC21 | Category : Swift</em></blockquote><blockquote><em>🔗 </em><a href="https://developer.apple.com/videos/play/wwdc2021/10192/"><em>https://developer.apple.com/videos/play/wwdc2021/10192/</em></a></blockquote><blockquote><em>🔖 Join us for an update on Swift. Discover the latest language advancements that make your code easier to read and write. Explore the growing number of APIs available as Swift packages. And we’ll introduce you to Swift’s async/await syntax, structured concurrency, and actors.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Q2ZNayS57yR4NSrE.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8R7Kfqi2JEIpbxrT.png" /></figure><ul><li>Diversity</li><li>Update on Swift packages</li></ul><h3>Package collections in Xcode</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pX1ofa2mUgKGEwT9.png" /></figure><p>Swift Package Collections</p><p>No longer need to search for packages on the Internet, or copy and paste URLs to add them.</p><p>You can now simply browse a collection and add packages from new package search sreen in Xcode.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*WUz5O7-A-u_yBwwC.png" /></figure><p><a href="http://swift.org/blog/package-collections">Package Collections</a></p><h3>Swift Collections</h3><p>new open source package of data structures that complements those available in the Swift Standard Library.</p><ul><li>Deque</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uoEHpRsyK9e8vV-s.png" /></figure><ul><li>Deque is like an Array, except that is supports efficient insertion and removal at both ends.</li><li>OrderedSet</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VhMAE2a541qOjqme.png" /></figure><ul><li>OrderedSet is a powerful hybrid of an Array and a Set.</li><li>Like Array, OrderedSet maintain its elements in order and supports random access.</li><li>Like a Set, OrderedSet ensures each element apprears only once and provides efficient membership testing.</li><li>OrderedDictionary</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*77vX574OoOjn_ioK.png" /></figure><ul><li>OrderedDictionary, which is a userful alternative to Dictionary when order is important, or we need random access to elements.</li></ul><h3>The Alogrithms package</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zxl8-HpL6uit3I2X.png" /></figure><p>New open source package of Sequence and Collections algorithms.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*i9_J3WRpARyA6Tbd.png" /></figure><h3>Swift System</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*X1cj2gR0KZVbaFQP.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*04gFVwrI8sZnM3KZ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*tKXWADOkuwqq2cpD.png" /></figure><h3>Swift Numerics</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rGZHjZPXXwPU98xY.png" /></figure><p>log, sine, cosine</p><p>Because these implementations are written in Swift, they are frequently more efficient than a traditional C library and allow for optimizations.</p><h3>The ArgumentParser package</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*OceGWb0tMmgaizOg.png" /></figure><h3>Update on Swift on server</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*d9sRymiSmIkbKrUk.png" /></figure><p>Static linking on Linux</p><p>improves application startup time, as well as simplifies the deployment of server applications, which can now be deployed as a single file.</p><p>Improved JSON performance</p><p>in Swift 5.5, the JSON encoding and decoding used on Linux were reimplemented from scratch, resulting in performance gains for most common use cases.</p><p>Enhanced AWS Lambda runtime</p><p>enhanced and optimized the performance of the AWS Lambda runtime library itself.</p><p>All this work made Swift programs running on AWS Lambda start 33% fatser, as well as 40% faster invocation time for a lambda routed via AWS API Gateway.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hJoY7-2eEuMrhdM5.png" /></figure><h3>Developer experience improvements</h3><h3>Swift DocC</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*s5cIBV4jPmI-ohk5.png" /></figure><p>A documentation compiler that’s deeply integrated inside Xcode 13, to help you teach developers how th use your Swift framework or package.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*G4btrXR5DyyRgHyU.png" /></figure><p>In Swift 5.5, we invested in quality and performace improvements in the type checker.</p><p>One result of this is you will see fewer “expression too complex” erros when compiling your code.</p><p>We also sped up the performance for type checking of array literals.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aycYICTkdh4Rp6eS.png" /></figure><h3>Memory Management</h3><p>ARC automatically frees up the memory used by class instances when those instances no longer needed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4bPAvQP2aiM1PNwJ.png" /></figure><p>To do this, the Swift compiler inserts a retain operation any time a new reference is created and a release operation whenever a new reference stops being used.</p><p>New way to track references inside the compiler that allows the compiler to significantly reduce the number of retain and release operations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*c5PC4XDy6MfqUeOR.png" /></figure><p>Xcode setting, Optimize Object Lifetimes, that will allow you to see the effect of this new, more aggressive ARC optimization on your code.</p><h3>Ergonomic improvements</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9xVw6tw6z4X9J6ZY.png" /></figure><h3>Result Builders</h3><ul><li>Originally designed for SwiftUI</li><li>Flexible way to define complex object hierarchies</li><li>Standardize and refined this year</li></ul><h3>Enum Codable synthesis</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*e33Tf2ZcvlF4CkD6.png" /></figure><p>You just need to declare the Codable conformance, and the compiler will do all of boilerplates that work for you.</p><p>Flexible static member lookup</p><p>Type inference in Swift means you can omit redundant type information.</p><p>But Enum-like structures are also represented in other ways.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Fq_ab3pmkJdV4MLQ.png" /></figure><p>You might have a collection of types that conform to a protocol and want to use instances of those types in your API.</p><p>You can now refer to instances of those types using the same dot-notation that you use for Enums, by declaring a few static properties on your protocol.</p><p>This is enabled by improvements to Swift’s type checker that allows it to reason more generally about static properties in generic contexts, including chained property references such as the .large.</p><p>This allows library authors to build sophisticated generic data models with natural and easy-to-use Enum-like APIs.</p><h3>Property wrappers on parameters</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dezHNI6-xzO4EcMn.png" /></figure><p>@NotEmpty</p><p>With the implementation, those same property wrappers can now be used on function and closure parameters.</p><h3>Asynchronous and concurrent programming</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ctPTg89cQiWlCHSd.png" /></figure><p>Software projects are composed out of blocks of code that execute in some order. In the simplest case, those blocks execute, on after the other in a simple sequence. But other structures are common as well.</p><p>Networking APIs are often designed in an asynchronous style. Int these APIS, after you’ve sent a request to the remote server, there may be a long delay until you receive a response and need to do more work. Ideally, your code would be suspended during this delay so it does not use any resources until you are able to act on the reponse.</p><p>In contrast, concurrent code is when you have two or more blocks of code that you would like to have running at the same time. These are often independent but related operations. Processing several frames of a video, for instance, or running the next iteration of an ML classfier at the same time that you’re updating the UI with previous set of results.</p><h3>Asynchronous Programming with Async/Awailt</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wpfz1bvgm4YLFFnn.png" /></figure><p>This uses Foundation’s URLSession class to make a network call.</p><p>The dataTask method is an asynchrounoush operation. You call it with a closure argument. When the result becomes available, your closure will be called with the results to process.</p><p>Using closures in this way to express asynchronous code results in a somewhat awkward order of operations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*H5ZN71to2xNcxBEW.png" /></figure><p>await</p><p>tell the compiler that our function can be suspended as soon as the data method begins and that we won’t be able to finish the assignment until that operation has completed.</p><p>Syntatically, the async and awail keywords are used similary to throws and try.</p><p>aysnc decorates the function declaration to indicate that this function must be com mpiled to support suspension.</p><p>await keyword to mark any call to an async function, method, or closure.</p><h3>Structed Concurrency</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*UjPCoyNxpboo1nKF.png" /></figure><p>async</p><p>that it will able to suspend if it needs to wait for results that are being computed in other threads.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xwzt_GG-MJ92-kMR.png" /></figure><p>async let</p><p>to run the first two operatipons in parallel.</p><p>This initialization will run in parallel with other code out you tryh to use th results.</p><h3>Actors</h3><p>Whenever two seperate threads share data, you run the risk that the data will be inconsistent, or even corrupted.</p><p>Swift’s new actor construct helps protect your data against such problems.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/0*cm4zUKbB0urwTi3f.png" /></figure><p>If two or more threads call the increment method at the same time, you can end up with a badly-corrupted count.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/836/0*w328S7pRyMDJbB8O.png" /></figure><p>actor protects against such corruption</p><p>Actors work by suspending any operation that might cause data corruption until it’s safe to make that particular change.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/870/0*ZHzciDID9KLYvha_.png" /></figure><p>This means you generally need to use await when you call an actor method from outside of the actor.</p><p>Actors also work seamlessly with async/await.</p><p>Marking this publish method as async allows it to be suspended while waiting on network operations. While its suspended, other methods can run on this actor without waiting for the network operation to complete and without risk of data corruption.</p><ul><li>Actors are reference types, like clsses, but they obey a number of rules designed to ensure that actors are safe to use in a multi-threaded environment.</li><li>By packaging your data into actors, you are clearly stating that you expect this data to be accessed concurrently and that you want the Swift compiler and runtime to coordinate access so that no corruption is possible.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a4db033904bf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Design great widgets]]></title>
            <link>https://medium.com/@jjuou2/design-great-widgets-ed8822b308c9?source=rss-9b8f5f9360bb------2</link>
            <guid isPermaLink="false">https://medium.com/p/ed8822b308c9</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[widget]]></category>
            <category><![CDATA[wwdc-2020]]></category>
            <category><![CDATA[wwdc20]]></category>
            <category><![CDATA[swiftui]]></category>
            <dc:creator><![CDATA[Jinha Park]]></dc:creator>
            <pubDate>Sat, 04 Jul 2020 18:48:34 GMT</pubDate>
            <atom:updated>2020-07-04T18:48:34.545Z</atom:updated>
            <content:encoded><![CDATA[<h3>Design great widgets</h3><blockquote><em>📅 2020.7.2 (THU)</em></blockquote><blockquote><em>🗂 WWDC2020 | Session : 10103 | Category : Frameworks</em></blockquote><blockquote><em>🔗 </em><a href="https://developer.apple.com/videos/play/wwdc2020/10103/"><em>https://developer.apple.com/videos/play/wwdc2020/10103/</em></a></blockquote><blockquote><em>🔖 Widgets elevate timely information from your app to primary locations on iPhone, iPad and Mac. Discover the keys to designing glanceable widgets, developing a strong widget idea, and clearly communicating with content, color, sizing, layout, and typography. If you’d like to learn more about the technical implementation for adding widgets into your app, check out “Get Started with WidgetKit” and our three-part code-along series.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*b31hiO4ynbDLRrXWEFF4aQ.png" /></figure><p>In iOS 14, the entire widget has been completely redesigned. At its foundation is an entirely new visual aesthetic, and powerful new capabilities.</p><p>One of the things we’re really excited about is that people can now add widgets directly onto their home screen pages.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*b31hiO4ynbDLRrXWEFF4aQ.png" /></figure><p>Another feature is Smart Stacks. These let you add several different widgets into a single location and quickly flick between the different widgets inside.</p><p>But what is really powerful is that smart stacks dynamically change and adapt to how you use them. Based on your behavior and context, a smart stack will automatically rotate to show you the most relevant widget at a given time.</p><p>When designing a widget there are 2 main parts of process to focus on, Ideation and Creation.</p><h3>Ideation</h3><h3>Principles</h3><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*b31hiO4ynbDLRrXWEFF4aQ.png" /></figure><ul><li>Personal We want to look for things that are personal because they can allow for a deeper emotional connection with a piece of your app or an experience that it enables for someone</li><li>Informational Widgets provide a great way to see a top level overview of information from a variety of sources on someone’s device. Surfacing the right information can save people from doing commonly repeated actions in your app.</li><li>Contextual Context helps surface the right information at the right moment and allows for better experience that at its best feels like it’s magically prediction someone’s need and next steps.</li></ul><h3>Example</h3><p>Calendar</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*b31hiO4ynbDLRrXWEFF4aQ.png" /></figure><p>It shows the day of the week and the current date, your next meeting or event was the most important piece of information to surface from within the app.</p><p>Glanceable details like the start time and event location save people a potential step in opening the app to find this information.</p><p>If you have a busy schedule with lots of events it collapses some of the less relevant information and prioritizes the single most important piece of information from each event.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*b31hiO4ynbDLRrXWEFF4aQ.png" /></figure><p>When your day is almost ever and there’s no more events, rather than just showing a blank widget when possible we instead start telling your about what is coming up next and happening in your day tomorrow.</p><p>Widgets are dynamic and informative, and contextual details make the experience feel very personal and adaptive to person’s need.</p><h3>Editing</h3><p>In iOS 14, your widgets will jiggle just like apps do in edit mode and you can tap on a widget to flip it around and see what it allows for you to edit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*b31hiO4ynbDLRrXWEFF4aQ.png" /></figure><p>Here, the Weather widget lets me change what location it’s displaying the weather conditions for. By default it adapts to your current location so that when person adds a widget they don’t have to do any additional work.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*b31hiO4ynbDLRrXWEFF4aQ.png" /></figure><p>If I tap on the location field, I get a list of all my favorite weather cities as well as the ability to search for other locations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*b31hiO4ynbDLRrXWEFF4aQ.png" /></figure><p>Most of the new widgets in iOS support editing like this and it’s a great experience to add and choose different reminders list, stocks, notes and world clocks.</p><h3>Multiples</h3><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/0*J974ypWl-oIN1d8R.png" /></figure><p>For Stocks, we had two different ideas: to offer a widget that shows a glanceable compact summary of your watchlist information but also the ability to add a single stock symbol as a separate widget to keep track of it at a higher resolution just like weather did.</p><p>Several other apps in iOS 14 offer multiple widgets, including news which lets you follow top news from a specific topic and notes that lets you pin a favorite note or add a shared note folder.</p><h3>Creation</h3><h3>Sizes and Interactions</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*RFpiPDzd-HT-O1pZ.png" /></figure><h3>Small</h3><ul><li>All about the most useful piece of content from your app in a size that constraints how much content can actually fit in it.</li><li>Small widget supports a single tap target. Tapping it should deep link to the content that’s on the widget.</li></ul><p>Ex) small Calendar widget</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/406/0*vLUxUUGYo2kutI2_.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/0*y742ZPRHTC9KQMwM.png" /></figure><p>Since the widget is always showing what event is coming up next, we thought it made the most sense to bring you to the latest event in the app’s Day View.</p><p>When you tap on the widget, the Day View scrolls to the latest event and gives you a nice glimpse of the rest of your day around it.</p><p>Ex) small News widget</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/566/0*wmlFJhUbrA_yY3kY.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/542/0*SJ5Q3kpBBymSJMrx.png" /></figure><p>Since it previews a rich news story that you might be interested in reading, tapping it brings you directly to that news story and the app.</p><h3>Medium, Large</h3><ul><li>Both sizes fit more content and support multiple tap targets. Tapping a piece of content in a medium or large widget should also deep link you to the displayed content that’s on the widget</li></ul><p>Ex) News</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/572/0*f6TgVIjjiWCdIZPw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/542/0*ieOhhXvrlqI-Iowh.png" /></figure><p>Tapping either article brings you directly to the News story you tapped on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/558/0*I5q19aSlVDB36Un-.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/692/0*CvymLsA5bF23XA3k.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/594/0*o-NyFb0dAiGbeDxp.png" /></figure><ul><li>Fill style is best for when you’re deep linking into a single piece of content. Every small widget uses fill style since it only supports one tap target.</li><li>Cell style is best for when you’re selecting a piece of content in a widget that lives in its own shape.</li><li>Content style is great for when you’re selecting a piece of content that lives un-contained in a widget.</li></ul><h3>Content and Personality</h3><p>The most important part about making your widget come to life is what lives in it. You should think about content and personality when you’re designing your widget.</p><p>“ What are people looking for when they launch my app?”</p><p>Also find distinct items of information that people find useful in your app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CsiF-oVPP1W4YU9B.png" /></figure><p>When designing widget set, we looked at finding personality through how our apps look.</p><p>For Weather, we used the familiar weather condition background, as well as the iconography from the app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kPyZNh2SWMLYG5DS.png" /></figure><p>For News, we took inspiration from the rich story images that you see in news stories.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JHJkl-cu9hOgYZbj.png" /></figure><p>And for Calendar, we took inspiration from its simplistic look and familiar red tint color, focusing all on what events are coming up next.</p><p>Another approach for finding personality is taking inspiration from your app icon.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ZRikyL4OIYwdZV8v.png" /></figure><p>Like Notes, where we took on the icons notepad illustration style.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PiD3Gq39Z1d2NN3A.png" /></figure><p>Podcasts, where we use the icon’s purple gradient.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*yQE9XEfv0yu7WuxO.png" /></figure><p>And Tips where we use the icons yellow gradient.</p><p>When it come to laying out content in your widget, there were two patterns we found when designing our widget set.</p><ol><li>Layout that expands across all three sizes. like Weather, where we add additional information across each size.</li><li>Layout that is completely unique across each size. like News, the small widget prioritizes rich content that fills up the whole space, while the medium widget focuses on showing more news stories.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*EVBT23QNkx0_ZTQR.png" /></figure><p>When you’re designing for each size, make sure not to scale up your smaller widget into your large widget.</p><p>Think about the information you’re working with and what makes the most sense for each size.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0qQs7cQpvYU6awyG.png" /></figure><p>For the large Screen Time widget, since we had more useful information that we could include and more space, we increased the size of the chart and also included category and app details.</p><p>If you don’t have more information to show in your larger sizes though, it’s fine to only support specific sizes of your idea. All sizes for an idea aren’t required.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*iFc6q90e-nzlWdz6.png" /></figure><p>We recommend only including a max of four pieces of information in the small widget size.</p><h3>Patterns</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_UDRnj6X_daLPVvJ.png" /></figure><p>Across the different small, medium and large sizes, there were several common layout patterns that emerged.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kcfvFepvXcueHuM-.png" /></figure><p>There are mix of single item and denser multi-item summary layouts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2Ae78t2MxyLHnNVb.png" /></figure><p>These patterns serves as a helpful starting place and a good way to try out an idea in a format that already works well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FZnri_-hCQjmyMMN.png" /></figure><p>When designing your own custom layouts, follow the default sixteen point layout margins across all sizes to make sure the content in your widget feels consistent when it’s place next to other widgets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4I_u5xYwoYS7otXV.png" /></figure><p>For layout with graphical shapes like circles and inset platters use tighter eleven point margins across all sizes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3aA-OJhN-1C1UR95.png" /></figure><p>Shape corners that sit close to the edges of your widget should appear concentric with the widget corner radius.</p><p>Since the widgets corner radius changes across different device sizes, we provide a SwiftUI container that can assign to shapes in your widget that will make them concentric with the widgets corner radius values.</p><p>For type, you should use SF Pro or other variants of San Francisco that are available like SF Mono and SF Pro Rounded. If a custom font is important to how your widget represents its brand or personality, make sure it&#39;s applied in a way so that your widget still feels at home alongside other widgets.</p><p>A widget should look great in both light and dark appearance modes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mqhc9LtKuwH4nerR.png" /></figure><p>Every widget must provide a placeholder which is shown when the system has no way of displaying your widgets data.</p><p>You should show the base graphical elements in this state and block in areas of text where your information is shown in the layout.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*WrraPlqkt0miLcgk.png" /></figure><p>This way, when the system goes form place holder to the proper data, the content can replace the static elements without having the layout or color shift around.</p><h3>Tips</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QqmgzFph_aoOg4wa.png" /></figure><p>You should only use logo in your widget if your app is an aggregator of content from different sources.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*G0dsC2TegqGtPMJs.png" /></figure><p>To keep this treatment consistent across different widgets, your logo should always sit in the top right corner.</p><p>Avoid using word marks in the space and anywhere else in your widget.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gZhH78u30b7HB4_e.png" /></figure><p>Another thing to avoid is putting your app icon in your widget.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*WAb_dXeFtPja_w_S.png" /></figure><p>Also avoid putting your app name in your widget as it will feel redundant with the app label that already appears underneath of it on the home screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ZcXEHjkimbigklYg.png" /></figure><p>Don’t put text that instructs a user or talks to them, instead, if you feel there’s something import to communicate do it in a graphical way.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pdVYig0zBxHEfaIL.png" /></figure><p>When displaying chronological information on a widget, don’t use language like “last updated” or “last checked”.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ed8822b308c9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Meet WidgetKit]]></title>
            <link>https://blog.devgenius.io/meet-widgetkit-eaa10d5c27c8?source=rss-9b8f5f9360bb------2</link>
            <guid isPermaLink="false">https://medium.com/p/eaa10d5c27c8</guid>
            <category><![CDATA[widget]]></category>
            <category><![CDATA[wwdc-2020]]></category>
            <category><![CDATA[wwdc20]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Jinha Park]]></dc:creator>
            <pubDate>Mon, 29 Jun 2020 11:31:34 GMT</pubDate>
            <atom:updated>2020-07-02T10:04:48.741Z</atom:updated>
            <content:encoded><![CDATA[<h3>Meet WidgetKit</h3><blockquote><em>🗂 WWDC2020 | Session : 10028 | Category : Frameworks</em></blockquote><blockquote><em>🔗 </em><a href="https://developer.apple.com/videos/play/wwdc2020/10028/"><em>https://developer.apple.com/videos/play/wwdc2020/10028/</em></a></blockquote><blockquote><em>🔖 Meet WidgetKit: the best way to bring your app’s most useful information directly to the home screen. We’ll show you what makes a great widget and take a look at WidgetKit’s features and functionality. Learn how to get started creating a widget, and find out how WidgetKit leverages the power of SwiftUI to provide a stateless experience. Discover how to harness your existing proactive technologies to make sure your widget surfaces relevant material. And create a Timeline that ensures your content is always fresh. For more on creating widgets, check out “Build SwiftUI views for widgets” and “The widgets code-along.” and explore the growing number of APIs available as Swift Packages.</em></blockquote><p>In iOS 14, we have a dramatic new Home screen experience, one that is much more dynamic and personalized, with a focus on widgets.</p><p>New widgets are designed to be bold, highly glanceable, and be perfectly at home not just on the iPhone Home screen but also our refreshed Today view, pinned to your iPad home screen, and finally in the gorgeous new Notification Center on macOS Big Sur.</p><h3>What makes a great widget?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BTIOJcnneTyJxQpf.png" /></figure><h3>Glanceable</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*IlJ3iSouKZHR7Wi3.png" /></figure><p>New widgets can come in many sizes. Especially at the smallest widget size, you only have the space of around four Home screen icons. You don’t need to tap any buttons or even spend time trying to figure out a complicated UI. The content is the focus.</p><ul><li>Widgets are not mini-apps.</li></ul><blockquote><em>Design Great Widgets — WWDC20</em></blockquote><h3>Relevant</h3><p>Smart Stacks</p><p>Smart stacks are a collection of widgets that will automatically rotate to show the right widget at the top. But you can also swipe through.</p><ul><li>Stacks use on-device intelligence</li><li>Siri Shortcuts donation</li><li>WidgetKit API</li></ul><blockquote><em>Add Configuration and Intelligence to Your Widgets — WWDC20</em></blockquote><h3>Personalization</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jwHRTu9pIvN7ynHa.png" /></figure><p>Different metric</p><p>3 different sizes : small, medium, or large</p><p>→ You’re not required to support all the sizes, but recommended supporting as many sizes as possible</p><p>WidgetKit</p><p>We can generate this entire configuration UI from your Intent completely automatically, with no additional work for you.</p><h3>WidgetKit</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KGZqgmdxw_4WIpKR.png" /></figure><p>It was a goal from the very beginning for widgets to be multi-platform and to make it as easy as possible for developers to have their learnings apply across iOS, iPadOS, and macOS.</p><p>So widgets user interface in WidgetKit are built entirely with SwiftUI.</p><p>SwiftUI also makes it easy to support features like Dynamic Type and Dark Mode nearly automatically.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KI-yt9Fn68JgMDM-.png" /></figure><p>The average person goes to the Home Screen more than 90 times a day and only spends a few moments there.</p><p>When we designed complications on watchOS, we had very similar goals of having things be ready and immediately glanceable. So we took some inspiration from how they were built.</p><h3>How WidgetKit works</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*SxvBsg8rrhlSU88L.png" /></figure><p>WidgetKit extension are background extensions that returns a series of view hierarchies in a timeline.</p><p>Using the declarative nature of SwiftUI, we can package up these views in this timeline and send them over to the Home screen which will present them at the correct time according to the timeline.</p><p>This avoids the entire “launch a process, load, and then present a view”. They are ready to go and immediately glanceable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DclrDGFRF0OzMc_e.png" /></figure><p>The fact that we have your views ready beforehand means we can also reuse them in other areas of the system.</p><p>For example, we can have this super-fun experience to add widget from the Widget Gallery, where people who use your app can get a preview of exactly what your widget will look like right on the Home screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nguRjpvU2e5KBgBz.png" /></figure><p>Example Calendar’s widget</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*V-vODInNsT7t02w1.png" /></figure><p>The extension can use this information to render the right views for when my next meeting is happening, when I’m in that meeting, and the next one after.</p><p>If I go into Calendar and update the event, Calendar will then use API to reload the timeline.</p><p>What we mean by that is that the extension wakes up and return a new timeline with all the new updates.</p><h3>Defining a Widget</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xfXmMey65WrxVBcS.png" /></figure><p>We wanted a mechanism to allow a single extension to support multiple kinds of widgets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Xwd7exb70XmZFmOU.png" /></figure><p>For example, a single Stocks extension provides an experience like the Stocks overview widget, a great widget which provides glanceable information about a few stocks. But also, that same extension powers the Stock detail widget which allow a user to show a single stock on their Home screen or Notification Center on mackOS.</p><p>WidgetKit extension can support SwiftUI, AppKit, and Catalyst-based macOS apps.</p><h3>Configuration</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Lti7e5Na8FKnq_cj.png" /></figure><p>Kinds of widgets can also express which type of configuration they support.</p><h4>StaticConfiguration</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*b_IgBwXK0OwTB4Rt.png" /></figure><h4>IntentConfiguration</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*UkRzbJmuk4WYLzOl.png" /></figure><h3>supportedFamilies</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KmswS3H1Z9CRe8BZ.png" /></figure><p>A particular kind can also enable one or many supportedFamilies. By default, widgets support all family types.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2nqx_-wS6SX3mvOv.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BNRUu_EF7byfN387.png" /></figure><p>These families look great on iOS and on macOS.</p><h3>Placeholder</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qDZxMUqpficMNt1Z.png" /></figure><p>Great placeholder UIs show a representation of what your kind of widget is.</p><ul><li>Default content Each kind of widget is required to provide a placeholder UI. Placeholder UI is the default content of your widget. It should be a representation of your widget kind, but nothing more than that.</li><li>No user data There should not be any user data in this UI.</li><li>Queried on environment change The other important thing to note is this UI retrieved only sparingly. There are no guarantees on when that will occur. Typically we will only ask for a new placeholder UI on a device environment change.</li></ul><p>Sample Widget code</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*bE0jihTmlZIQkEve.png" /></figure><h3>Creating a glanceable experience</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0Ia_2KYcl8L8WODg.png" /></figure><p>All three show me useful information and invite me as the user to tap to launch the app and find out more information. The first aspect of creating a glanceable experience is creating StatelessUI, which SwiftUI is uniquely perfect for.</p><h3>StatelessUI</h3><ul><li>Widgets are not mini-apps</li><li>No scrolling</li><li>No videos or animated images</li><li>Tap interactions</li></ul><h3>Deep links</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Nkg5I75CVrust25J.png" /></figure><p>User can tap on the most recently played album and deep link directly into that app. systemSmall has a single tap target, so the entire widget is a tap target meant to tkae the user directly into the app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FKR7bcG9o76KCu2y.png" /></figure><p>Each album is an individual link which can take you directly into that app.</p><h3>Tap interactions</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qEoYjk7cWC527wF0.png" /></figure><p>The entire widget can be associated with a URL link using the widgetURL API.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FnP_DsqhALVQt0l2.png" /></figure><p>If you want to create sublinks in systemMedium or systemLarge, then you can use the new Link API in Swift UI.</p><h3>Views, timelines, and reloads</h3><h3>Views</h3><ul><li>Placeholder</li><li>Snapshot</li><li>Timeline</li></ul><h4>Spatshot</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cdIpjtQ2-IrnJG-z.png" /></figure><p>Snapshot is where the system needs to quickly display a single entry. So the expectation is for your extension to quickly return a view as fast as possible because when you do so, you’ll see your real widget in the gorgeous Widget Gallery on iOS.</p><p>This isn’t a screenshot or image we had to provide at design time. This is your real widget experience on iOS, iPadOS, and macOS.</p><h4>Timeline</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*MibLJybqDHVuO83j.png" /></figure><p>What you see in the Widget Gallery is what you get when the user adds it to their device/</p><p>If a snapshot is just a single entry, then a series of multiple views to be displayed at the right time is just a timeline.</p><p>Timelines are a combination of views and dates that are returned, which allow you to say at what time a particular view should be shown.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DBaddABiH0TALFYf.png" /></figure><p>And by returning a timeline is how we drive the widget experience. Timeline’s returned should be for both Dark and Light Mode.</p><p>When a WidgetKit extension returns an entry, we will take that information and serialize the view hierarchy to disk. This means we just-in-time render each individual entry. This enables the system to power numerous widgets at the same time with numerous timelines.</p><p>Timelines should typically be returned for a day’s worth of content. There are times though when your widget needs to return more up-to-date information.</p><p>We do this through the concept of what we call reloads.</p><h3>Reloads</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*w8MMWFvqv9mEdvUE.png" /></figure><p>Reloads are where the system will wake up your extension and ask for a new timeline for each widget placed on the device.</p><p>Reloads help ensure that your content is always up-to-date for your user.</p><p>TimelineProvider protocol</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QT3Jln56TKWl24VS.png" /></figure><p>TimelineEntry : consists mainly of a date</p><p>Context : provides environment information and the context for which the system is asking you for entries</p><p>func snapshot : the system asks for a single entry</p><p>func timeline : the system asks for a series of entries</p><p>Example of how to conform the TimelineProvider protocol</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*oRI7RogLHnf5au1T.png" /></figure><p>Baked into each timeline is a ReloadPolicy. It’s where you can tell the system when to ask for the next timeline.</p><h3>ReloadPolicy</h3><ul><li>atEnd</li><li>after(date: Date)</li><li>never</li></ul><h3>System reloads</h3><ul><li>ReloadPolicy The system will take into account your ReloadPolicy and determine the best time to reload your widget.</li><li>Widgets viewed frequently receive more reloads</li><li>Environment changes The system will also force reloads for wherever a device environment changes.</li></ul><h3>App-driven reloads</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BYKDOCQl-TIzYPVW.png" /></figure><p>The system will determine the best time to reload your widget but there are also other events which may need you to ask the system for a reload from your app.</p><p>For example, your app may receive a background notification, or a user may make a change in the app itself.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*iBYOgv0IXeHO1q_2.png" /></figure><p>When receiving a background notification, you can user WidgetKit API via WidgetCenter to reload your timeline, which will wake your extension. And if your user makes a relevant change in your foreground app, you may also reload your timeline.</p><p>Be judicious with your foreground app reloads. Only reload your widget when a relevant change in the app has occurred which should reflected in you widget.</p><p>You can use WidgetCenter APIs from within your app process or extension to reload your timeline.</p><h3>WidgetCenter</h3><ul><li>reloadTimelines(ofKind:)</li><li>reloadAllTimelines</li><li>getCurrentConfigurations(completion:)</li></ul><h3>URLSession</h3><ul><li>Background sessions</li><li>onBackgroundURLSessionEvents</li><li>Batch requests to your server</li></ul><h3>Reloads</h3><ul><li>Background reloads are budgeted</li><li>Be efficient with how much processing and networking your widget requires.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*a4UKbcGRMTrW8fqK.png" /></figure><p>There are many ways to drive reloads to help keep your widget up-to-date. Think through the right experience for your kind of widget. And keep in mind how to be efficient with different ways to reload your timeline.</p><h3>Personalization and intelligence</h3><ul><li>Intents, which are used as a mechanism to allow a user to configure a widget</li><li>Relevance, which allows the developer to inform the intelligence in the stack.</li></ul><h3>How WidgetKit works</h3><ul><li>Intent frameworks Intents are all powered by the Intents framework.</li><li>Parameters Intents contains a set of parameters which are questions to ask the user. (ex. Weather’s configuration question is the location for which to return a forecast)</li><li>Used with Siri, Shortcuts, and now widgets</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rZoZVm7K_DPCeQG4.png" /></figure><p>The Stocks single symbol widget asks someone which stock to show. When the user tires to configure the widget, Intents can help answer this question by allowing Stocks to return the same list of stocks that are presented in the Stocks app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FLujcqXUw8714uOT.png" /></figure><p>What if someone wanted to show a stock that didn’t already exist in the main app?</p><p>Thanks to the power of Intents, we can actually drive this type of experience using the Intents dynamic options capability. So the user can search in the configuration UI and the system will fire up the Stocks Intents extension which can then return series of answers in the form of stocks symbols.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*M6uGGB_XqG-7uYrZ.png" /></figure><p>🆕New in iOS 14, Intents now support in-app Intent handling, where your app can answer these questions.</p><blockquote><em>What’s New in SiriKit and Shortcuts — WWDC20</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sgzTgHD9CRGuISx4.png" /></figure><p>Now we specify an IntentConfiguration instead of a StaticConfiguration and we specify an associated Intent.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7Cc9q2EXelV3Uco8.png" /></figure><p>Now evolves into the Provider conforming to the IntentTimelineProvider.</p><p>You will be passed in an Intent object, and based on the parameters in the Intent, you can generate a specific timeline.</p><p>The system can intelligently rotate to the most relevant widget and your app and widget can help feed this intelligence.</p><h3>Intelligence</h3><ul><li>Shortcuts donation When users perform actions in your app, your app can donate shortcuts. It your widget is backed by the same INIntent, then your widget may be rotated to in the stack when the user would have typically perform the action.</li></ul><blockquote><em>Add Configuration and Intelligence to Your Widgets — WWDC20</em></blockquote><ul><li>TimelineEntryRelevance Widget extension also has the ability to annotate timeline entries with relevance values.</li></ul><h3>TimelineEntryRelevance</h3><ul><li>score float value that you provide relative to all entries you have ever provided</li><li>duration time interval for when the particular entry is relevant</li><li>Relative to all entries you have ever provided</li></ul><p>When the time is appropriate and you feel your entry is the most relevant, then you may return a score and duration to inform the system to rotate to your particular widget.</p><h3>Wrap up</h3><ul><li>Widgets are not mini-apps</li><li>Glanceable</li><li>Timelines, reloads, and intelligence</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eaa10d5c27c8" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/meet-widgetkit-eaa10d5c27c8">Meet WidgetKit</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Get the most out of Sign in with Apple]]></title>
            <link>https://medium.com/swlh/get-the-most-out-of-sign-in-with-apple-e7e2ae072882?source=rss-9b8f5f9360bb------2</link>
            <guid isPermaLink="false">https://medium.com/p/e7e2ae072882</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[wwdc]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[wwdc20]]></category>
            <dc:creator><![CDATA[Jinha Park]]></dc:creator>
            <pubDate>Fri, 26 Jun 2020 17:35:43 GMT</pubDate>
            <atom:updated>2020-06-29T13:40:54.664Z</atom:updated>
            <content:encoded><![CDATA[<h3>Get the most out of Sign in with Apple</h3><blockquote><em>🗂WWDC2020 | Session : 10173 | Category : Privacy and Security</em></blockquote><blockquote><em>🔗 </em><a href="https://developer.apple.com/videos/play/wwdc2020/10173/"><em>https://developer.apple.com/videos/play/wwdc2020/10173/</em></a></blockquote><blockquote><em>🔖 Sign in with Apple makes it easy for people to sign in to your apps and websites with the Apple ID they already have. Fully integrate Sign in with Apple into your app using secure requests, and by handling state changes and server notifications. We’ll also introduce new APIs that allow you to let existing users switch to Sign in with Apple quickly and easily.</em></blockquote><blockquote><em>Related : Introducing Sign In with Apple — WWDC19 (</em><a href="https://github.com/HARlBO/WWDC/blob/master/WWDC2019/Introducing-Sign-In-with-Apple.md"><em>Introducing Sign In with Apple</em></a><em>)</em></blockquote><h3> Creating a secure request</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qaK0JenAXJg6cg4n.png" /></figure><p>These nonce and state properties will allow you to verify that the authorization and credential you get after executing a request are the ones you were expecting.</p><h3>Securing your request</h3><h4>Nonce</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ampMPSr_0QncmG8y.png" /></figure><p>The nonce is an opaque blob of data sent as a string in the request.</p><p>It is important to generate one unique nonce every time you create a new request as later on you will be able to verify this value.</p><p>This will allow you to verify this value in your server, helping prevent replay attacks.</p><h4>State</h4><p>The state value is also an opaque blob of data sent with the request.</p><p>Once key difference he has with the nonce value is that the state will be returned in the credential allowing you to locally match a credential to a request and verify this was generated from your application.</p><h4>Response Private email relay</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2_QoQYEgCl-iPIZP.png" /></figure><p>Example on how to get a credential from an authorization</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*46Nl9Pzyk_RIKQjW.png" /></figure><p>Inside of credential you will find properties containing the user information that you requested like name and email. You will also find important properties that will allow you to securely verify the request and create a session with your servers.</p><h3>Verifying Credentials</h3><h4>Response</h4><ul><li>Cache the objects locally It is important to cache the objects you need in case of the failure communicating with your server due to poor connectivity.</li><li>Verify the state value Make sure you verify the state value of the credential to be the same state value you previously generated.</li><li>Validate the information with Apple The response contains an authorization code an identity token. Send these values to your server where they can be decoded. Once decoded, verify the received information as well as session with Apple servers.</li></ul><p>How will the entry token will look when decoded by your server</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*fPPCR1MhFumFz3Q1.png" /></figure><ul><li>subject : A user identified that was returned to you on the authorization and will allow to create a session in your servers.</li><li>nonce : Verify these to be the same nonce you generated previously in the request. This will allow you to verify the authenticity of the authorization and help mitigate replay attacks.</li><li>real_user_status : 0 - unsupported, 1 - unknown, 2 - likely real</li></ul><h4>Identity token and authorization code</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2NG4rS0AG4vatBLd.png" /></figure><p>You can exchange the authorization code with the Apple ID servers. And when this is successful you will receive a refreshed token and an access token for future calls as well as a new identity token that should be identical to the one you already have.</p><p>You may verify a refresh token once a day to confirm that the user’s Apple ID on that device is still in good standing.</p><h3> Credential state changes</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lnOg2RfKgTfU-h7b.png" /></figure><p>getCredentialState API allows you to verify the current state of a credential by sending the currently stored user identifier.</p><p>It is important that this method is called every time your application is launched or changes to the foreground. That way you will be able to react on time to any changes in status and present the appropriate scheme in your application to your user.</p><ul><li>.authorized : You can fast track the user directly to your application and skip the login UI.</li><li>.revoked : The user decided to sign out of your application. In this scenario you should sign the user out of your application. Close your session and present the login screen</li><li>.notFound : This will be returned when there was no credential matching the user identifier. Present a login screen so that the user can authenticate your application.</li><li>🆕 .transferred</li></ul><h3>🆕 Transferred State</h3><ul><li>Ownership changed This will only be received by application that recently were transferred from one development team to another. (ex. after a company’s acquired)</li><li>User migration needed User identifiers are unique to a team. So when transferring ownership of an application, the existing user will need to be migrated to a new user identifier to match the new team.</li><li>Silent migration This migration is handled silently. This is without any user interaction and can be triggered calling the same API used to create a new account or logging the user.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PamSETNRv_PLh8eR.png" /></figure><p>We can validate the transfer state of the user and generate the new user identifier that will match the new team.</p><h3> Server notifications</h3><h3>🆕 Server to server developer notifications</h3><p>Listening to these notifications will allow you to monitor things like credential state changes right from your server as well as receive other types of events.</p><ul><li>Register You have to register your server endpoint on the Apple developer’s website.</li><li>JWT Event Events will be sent as JSON web tokens signed by Apple.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ER9cYgOJEDiirXRk.png" /></figure><p>The email-disabled event which you can get if a user has decided to stop receiving emails on their email relay. The email enabled event means that the user opted back into receiving email messages.</p><p>It is important to note that this event as well as the email disabled will only be sent when the user previously decided to use a private email relay for their account.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*eIcJ90n9d6hoOldV.png" /></figure><p>The consent-revoked event will be sent to you when a user decided to stop using their AppleID with your application and should be treated as a sign out by the user.</p><h3> Sign in with Apple Button</h3><h3>🆕 Swift UI support</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5cHxo1yBE5wi9gGK.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*w1Jh7mYPXpiog5_K.png" /></figure><p>onRequest : This is the right place to add the requested scopes like name and email and the nonce state values.</p><p>onCompletion : We will get the result of the request and handle the success or failure cases just as you would on the delegate methods for the authorization controller.</p><p>.signInWithAppleButtonStyle : We can also select the Button style.</p><h4>Styles</h4><ul><li>Black</li><li>White</li><li>White outline</li></ul><p>If you need to personalize the Sign in with Apple Button more to match the specific design of your website or application → a new online portal</p><h3>🆕 Online Button editor</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*C2PNot-v0AxXqTMN.png" /></figure><p><a href="https://appleid.apple.com/signinwithapple/button">https://appleid.apple.com/signinwithapple/button</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*UduOXvaKpSO1NQUv.png" /></figure><h3> 🆕 Upgrading to Sign in with Apple</h3><p>What about users that are already using a traditional username and password based account and don’t want to fork their current account?</p><ul><li>Secure It’s secure for both you and your users. Upgrading to Sign in with Apple is the easiest way to convert your accounts to two factor authentication.</li><li>Reduce complexity Account recovery is also a lot less complicated with Sign in with Apple.</li><li>Prevent duplicate accounts Utilizing this API will prevent the duplication of accounts.</li></ul><p>→ Users that are already using a traditional username and password based account won’t abandon their current account, they can just upgrade.</p><h3>Overview</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aeThkcTwwFH92dVz.png" /></figure><blockquote><em>One Tap Account Security Upgrades — WWDC20</em></blockquote><h3>Three flow for upgrades</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/438/0*bejC776t1VS5GvBw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/430/1*r2wURbV9LY8l5MSp3hSjHg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/442/0*sO2wWcJF6tmeIBVX.png" /></figure><ol><li>When security recommendations identifies a weak credential in the new password manager and settings.</li><li>When a user is interacting with your app utilizes password autofill and the selected credential is a weak credential.</li><li>When you invoke the new authentication services API via a user interaction that you specify within your app</li></ol><h3>ASAccountAuthenticationModificationViewController</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*akQV_zxtrKzgtIfh.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*W6FgphCodp5Rxnf9.png" /></figure><ul><li>convertAccountsToSignInWithAppleWithoutUserInteraction : Called initially by the extension hosting process in an attempt to upgrade the credential without user interaction.</li><li>viewDidLoad : This can be used to set up an intermediary user interface for the security step of flow if necessary. Providing intermediary UI to indicate progress might help provide the best user experience.</li><li>prepareInterfaceToConvertAccountToSignInWithApple : This is called just prior to your view appearing. It gets past the same ASPasswordCredential provided is a non user interaction flow.</li></ul><h3>Extension context</h3><ul><li>ASAccountAuthenticationModificationViewController Used to control the flow of the upgrade.</li><li>Authorization It has function to request Sign in with Apple authorization.</li><li>Request UI If you’re evaluating the credential or currently signed in account and determined that additional UI is needed to verify the account the extension context is used to request that the step up security UI is displayed.</li><li>Complete This removes the existing credential.</li><li>Cancel The extension context is also used in cases which you need to cancel the flow entirely.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jA9mrd2k-H83RAnz.png" /></figure><ul><li>getSignInWithAppleAuthorizationWithState : Displays the Sign in with Apple UI with your apps information asking the user to authorize the upgrade. Request in upgrade flows nonce and state is passed as a parameter to this call.</li><li>completeUpgradeToSignInWithApple : This lets the extension hosting process know that authorization completed successfully resulting in the removal of the password credential.</li><li>cancelRequest</li><li>userInteractionRequired : If your extension determines that additional UI needs to be shown to the user.</li><li>userCanceled : If your canceled while within your UI flow utilize that user cancelled ever.</li><li>failed : All other failures can use the failed error.</li></ul><h3>Account authentication modification extension</h3><h4>Prepare to convert without UI</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vi4UB96HltiWzBlZ.png" /></figure><ol><li>We begin the flow in the OS when toe user interacts with a weak credential and wants to upgrade that credential to Sign in with Apple.</li><li>Your account modification extension is initialized by the password managing process.</li><li>And the convert without UI function is called providing the password credential intended to be upgraded to Sign in with Apple.</li><li>The extension’s job is to evaluate the past credential to make sure it is valid prior to upgrading to Sign n with Apple (At this point checking too see if the username matches the currently signed in user is a good first course of action.)</li><li>The extension determined that the state of the signed in user and the pass credential requires a call to the server to verify the account.</li><li>The server verifies the credential and the authentication is a success.</li><li>The server then replies back to the extension confirming that the account is ready to be upgraded to Sign in with Apple.</li><li>The account is confirmed as authenticated and eligible for upgrade the extension context would be used to request the Apple ID credential.</li></ol><p>What would happen if there’s an issue with the account preventing an immediate upgrade?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*YKAaN0ttvPvLbpXu.png" /></figure><ol><li>Flow begins when the user interacts with a weak credential and wants to upgrade that credential.</li><li>Your account modification extension is then initialized by the password managing process.</li><li>Then the prepare to convert without UI function is called with the password credential.</li><li>The credential are then verified by the extension.</li><li>The extension calls it verify credential function which results in a call today extensions back end to validate the credential.</li><li>The server will attempt to verify the account with the request.</li><li>Sever determines that this account needs additional verification.</li><li>That reply comes back to the extension and the verified credential function evaluates this as a twoFactorAuthRequired.</li><li>This case is handled by using the extension context to call cancel with error with the user interaction required error.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*djAyLnaNrAf_g294.png" /></figure><p>verifyCredential<br>→ When the existing credential is verified one of these three values would get returned.</p><ul><li>.failure : Result for cases such as when the server attempts to validate the credential but the account or service date is not appropriate for converting the account at that time.</li><li>.success : This indicates that the account is ready to be converted right away.</li><li>.twoFactorAuthRequired : This means that we need to show some UI to the user. The credential alone is not enough to upgrade.</li></ul><h3>Request UI only if needed</h3><p>To avoid users having to do extra work in most cases where a user is already authenticated in your app.</p><h3>Converting with UI</h3><p>There could be circumstances where UI flows might be warranted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nsMlyYBhN8KZbRGn.png" /></figure><ol><li>After the extension contacts cancelled with the user interaction required error, the password managing process initializes a new instance of the account modification view controller</li><li>And calls it prepared to convert with your function. Passing the ASPasswordCredential. (At this point, the extension’s ViewController is presented providing Intermediary UI such as a spinning gear.)</li><li>Utilizing the same credentials as earlier with perhaps a slight change of context a request is made to the back end.</li><li>The server attempts to verify the account. Requires two F.A and sends a rely back to the extension.</li><li>The extension updates the view asking the user for two factor authentication.</li><li>The user provides the verification code which the extension would then verify.</li><li>If the user could not be verified at this point, the extension context would be used to cancel the flow with the failed error.</li><li>If the user provide a valid code and verification is a success, the extension is now ready to request the AppleID credential.</li></ol><h3>Upgrading account</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qkMJXAXGRmDNAVlQ.png" /></figure><ol><li>It is important to secure your request, to do so your extension would generate a state and nonce and pass them as parameters for the getAppleIDCredential call.</li><li>This results in an upgrade to Sign in with Apple UI being displayed to the user.</li><li>The user then authorizes using Face ID.</li><li>The AppleIDCredential is provided to the extension in the completion block of the getAppleIDCredential call.</li><li>The extension would then verify the credentials stay properly as being the same generated earlier.</li><li>The extension would them request an upgrade of the account providing the necessary account information and the AppleIDCredential to the server back end, so the account can be converted.</li><li>The back end would then exchange the authorization code with Apple servers verifying the value of the nonce in the identity token.</li><li>And if successful perform a conversion of the account.</li><li>After converting, it sends a reply back with a success value. It is important to note again that if the servers operation failed the extension contact should be used to call cancel with error with the failed error.</li><li>This time the server is indicating success. So the extension will perform any required bookkeeping and then call a complete upgrade to Sign in with Apple on the extension context.</li><li>This result in the password manager removing the existing credential and with that the flow is completed.</li></ol><p>Utilizing this API →</p><ul><li>Improving user security</li><li>Avoid confusion</li><li>Convenient</li></ul><p>ᵗʱᵃᵑᵏઽ ⠒̫⃝♡</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e7e2ae072882" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/get-the-most-out-of-sign-in-with-apple-e7e2ae072882">Get the most out of Sign in with Apple</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What’s New in Swift From WWDC 2020]]></title>
            <link>https://medium.com/better-programming/whats-new-in-swift-wwdc2020-4c112bbeb8fe?source=rss-9b8f5f9360bb------2</link>
            <guid isPermaLink="false">https://medium.com/p/4c112bbeb8fe</guid>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[wwdc]]></category>
            <dc:creator><![CDATA[Jinha Park]]></dc:creator>
            <pubDate>Wed, 24 Jun 2020 16:23:31 GMT</pubDate>
            <atom:updated>2020-06-27T00:38:18.551Z</atom:updated>
            <content:encoded><![CDATA[<h4>A detailed look at all that Apple unveiled this year</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*a065QVHxEyN6OP3BCIdXYg.png" /></figure><h3>Internal Benchmark: Binary Size</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-S3fIH4KBIMueDKF.png" /></figure><p>To track progress, we’ve been using a Swift rewrite of one of the apps that ships with iOS.</p><p>At each subsequent release, we narrowed the difference. With Swift 5.3, we’re down to below 1.5x the code size of the Objective-C version.</p><p>Different styles of applications, however, produce different binary sizes.</p><h3>MovieSwiftUI Binary Size</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2_RdA87fBcJaOFnG.png" /></figure><p>In Swift 5.3, there are significant improvements to the code size of SwiftUI apps. We see that its application-login code size is reduced by over 40%.</p><p>Now, binary size is essential for things like download times. But when you’re running the app, it’s part of what we call <em>clean memory.</em> That’s memory that can be purged because it can be reloaded when needed. So it’s less critical then <em>dirty memory, </em>the memory the application allocates and manipulates at runtime.</p><h3>Dirty Memory</h3><h4>Example of memory layout</h4><p><strong>Objective-C</strong></p><p>Swift’s use of value types has some fundamental advantages over reference type–based languages.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*h_wQ6W8fbjI09vOA.png" /></figure><p>In Objective-C, object variables are just pointers. So the array holds pointers to the model objects. Those objects, in turn, hold pointers to their properties. Every object you allocate has some overhead and performance and memory use.</p><p>This is so important that Objective-C has a special, small-string representation for tiny ASCII strings that allow them to be stored within the pointer, which saves on allocating the extra object.</p><p><strong>Swift</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*AUpb5oASaBNHSUp_.png" /></figure><p>Swift’s use of value types avoids the need for many of these values to be accessed via a pointer. Thus the UUIDs can be held within the Mountain objects, and Swift’s small string can hold many more characters, up to 15 code units, including non-ASCII characters.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dCTlKFHfd2k6bDXO.png" /></figure><p>Finally, all the Mountain objects can be allocated directly within the array storage. So with the exception of a few strings, everything is held within a contiguous block of memory. Swift programs can get a significant memory benefit from using value types like this.</p><h3>Heap Usage</h3><h4><em>400 model objects</em></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Ao2V-VPJcEe9IuU8.png" /></figure><p>So if we examine the heat memory used by an array of 400 of these model objects, we can see the Swift model data is more compact.</p><h4><em>Model and language/library overhead</em></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aRemZKclGy8KJzcW.png" /></figure><p>Some Swift programs previously still use more heat memory because of runtime overhead. Previously, Swift created a number of caches and memory on startup. These caches stored things like protocol conformists and other types of information as well as data used to bridge types over to Objective-C.</p><h4><em>Swift 5.3</em></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ToEYMWqdhYzf5XVS.png" /></figure><p>All language runtimes have some overhead, but in Swift’s case, it was too large. In Swift 5.3, that overhead has been cut way down to the point where the Swift version of the app now uses less than a third of the heat memory it did in last year’s release.</p><p>To get the full advantage of these improvements, an app’s minimum deployment target needs to be set to iOS 14.</p><p><strong>Lowering the Swift runtime in the userspace stack</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ygTeZwjzBqdEGqJ8.png" /></figure><p>In most applications, these differences aren’t often noticeable, but optimizing Swift’s memory like this was critical to push Swift further throughout Apple’s system — to be able to use it in demons and low level frameworks, where every byte of memory used counts.</p><p>Swift’s Standard Library now sits below Foundation in the stack. That means it can actually be used to implement frameworks that’ll float below the level of Objective-C where previously C had to be used.</p><h3>Diagnostics</h3><p>Errors and warnings from the compiler have vastly improved in this release cycle.</p><h4>New diagnostics subsystem in the Swift compiler</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*myw6edhP1Z3rS7Ue.png" /></figure><p>The Swift compiler has a new diagnostic strategy that results in more precise errors that point to the exact location in the source code where the problem is occuring. There are new heuristics for diagnosing the cause of issue that lead to actionable errors with guidance on how to fix issues.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*HW25F3elrIUixbgp.png" /></figure><p>Here’s an example of an incomprehensible diagnostic that the Swift 5.1 compiler would’ve produced in SwiftUI code a year ago.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*G0XTDhOgLN5Jjjrq.png" /></figure><p>Fast forward to today, and the diagnostic is significantly better with an error that tells you exactly what the problem is.</p><p>When diagnosing issue, the compiler internally also records more information about problems, so it now produces additional notes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*bsRKshaBdZqplsNw.png" /></figure><p>In this case, applying the fix naturally guides the developer into providing the missing pieces to an incomplete initialization of a TextField.</p><h3>Code Completion</h3><p>This covers everthing from the code-completion inference provided by the compiler in SourceKit and to the experience in the Xcode code editor.</p><h4>Improved type-checking inference</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GfvvQXTAbTarMnk_.png" /></figure><p>First, the inference of candidate completions has significantly improved. Here, the compiler is inferring the value in a ternary expression when used within an incomplete dictionary literal.</p><h4>Code completion: KeyPath as function</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7nEoPVcaNYX4VQZO.png" /></figure><p>Code completion also provides the values you’d expect for some of the more dynamic features of the language, such as using KeyPath as a function.</p><h4>15x faster code-completion speed compared to Xcode 11.5</h4><p>Besides the quality of completion results, code-completion performance has drastically improved, in some cases up to 15x.</p><h4>Code completion performance on SwiftUI code</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NtV3acKDADsr2AFj.png" /></figure><p>This is particularly beneficial for editing SwiftUI code.</p><h3>Code Indentation</h3><p>Code indentation in Xcode, also powered by the open-source SourceKit engine, has significantly improved.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*k1WG8ulfo771bg1E.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*huL3BMg-hYN4JQNF.png" /></figure><p>Here, you can see one of the improvements at work in SwiftUI code taken from the open-source MovieSwiftUI project. Before you’d sometimes get a natural indentation for some of the chained accesses.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6eJWlndddNGmB8Pf.png" /></figure><p>But now, they’re cleanly visually aligned. These and the other improvements will have a noticeable effect on your editing experience.</p><h3>Debugging</h3><h4>Better error messages for runtime failures</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1VqbrASUS0OxU_al.png" /></figure><p>When debug information is available, the debugger will now display the reason for common Swift runtime failure traps instead of just showing an opaque invalid instruction crash.</p><h4>Increased robustness in debugging</h4><p><strong>The pros and cons of using modules for debugging</strong></p><ul><li>LLDB uses Clangemodules to resolve types</li><li>LLDB can encounter different module failures than at compile time</li></ul><p>Swift imports APIs from Objective-C using Clang modules. To resolve information about types and variables, LLDB needs to import all Swift and Clang modules that are visible in the current debugging context.</p><p>While these module files have a wealth of information about types, since LLDB has a global view of the entire program and all of its dynamic libraries, importing Clang modules can sometimes fail in ways they wouldn’t at compile time — e.g., when the search pass from different dynamic libraries are in conflict.</p><h4><em>Using DWARF debug information for Objective-C types in Swift</em></h4><ul><li>LLDB now can resolve Objective-C types in Swift using debug information</li><li>Increases reliability of core debugging features, like Xcode’s variable view</li></ul><p>As a fallback, when this occurs, LLDB can now also import C and Objective-C types for Swift debugging purpose from DWARF debug information. This vastly increases the reliability of features such as the Xcode variable view and expression evaluator.</p><h3>Official Swift Platform Support</h3><ul><li>Apple platforms</li><li>Ubuntu 16.04, 18.04, 20.04</li><li>CentOS 8</li><li>Amazon Linux 2</li><li>Windows (coming soon!)</li></ul><p>With these efforts comes an increased opportunity to use Swift in more places.</p><h3>Swift on AWS Lambda</h3><p>Serverless functions are an easy way for client application developers to extent their applications into the cloud.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*WHstTo3VHewXYrBv.png" /></figure><p>It’s now easy to do this in Swift using the open-source Swift AWS runtime.</p><pre>import AWSLambdaRuntime</pre><pre>Lambda.run { (_, evnet: String, callback) in<br>	callback(.success(&quot;Hello, \(event)&quot;))<br>}</pre><p>The amount of code needed is as simple as writing “Hello, World!”</p><h3>Language and Libraries</h3><h4>Language</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uvSO5oW8cXLXVwal.png" /><figcaption><a href="http://apple.github.io/swift-evolution">Swift Evolution</a></figcaption></figure><h4>Multiple trailing closure syntax (SE-0279)</h4><pre>// Multiple trailing closure syntax</pre><pre>UIView.animate(withDuration: 0.3, animations: {<br>	self.view.alpha = 0<br>})</pre><pre>⬇️⬇️⬇️</pre><pre>UIView.animate(withDuration: 0.3) {<br>	self.view.alpha = 0<br>}</pre><p>Since its inception, Swift has supported something called trailing closure syntax that lets you pop the final argument to a method out of the parentheses when it’s a closure.</p><p>It can be more concise and less nested without the loss of clarity, making the call site much easier to read.</p><p>However, the restriction of trailing closure syntax to only the final closure has limited its applicability.</p><pre>UIView.animate(withDuration: 0.3, animations: {<br>	self.view.alpha = 0<br>}) { _ in<br>	self.view.removeFromSuperview()<br>}</pre><p>In this case, the trailing closure makes the code harder to read because its role is unclear. Worse, it changes meaning from the completion block at one call site to the animation block at another.</p><p>Concerns about call-site confusion have led Swift style guides to prohibit the use of trailing closure syntax when a method call, like this one, has multiple closure arguments.</p><pre>UIView.animate(withDuration: 0.3, animations: {<br>	self.view.alpha = 0<br>}, completion: { _ in<br>	self.view.removeFromSuperview()<br>})</pre><pre>UIView.animate(withDuration: 0.3) {<br>	self.view.alpha = 0<br>}<br>⬇️<br>UIView.animate(withDuration: 0.3, animations: {<br>	self.view.alpha = 0<br>}) { _ in<br>	self.view.removeFromSuperview()<br>}</pre><p>As a result, if we ever need to append an additional closure argument, many of us find ourselves having to rejigger our code more than may seem necessary.</p><p><strong>SE-0281</strong></p><pre>UIView.animate(withDuration: 0.3) {<br>	self.view.alpha = 0<br>}<br>⬇️<br>UIView.animate(withDuration: 0.3) {<br>	self.view.alpha = 0<br>} completion: { _ in<br>	self.view.removeFromSuperview()<br>}</pre><p>New to Swift 5.3 is multiple trailing closure syntax. This extends the benefits of trailing closure syntax to calls with multiple closure arguments, and there’s no rejiggering required to append an additional one.</p><p>Multiple trailing closure syntax is also a great fit for DSLs. SwiftUI’s new Gauge view is used to indicate the level of a value relative to some overall capacity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*oFtqhw4yAVgMHVZ9.png" /></figure><p>By taking advantage of multiple trailing closure syntax, Gauge is able to elegantly, progressively disclose is customization points.</p><p><strong>API design: trailing closure syntax</strong></p><pre>// API design : trailing closure syntax</pre><pre>extension Collection {<br>	func prefix(while predicate: (Element) -&gt; Bool) -&gt; SubSequence<br>}</pre><pre>message.body = &quot;Hello WWDC!\n--Kyle&quot;<br>let summary = message.body.prefix { !$0.isNewline }<br>assert(summary, &quot;Hello WWDC!&quot;</pre><p>A better name for <em>take</em> might be something like <em>prefix,</em> which suggests the result is anchored to the start of the collection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*AFYSbrm09PQolWMd.png" /></figure><p>It’s important that the base name with a method clarify the role of the first trailing closure because its label will be dropped even if it isn’t the first argument to the method.</p><h3>KeyPath Expressions as Functions (SE-0249)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DSs2YVQ9Io_Va4Xc.png" /></figure><p>Swift 4.1 saw the introduction of smart KeyPaths: types that represent uninvoked references to properties that can be used to get and set their underlying values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Zc8NNM4b_vQP2Yl3.png" /></figure><p>⬇️</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*98kXJZ2VDUQrPIyR.png" /></figure><p>When you’re designing an API, KeyPaths are a tempting alternative to function parameters if you expect the call site to be a simple property access because they’re more concise and less nested.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NoforG3R_PBOAr47.png" /></figure><p>⬇️</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_Ls9uusFkodPQir-.png" /></figure><p>You can use a KeyPath expression as a function. This means you can pass a KeyPath argument to any function parameter with a matching signature, and you can delete any duplicate declarations you may have added in the past in order to accept KeyPaths.</p><h3>@main (SE-0281)</h3><p>A tool for type-based program entry points.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Mq15oEjKpvTGukoo.png" /></figure><p>Since Swift 1.0, you’ve been able to use the UIApplicationMain attribute on your app delegate to tell the compiler to generate an implicit main.swift that runs your app.</p><p>In Swift 5.3, this feature has been generalized and democratized.</p><p>If you’re a library author, just declare a static main method on the protocol or superclass you expect your users to derive their entry point from.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*a7PS23ewdhRdpWqE.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ERzyxKdTu6t5ay9W.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*XvaE8jVfedcOOvaj.png" /></figure><p>This will enable your users to tag that type with @main and the compiler to generate an implicit main.swift on their behalf.</p><p>This standardized way to delegate a program’s entry point should make it easier to get up and running, whether you’re working on a command-line tool or an existing application.</p><h3>Increased Availability of Implicit ‘self’ in Closures (SE-0269)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uGz6H5MSeHY37g33.png" /></figure><p>In order to dray attention to potential retain cycles, Swift requires the explicit use of self in escaping closures which capture it.</p><p>But when you’re required to include many self dots in a row, it can start to feel a bit redundant.</p><p>In Swift 5.3, if you include self in the capture list, you can omit it from the body of the closure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*AOQUOYAfM93bgPlc.png" /></figure><p>You’re still required to be explicit about your intention to capture self. But now the costs of that explicitness is only a single declaration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8k9Zvcg_5eVGLgFC.png" /></figure><p>Sometimes, however, even a single use of self. can feel unnecessary — like in SwiftUI, where self tends to be a value type, making reference cycles much less likely.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*WIMQCrEoXvoDzu8b.png" /></figure><p>With Swift 5.3, if self is a struct or an enum, you can omit it entirely from the closure.</p><h3>Multipattern Catch Clauses (SE-0276)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kkOzmYv6_VGo1XNz.png" /></figure><p>Historically, do catch statements haven’t been as expressive as switch statements, leading folks to resort to nesting switches inside of catch clauses.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vfH1-DphSNs0Ck-Z.png" /></figure><p>In Swift 5.3, the grammar of catch clauses have been extended, providing for the full power of switch cases. This allows you to flatten the kind of multiclause pattern matching directly into the do catch statement, making it much easier to read.</p><h3>Enum Enhancements</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*J75v82MAKH-zs5pO.png" /></figure><p>Since Swift 4.1, the compiler’s been able to synthesize equatable and hashable conformance for a wide variety of types.</p><p>Sometimes, though, you run into situations where it’d be awfully convenient to have a comparison operator.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CJQzAKI9ADiWVlsL.png" /></figure><p>In Swift 5.3, the compiler has learned how to synthesize comparable conformance for qualifying enum types.</p><h4>Enum cases as protocol witnesses</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*tasbaxAiOSwc7LF3.png" /></figure><p>In Swift 5.3, enum cases can now be used to fulfill static var and static func protocol requirements.</p><h3>Embedded DSL Enhancements</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ri9qh9XqaYrpoEz7.png" /></figure><p>This included builder closures to collective use children and basic control flow statements like if/else.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*RufFF0UpfgHhfs9O.png" /></figure><p>In Swift 5.3, embedded DSLs have been extended to support pattern matching–control flow statements like if let and switch.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6V2Pe5m4vqsB4ota.png" /></figure><p>I’ve got a main window for my primary user interface and a preference window for my app settings.</p><p>Previously, to use DSL syntax at the top level of the body like this required tagging it with the specific builder attribute.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CPneBfl-xfeq6phy.png" /></figure><p>In Swift 5.3, the builder attribute will no longer be required because we’re teaching the complier how to infer it from the protocol requirement.</p><h3>SDK</h3><h4>Float16</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*l7xwfot6RR8O8iJb.png" /></figure><p>Float16 is an IEEE 754-standard floating-point format. Float16 takes just two bytes of memory, as opposed to a single precision float which takes four.</p><h4>Apple Archive</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*C8n5HDHpZ7LXa2eJ.png" /></figure><p>A new modular archive format based on the battle-tested technology Apple uses to deliver OS updates is here.</p><h4>Idiomatic Swift API</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pgY6aknsIbNd2MxF.png" /></figure><p>This includes a FileStream constructor, which leverage another new library, <a href="https://developer.apple.com/documentation/swift_packages/target/3197895-systemlibrary">Swift System</a>.</p><h4>Swift System</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xMa3kfNM883Guv_v.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NKblJYSuL_f3YW5P.png" /></figure><p>The raw, weakly typed interfaces imported though the Darwin overlay can be finicky and error-prone.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mJiyAenuTRIrN7MJ.png" /></figure><p>Swift System wraps these APIs using techniques such as strongly typed RawRepresentable structs, error handling, defaulted arguments, namespaces, and function overloading, laying the groundwork for a more idiomatically Swift system layer of the SDK.</p><h3>OSLog</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lGu1GX--GITw0E_G.png" /></figure><p>If you’re still using print as your logging solution, now is the perfect time to reconsider.</p><h3>Packages</h3><h4>Swift Numerics</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nD5SjWLBbG7vcFDB.png" /></figure><p>Swift Numerics’ complex numbers are layout-compatible with their C counterparts but faster and more accurate.</p><h4>Swift ArgumentParser</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8IgKb4VlQtOHvbfE.png" /></figure><p>A new open-source Swift package for command-line argument parsing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*94UjnZVMEpFPpLzB.png" /></figure><h4>Swift StandardLibraryPreview</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wo8pLvBq9omInjO9.png" /></figure><p>Now, you can provide the implementation for StandardLibrary feature proposal as a standalone SwiftPM package.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4c112bbeb8fe" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/whats-new-in-swift-wwdc2020-4c112bbeb8fe">What’s New in Swift From WWDC 2020</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Efficient Interactions with Frameworks]]></title>
            <link>https://medium.com/@jjuou2/efficient-interactions-with-frameworks-5a1bcf56f3bb?source=rss-9b8f5f9360bb------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a1bcf56f3bb</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[wwdc]]></category>
            <category><![CDATA[framework]]></category>
            <dc:creator><![CDATA[Jinha Park]]></dc:creator>
            <pubDate>Mon, 25 May 2020 15:34:10 GMT</pubDate>
            <atom:updated>2020-05-25T15:34:10.774Z</atom:updated>
            <content:encoded><![CDATA[<h3>Efficient Interactions with Frameworks</h3><blockquote><em>📅 2020.5.25 (MON)</em></blockquote><blockquote><em>WWDC2017 | Session : 244 | Category : App Frameworks</em></blockquote><p>🔗 <a href="https://developer.apple.com/videos/play/wwdc2017/244">Efficient Interactions with Frameworks — WWDC 2017 — Videos — Apple Developer</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6GHwVT6IDV8jHo_0.png" /></figure><p>There are multiple dimensions, how can we visualize this a little bit better?</p><h3>Ⅰ</h3><ul><li>If you’re looking at a lot of data and code that runs very frequently.</li><li>These are going to be things that are going to be likely to be able to make a notable impact upon performance.</li><li>You’re going to want to spend time optimizing these cases.</li></ul><h3>Ⅲ</h3><ul><li>If you’re looking at something that works just a little bit of data and runs just a few times.</li><li>You don’t really want to spend a whole lot of time worrying about them too much.</li></ul><h3>Ⅱ, Ⅳ</h3><ul><li>That are highly dependent upon the situation.</li><li>You’ll most certainly want to be able to measure the performance in a scenario that reflects actual usage.</li><li>Use that information to be able to evaluate whether it’s worth your time to be able to make changes.</li></ul><h3>Improvements in Foundation</h3><p>NSCalendar</p><ul><li>Date enumeration, not only to use less memory, but also, it’s much faster too.</li><li>Implementation is not only faster, but also, corrects some outstanding Edge case that have been lurking around for a while.</li></ul><p>Internal locking improvements</p><ul><li>Migrate to using Atomics and OS and Fairlock, which in the end, ends up playing a lot better with quality of service.</li></ul><p>NSOperation and NSOperationQueue</p><ul><li>More correct implementation, whenever it comes to their quality of service.</li><li>Neat performance improvements, 25% improvement on queueing operation.</li></ul><p>Copy on write collections</p><ul><li>A number of collection types will now use copy on write as their backing storage.</li></ul><h3>Copy on Write Collections</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lXqlo9vYBkHyUEiv.png" /></figure><p>COW is a mechanism, where two items can point to a shared backing store until a mutation occurs. And when that mutation happens, the mutation party copies that backing storage to be albe to allow for the write to happen.</p><p>→ Copying isn’t costly, anymore.</p><p>This means that whenever you defensively copy a mutable container, it’s almost free</p><ul><li>before : copies of collections were at best, linear execution time.</li><li>now : whenever you copy them, they’re constant until a shared mutation.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5LhBNqwT4vweWDp1.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ZfHp3QB9021GIC1O.png" /></figure><ul><li>Sine copies are nearly free, we can do the same thing every single time and not worry about the performance hit.</li><li>You can defensively copy return values so that it does the right thing without having worry about the performance costs.</li></ul><h3>Data</h3><blockquote><em>The best types for dealing with bytes</em></blockquote><p>Data is its own slice</p><p>Indexing is only a few instructions in optimized builds</p><p>Appending is dramatically faster</p><p>Replacing region is faster too</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gyrZvlhEzl8Z26HM.png" /></figure><p>→ Since data is a common currency of dealing with a collection of bytes, this should be really fast.</p><p>And if you were using Data, you get this advantage for free. And it will also be able to interoperate with all the rest of the APIs that take and use data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dCpnNwM3ipMLEqyf.png" /></figure><h3>Bridges and how the affect your app</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GAowO3aY98iTSODm.png" /></figure><p>Toll-free bridging</p><ul><li>Zero cost at the cast</li><li>The NSArray being bridged to a CFArray, it&#39;s just a reinterpretation of a pointer.</li><li>There is a slight cost to be paid, whenever you pass hat object to CFArrayGetCount</li></ul><p>Swift bridges</p><ul><li>Cost in these particular cases are paid in advance.</li><li>These are then normal costs at the usage.</li></ul><h3>Strings, ranges, and text</h3><p>Invest in performance that matters to your users</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GuPy566rtWQ6DwYY.png" /></figure><h3>String bridging</h3><blockquote><em>Example 1 : </em><em>UILabel</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*w8Si3lNGinPR9vT0.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aukneBRpql3toH9_.png" /></figure><p>The NSString form the framework is a reference type, while Swift&#39;s String is value type.</p><p>And so, when ask the framework for that NSString, it&#39;s wrapped in the value type when it crosses the Swift bridge.</p><p>To preserve Swift value semantics, the framework has to make a copy of it.</p><p>In this case, the original NSString is immutable, so when the framework makes that copy, it&#39;s optimized to just retain, which is pretty cheap. It&#39;s just incrementing the ref count.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*OXGzAmljXQFmNQ47.png" /></figure><p>In this case, the original string consisted of seven ASCII characters. So, even if we make a full copy the impact would be pretty small.</p><p>Most of the time UILables are going to consist of short strings that are used for UI display purpose, so you&#39;re probably not going to be fetching their text very frequently. → Ⅲ</p><blockquote><em>Example 2 : </em><em>NSTextStorage</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KMY3i9cdOn8uS6YH.png" /></figure><p>Since NSTextStorage is intended for working with text editing, it&#39;s reasonable to expect the contents of that textStorageto be mutated frequently.</p><p>And contents of the textStorage could also be a very long string.</p><p>So for efficiency , the framework only keeps the mutable string around. So, when you ask for that string property on the text storage, what you’ll get is going to be backed by an NSString that refers to the mutable string.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vEBOtkCDU7kf7T0R.png" /></figure><p>Just as before, it will be wrapped in the value type when it crosses the bridge, because it’s an NSString</p><p>And the framework is going to make a copy. But NSString is mutable, so this copy could be expensive.</p><p>And textStorage is much more likely to contain long length strings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*B0JOZRYZ8-DhjJRY.png" /></figure><p>NSMutableString is a reference type that is not bridged. There is no copy. So we avoid cost of copy.</p><p>This situation results from a mismatch between Swift’s value semantics and the design of NSTextStorage, which needs to use reference semantics for performant management of large amounts of text.</p><p>If you working with large amounts of text and the text storage, use mutableString to access it even if you don&#39;t plan to mutating it.</p><p>How much text do you expect that storage to contain?</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*b31hiO4ynbDLRrXWEFF4aQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*b31hiO4ynbDLRrXWEFF4aQ.png" /></figure><p>→ If you use the string property, that&#39;s probably fine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/0*-9SAlo4-BOi0k2uc.png" /></figure><p>→ Consider using mutableString.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Vs_jXU6mCvsbwF8u.png" /></figure><p>→ Really hope you’re using mutableString</p><h3>Ranges</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nxxVm36biNDzsPBA.png" /></figure><blockquote><em>Example 1 : Working with </em><em>NSAttributedString</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*HJsKO9-vBjJb0VsZ.png" /></figure><p>🆕⬇️</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4oT0io-lVLaiwiOz.png" /></figure><blockquote><em>Example 2 : Working with </em><em>NSRegularExpression</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*YInMNMxrBzuxyoY0.png" /></figure><p>We want to print out all the start tags. In order to do this, we’ll use NSRegularExpression to find the tags we went, and then append them to a string.</p><p>But the NSRegularExpression API gives me NSRange back from my match groups.</p><p>And I need ranges of string index to be able to append to my Swift string.</p><p>Convert from NSRange to range a string index.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xKbABMFouyvvQnaD.png" /></figure><p>🆕⬇️</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*YF9xAOQHwQOdDmrN.png" /></figure><h3>Text layout and rendering</h3><p>Text poses some real performance challenges, because of its ubiquity in scale.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8brxwagRpQWwVhjb.png" /></figure><p>Factors that our frameworks take into account when we perform text layout and rendering.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*oIvFG1Evor5V_ELB.png" /></figure><p>We look all of these things and more to render your text in a way that’s both correct and performant.</p><p>→ So, I encourage you to use the standard label controls whenever possible.</p><blockquote><em>Example 1 : A Tale of Two Labels</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*g-Q8KO3mBQuweAdZ.png" /></figure><p>She set up her labels with attributed strings and off she went but noticed that the scrolling performance in her app was a little bit slow. So she rendered each line in a separate label, her app scrolling performance improved.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7wTOphL-CqTuXEbS.png" /></figure><p>But when she tested her app with Chinese text, she discover that the scrolling performance was even slower than before.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*yr7_l4PtP-NHcsGK.png" /></figure><p>Postmortem</p><ul><li>Initial conditions qualified for fast rendering path within the framework The optimization of splitting each line into its own label took advantage of the fact that attributed strings containing only one style of text may qualify for faster rendering. But this isn’t sufficient condition for faster rendering.</li><li>Input changes forced rendering to slower path Splitting the two line strings into separate labels, meant that the app was rendering twice as many labels as it needed to.</li><li>App used older layout practices by manually setting the frames, instead of using auto layout</li></ul><p>What You can do</p><p>🛠 Higher-level strategy</p><ul><li>Use standard label controls</li><li>The framework is in a better place to apply these optimizations, because it has a bigger picture view of the situation and more information about the rendering conditions</li><li>And when we make performance improvements, you’ll automatically get those benefits. 3x faster rendering with NSTextField in mackOS 10.13</li><li>Use modern layout practices like auto layout</li><li>Text layout and rendering performance with modern practices is very heavily scrutinized on our end.</li><li>You’ll be less likely to run into edge case performance scenarios that we haven’t already seen and improved</li></ul><p>🛠 Lower-level tips</p><ul><li>Set rendering attributes for attributed strings</li></ul><pre>let attributes: [NSAttributedStringKey: Any] = [ .font: UIFont.systemFont(ofSize: systemFontSize), .paragraphStype: NSParagraphStyle.default, .foregroundColor: UIColor.darkText] let myString = NSStringAttributedString(string: “Hello”, attributes: attributes)</pre><ul><li>If you don’t supply these attributes yourself, the text system needs to resolve them in order to be able to render</li><li>You can shave off a little bit of time by supplying these attributes yourself, when rendering attributes strings.</li><li>Specify alignment and writing direction if known</li></ul><pre>// Only do this if you’re absolutely sure your text doen’t have mixed directions var myParagraphStype = NSMutableParagraphStyle() myParagraphStype.baseWritingDirection = .leftToRight myParagraphStype.alignment = .left</pre><ul><li>You might see some small improvements from explicitly specifying the writing direction and alignment, instead of using the natural settings.</li><li>And this will save you a little time, because the text system can skip over any logic that tries to figure out the writing direction and alignment. But remember that you’ll only want to do this if you’re absolutely sure that your input data won’t contain mixed writing directions.</li><li>Use clipping line break mode for single line labels</li></ul><pre>// Only do this if you’re sure your text doesn’t require wrapping var myParagraphStype = NSMutableParagraphStyle() myParagraphStype.lineBreakingMode = .byClipping</pre><ul><li>By default, labels will use word wrap.</li><li>When you do this, the text system needs to figure out where to place the line breaks.</li><li>You can skip this line breaking and hyphenation logic, and your text might run there just a little bit faster</li><li>Summary</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gH1tXBmamfRuRzWD.png" /></figure><ul><li>Use the concepts of scale and frequency to minimize the large expense of operation in your code</li><li>Don’t sweat the small infrequent stuff</li><li>Always measure if you aren’t sure</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a1bcf56f3bb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introducing Sign In with Apple]]></title>
            <link>https://medium.com/@jjuou2/introducing-sign-in-with-apple-52f3e5a24c4f?source=rss-9b8f5f9360bb------2</link>
            <guid isPermaLink="false">https://medium.com/p/52f3e5a24c4f</guid>
            <category><![CDATA[apple]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[wwdc]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Jinha Park]]></dc:creator>
            <pubDate>Thu, 05 Mar 2020 17:35:00 GMT</pubDate>
            <atom:updated>2020-03-05T17:35:00.172Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introducing Sign In with Apple</h3><blockquote><em>📅 2020.3.4 (THU)</em></blockquote><blockquote><em>WWDC2019 | Session : 706 | Category : Privacy and Security</em></blockquote><p>🔗 <a href="https://developer.apple.com/videos/play/wwdc2019/706/">Introducing Sign In with Apple - WWDC 2019 - Videos - Apple Developer</a></p><h3>Introducing Sign In with Apple</h3><blockquote><em>📅 2020.3.4 (THU)</em></blockquote><blockquote><em>WWDC2019 | Session : 706 | Category : Privacy and Security</em></blockquote><p>🔗 <a href="https://developer.apple.com/videos/play/wwdc2019/706/">Introducing Sign In with Apple — WWDC 2019 — Videos — Apple Developer</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3-sOym82dQisqwuJ.png" /></figure><h3>Fast, easy account setup and sign in</h3><p>It’s secure and it’s private, both for your users and for your privacy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dBD1RMCprX9BKShG.png" /></figure><ul><li>The user can make a choice on which email they want to share.</li><li>Your app gets a unique, stable ID, a name and a verified email address.</li><li>Secure two-factor authenticated account</li></ul><h3>Sign In with Apple</h3><ul><li>Streamlined a count setup Users downloaded your app from the App Store using Apple ID already. And Sign In with Apple helps them engage fully with just a tap in your app.</li><li>Verified email addresses</li><li>hide my email options enable these users to share a hidden email address that routes to to their verified email inbox.</li></ul><blockquote>jinha@gmail.com → r45N934br1@privaterelay.appleid.com</blockquote><ul><li>Hide My Email</li><li>Linked to verified email</li><li>Two-way relay</li><li>Any email communication</li><li>Apple does not retain messages</li><li>Built-in security No password, two-factor authentication, no cost to you and no added friction to the user</li><li>Anti-fraud</li><li>Privacy friendly</li><li>On-device intelligence</li><li>Account information</li><li>Abstracted to a single bit</li><li>Cross-platform</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VKrqA5BObCXZuBa-.png" /></figure><h3>Integrating with Your App</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*i3Zmk9d4C5qGSyqs.png" /></figure><h3>Button</h3><pre>func setUpProviderLoginView() {<br>    	let button = ASAutoriationAppleIDButton() <br>    	button.addTarget(self, action #selector(handleAuthorizationAppleIDButtonPress, for: .touchUpInside)<br>    	self.loginProviderStackView.addArrangedSubview(button)<br>    }</pre><h3>Authorization</h3><pre>@objc func handleAuthorizationButtonPress() {<br>    	let request = ASAuthorizationAppleIDProvider().createRequest()<br>    	request.requestedScopes = [.fullName, .email]<br>    <br>    	let controller = ASAuthorizationController(authorizationRequests: [request])<br>    <br>    	controller.delegate = self<br>    	controller.presentationContextProvider = self<br>    <br>    	controller.performRequests()<br>    }</pre><p>Optionally, if your ares this for the best user experience, you can set requestedScopes for full name and email. You should only request this information if it’s truly required for your app and err on the side of minimum amount information.</p><pre>func autorizationController(controller _: ASAutorizationController, didCompleteWithAuthorization authorization: ASAutorization) {<br>    	if let credential = authorization.credential as? ASAuthorizationAppleIDCredential {<br>    		let userIdentifier = crendtial.user<br>    		let identityToken = credintial.identifyToken<br>    		let authCode = crendtial.authorizationCode<br>    		let realUserStatus = crential.realUserStatus<br>    <br>    		// Create account in your system<br>    		}<br>    }<br>    <br>    func authorizationController(_: ASAuthorizationController, didCompletedWithError error: Error) {<br>    	// Handle error<br>    }</pre><p>Both of these delegate callbacks are guaranteed to be made on your app’s main queue.</p><h3>Sign In</h3><blockquote><em>Response</em></blockquote><p>User ID</p><ul><li>Unique, stable, team-scoped user ID</li><li>→ You can use it to retrieve information from your user systems across different platforms, different systems, the web, Android. It remains stable across all of them.</li></ul><p>Verification data</p><ul><li>Identity token, code</li><li>→ A short-lived token that you can use with Apple ID servers to exchanges for a refresh token.</li></ul><p>Account information</p><ul><li>Name, verified email</li></ul><p>Real user indicator</p><ul><li>High confidence indicator that likely real user</li></ul><h3>Handle Session Changes</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*YOCXLo0Wfegb33YC.png" /></figure><pre>let provider = ASAuthorizationAppleIDProvider() <br>    <br>    provider.getCredentialState(forUserID: &quot;currnetUserIdentifier&quot;) { (credentialState, error) in<br>    	switch credentialState {<br>    	case .authorized:<br>    		// Apple ID Credential is valid<br>    	case .revoked:<br>    		// Apple ID Credintial revokec, handle unlink<br>    	case .notFound:<br>    		// Credential not found, show login UI<br>    	defualt: break<br>    	}<br>    }</pre><p>This API is very fast. You should call it on your app&#39;s launch to make sure that you provide a tailored experience for each of these states.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*onwvT5IyuQkfXsNf.png" /></figure><p>We expose a notification through NotificationCenter to let you know when this credential sate changed to revoked.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_jA8Aru_WUDVx_Jg.png" /></figure><pre>// Prepare requests for both Apple ID and password providers/<br>    	let request = [ASAuthorizationAppleIDProvider().createRequest(),<br>    							  ASAuthorizationPasswordProvider().createRequest()]<br>    <br>    	// Create an authorization controller iwth the given request/<br>    	let authorizationController = ASAuthorizationController(authorizationRequests: requests)<br>    	authorizationController.delegate = self<br>    	authorizationController.presentationContextProvider = self<br>    	authorizationController.performRequests()<br>    }</pre><pre>func authorizationController(controller: _: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) {<br>    	switch autorization.credential {<br>    	case let credential as ASAuthorizationAppleIDCredential:<br>    		let userIdentifier = crendtial.user<br>    		// Sign the user in using the Apple ID credential<br>    	case let credential as ASPasswordCredential:<br>    		// Sign the user in using their exisiting password credential<br>    	default: break<br>    	}<br>    }</pre><h3>Cross-Platform</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pSILq4I-dEbX4MjG.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3a2C8_74W8lCjUhs.png" /></figure><h3>JavaScript SDK</h3><ul><li>Include</li></ul><pre>&lt;script src=&quot;https://appleid.cdn-apple.com/appleauth/static/ jsapi/appleid/1/en_US/appleid.auth.js&quot;&gt;</pre><ul><li>Button</li></ul><pre>&lt;div id=&quot;appleid-signin&quot;&gt;&lt;/div&gt;</pre><ul><li>Configure</li></ul><pre>AppleID.auth.init({<br>    	clientId : &#39;com.example.webapp&#39;,<br>    	scope : &#39;name email&#39;,<br>    	redirectURI: &#39;https://example.com/redirectUri&#39;, state : &#39;state&#39;<br>    });</pre><ul><li>Result</li></ul><pre>POST /redirectUri</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*L-gkrIOFAsk92ab8.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*P6IlZgZpBziroC1o.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=52f3e5a24c4f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mysteries of Auto Layout, Part 2]]></title>
            <link>https://medium.com/@jjuou2/mysteries-of-auto-layout-part-2-39a0bc79fbd9?source=rss-9b8f5f9360bb------2</link>
            <guid isPermaLink="false">https://medium.com/p/39a0bc79fbd9</guid>
            <category><![CDATA[swif]]></category>
            <category><![CDATA[uiki]]></category>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[wwdc]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Jinha Park]]></dc:creator>
            <pubDate>Thu, 06 Feb 2020 17:44:26 GMT</pubDate>
            <atom:updated>2020-02-06T17:44:26.403Z</atom:updated>
            <content:encoded><![CDATA[<h3>Mysteries of Auto Layout, Part 2</h3><blockquote><em>📅 2020.2.6 (THU)</em></blockquote><blockquote><em>WWDC 2015 | Session : 219 | Category : UI Frameworks</em></blockquote><p>🔗 <a href="https://developer.apple.com/videos/play/wwdc2015/219/">Mysteries of Auto Layout, Part 2 — WWDC 2015 — Videos — Apple Developer</a></p><h3>The Layout Cycle</h3><blockquote><em>Mystery #7</em></blockquote><h3>Inside the Black Box</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0Ftju97RbC8rce1o.png" /></figure><h3>The Layout Cycle</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*AYV0ODPdSwP8xdw-.png" /></figure><p>High-level overview of the process</p><ol><li>Application run loop cheerfully iterating</li><li>until the constraints change in such a way that the calculated layout needs to be different.</li><li>This causes a deferred layout pass to be scheduled.</li></ol><p>When that layout pass eventually comes around, we go through the hierarchy and update all the frames for the views.</p><h3>Constraint Changes</h3><p>Changes to constraint expressions</p><ul><li>Activating or deactivating</li><li>Setting the constant or priority</li><li>Adding or removing views</li></ul><p>Engine recomputes the layout</p><ul><li>Engine variables receive new values These expressions are made up of variables that represent things like the origin or the size of a particular view.</li><li>Views call superview.setNeedsLayout()</li></ul><h3>Deferred Layout Pass</h3><ul><li>Reposition misplaced views</li><li>Two passes through the view hierarchy</li><li>Update constraints</li><li>Reassign view frames</li></ul><blockquote><em>updateConstraints</em></blockquote><p>Request via setNeedsConstraints()</p><p>→ Then some time later your update constraints method will be called.</p><p>Really, all this is a way for views to have a chance to make changes to constraints just in time for the next layout pass, but it’s often not actually needed.</p><p>Often not needed</p><ul><li>Initial constraints in IB All of your initial constraint setup should ideally happen inside Interface Builder. Or if you really find that you need to allocate your constraints programmatically, some place like viewDidLoad is much better.</li><li>Separate logic is harder to follow</li></ul><p>Implement it when</p><ul><li>Changing constraints in place is too slow It turns out that changing a constraint inside updateConstraint is actually faster than changing a constraint at other times. Because the engine is able to treat all the constraint changes that happen in this pass as a batch. This is the same kind of performance benefit that you get by calling activate constraints on an entire array of constraints as opposed to activating each of those constraints individually.</li><li>A view is making redundant changes It’s efficient to have the view just call setNeedsUpdateConstraints and then when the update constraints pass comes along, it can rebuild its constraints once to match whatever the configuration is.</li></ul><blockquote><em>layoutSubviews aka layout</em></blockquote><p>Traverse the view hierarchy, top-down</p><ul><li>Call layoutSubviews() (or layout() on OS X) The purpose is for the receiver to reposition its subviews.</li></ul><p>Position the view’s subviews</p><ul><li>Copy subview frames from the layout engine</li></ul><p>Override layoutSubviews() for custom layout</p><ul><li>…but be careful!</li></ul><blockquote><em>Overriding layoutSubviews</em></blockquote><p>Override when constraint are insufficient</p><p>Some views have already been laid out</p><p>Do</p><ul><li>Invoke super.layoutSubviews()</li><li>Invalidate layout within your subtree you should do that before you call through to the superclass implementation.</li></ul><p>Don’t</p><ul><li>Call setNeedsUpdateConstraints() There was an update constraints pass. We missed it. If we still need it now, it&#39;s too late.</li><li>Invalidate layout outside your subtree It can be very easy to cause layout feedback loops where the act of performing layout actually causes the layout to be dirtied again.</li><li>Modify constraints indiscriminately</li></ul><p>Remember</p><ul><li>Don’t expert frames to change immediately</li><li>Proceed with caution when overriding layoutSubviews()</li></ul><h3>Interacting with Legacy Layout</h3><blockquote><em>Mystery #8</em></blockquote><p>Positioning by frame versus constraints</p><p>Sometimes you need to set the frame</p><ul><li>e.g., if you’re overriding layoutSubviews()</li></ul><pre>var translatesAutoresizingMaskIntoConstraints: Bool</pre><h3>translatesAutoresizingMaskIntoConstraints</h3><p>Setting the frame automatically generates constraints</p><p>→ that enforce that frame in the Layout Engine</p><ul><li>Set the frame with gleeful abandon!</li><li>Constraints implement the autoresizingMask</li><li>Other views can be constrained to it</li></ul><p>Set to false when using constraints</p><ul><li>Beware-defaults to true for programmatically created views</li></ul><h3>Constraint Creation</h3><blockquote><em>Mystery #9</em></blockquote><h3>Layout Constraint Creation</h3><blockquote><em>🆕 Layout anchors</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wy-x-InAgtmxazwg.png" /></figure><h3>Constraining Negative Space</h3><blockquote><em>Mystery #10</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qAY3uwRmOJtr9kPP.png" /></figure><h3>🆕 NSLayoutGuide / UILayoutGuide</h3><ul><li>UILayoutGuide represents a rectangle in the layout engine</li><li>Cosntrain just like a view</li></ul><pre>let guide = UILayoutGuide()<br>    view.addLayoutGuide(guide)</pre><ul><li>Layout anchors are not available for margins</li><li>UIView now exposes layoutMarginsGuide → represents area of the view inside the margins.</li></ul><pre>var layoutMarginsGuide: UILayoutGuide</pre><h3>Debugging Your Layout</h3><blockquote><em>Mysteries of Auto Layout, part 2</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*e-Qzk6ww0A9JVObI.png" /></figure><h3>Unsatisfable Constraints</h3><blockquote><em>Mystery #11</em></blockquote><h3>Unsderstanding the Log</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Illt9Sg1bfb8bHIK.png" /></figure><p>Adding identifiers</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*s6UxvrczA0IQsXwv.png" /></figure><p>Tips</p><ul><li>Set accessibility identifiers</li><li>Identifies vies in logs</li><li>Set identifiers on layout guides</li><li>Add as you go</li><li>View one axis at a time</li><li>constraintsAffectingLayoutForAxis: on iOS</li><li>constraintAffectingLayoutForOrientation: on OS X</li></ul><h3>Understanding the Log</h3><ul><li>Start from the bottom</li><li>Check translatesAutoresizingMaskIntoConstraints</li><li>Set identifiers</li><li>Use constraintsAffetctingLayoutForAxis:</li></ul><h3>Resolving Ambiguity</h3><blockquote><em>Mystery #12</em></blockquote><p>Why doen’t my layout look right?</p><p>→ Possible causes</p><ul><li>Too few constraints</li><li>Conflicting priorities</li></ul><p>Diagnostic tools</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2pD9fz7VQ0IcfiD4.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hDtJzztFjseJWoZK.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*RpAqg88UMsPmNPOJ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*F7TGZKsSYiGgvOTm.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2ZoePhURfsKdskmK.png" /></figure><h3>Debugging Your Layout</h3><p>Think about what information the engine needs</p><p>Use the logs when constarints are unsatisfiable</p><ul><li>Add identifiers for constraints and views</li></ul><p>Check for ambiguity regularly</p><p>Use tools to help resolve issues</p><ul><li>Icons in Interface Builder</li><li>View debugger</li><li>Methods in lldb</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=39a0bc79fbd9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mysteries of Auto Layout, Part 1]]></title>
            <link>https://medium.com/@jjuou2/mysteries-of-auto-layout-part-1-b22ce12feb7a?source=rss-9b8f5f9360bb------2</link>
            <guid isPermaLink="false">https://medium.com/p/b22ce12feb7a</guid>
            <category><![CDATA[wwdc]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[uikit]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Jinha Park]]></dc:creator>
            <pubDate>Wed, 05 Feb 2020 01:30:34 GMT</pubDate>
            <atom:updated>2020-02-05T01:30:34.903Z</atom:updated>
            <content:encoded><![CDATA[<h3>Mysteries of Auto Layout, Part 1</h3><blockquote><em>📅 2020.2.4 (TUE)</em></blockquote><blockquote><em>WWDC 2015 | Session : 218 | Category : UIKit</em></blockquote><p>🔗 <a href="https://developer.apple.com/videos/play/wwdc2015/218/">Mysteries of Auto Layout, Part 1 — WWDC 2015 — Videos — Apple Developer</a></p><h3>Maintainable Layouts</h3><blockquote><em>Mystery #1</em></blockquote><h3>Constraints</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*YIgzHgPUCMvHaMOU.png" /></figure><h3>Stack View</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0YPJqCCIokeSfAv0.png" /></figure><ul><li>Built with Auto Layout</li><li>Manages constraints</li><li>Horizontal or vertical</li></ul><h3>Alignment</h3><ul><li>Horizontal StackView</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*joPAfSlbf6afoaq_.png" /></figure><ul><li>Vertical StackView</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2aESBBPdbOYiBfuQ.png" /></figure><h3>Distribution</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*oRL2lNPQHfb3JrMc.png" /></figure><p>This allows you to distribute along the axis, and you can do some pretty complex distribution behaviors without having to deal with any constraints.</p><ul><li>Fill : filling the stack view.</li><li>Fill equally, Fill Proportionally : based on content size of the subviews</li><li>Equal Spacing</li></ul><h3>Animate</h3><p>Animation is really easy on stack view</p><pre>UIView.animate(withDuration: 1) {<br>    	self.subviewToHide.hidden = !self.subviewToHidden.hidden<br>}</pre><h3>API</h3><p>It’s simple, familiar, straightforward .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9qCBfEKIbUcODeqb.png" /></figure><p>arrangedSubviews :</p><p>This property returns you a subset of all of the views that are owned by the stack view. It returns you the view that are currently being stacked.</p><p>What that implies is that you can have views that are not being stacked by StackView, such as decorators or overlay, and have a clean view hierarchy, and we think you will find that useful.</p><h3>Stack View in Interface Builder</h3><ul><li>Easy to build</li><li>Easy to maintain</li><li>Composable Stack Views</li><li>Lightweight</li></ul><p>→ Stack view is about layout and therefore it doesn’t need to render its own background, we’ve been able to do some optimizations. So we have a special Transform Layer class that doesn’t render on its own that can make Stack View run fast and even more performant than your regular views.</p><h3>Before and After</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DqgPQEbY9bkqDRj9.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*eK01RNpYyfwRcZ9z.png" /></figure><h3>Feeding the Layout Engine</h3><blockquote><em>Mysteries of Auto Layout, part 1</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_RjYcG5dAMLa3ky8.png" /></figure><h3>Changing Constraints</h3><blockquote><em>Mystery #2</em></blockquote><h3>Activate and Deactivate</h3><ul><li>Constraints find their own container</li><li>Adds constraints efficiently</li><li>Do not need to own all views</li></ul><p>❌ Add and remove</p><p>✅ Activate and deactivate</p><h3>Things to Keep in Mind</h3><p>🙅🏻‍♀️Never deactivate self.view.constraints</p><ul><li>Not all of those constraints in that array belong to you (such as the ones the view uses to set itself up)</li><li>Weird things will happen</li><li>Just don’t do it!</li></ul><p>🙆🏻‍♀️ Keep references to constraints that change</p><p>(either in an array of constraints or as individual constraints so that you can manage things exactly the way you want to.)</p><h3>Changing Constraints</h3><ul><li>Never deactivate self.view.constraints</li><li>Keep references to constraints It will make everything work better, and you can do cool thing like animation.</li><li>Animate changing constraints with view animation</li></ul><h3>View Sizing</h3><blockquote><em>Mystery #3</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4TBgYIPba61Acb9h.png" /></figure><p>Defining a particular view size</p><ul><li>Use constraints first</li><li>Override intrinsicContentSize for specific reasons</li><li>If size information does not come from constraints</li><li>If view has custom drawing (sometimes)</li><li>You will be responsible for invalidating in case the slide class changes or the text changes that you’ve got dynamic text, localization, or anything like that may cause your view to need to recalculate its internal size.</li><li>Size can change with size class changes</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*himqU8i25i3x-DIs.png" /></figure><p>The more you rely on proportions, the more likely you are to have a good layout that will be easy for you to put across all these different screens we are giving you.</p><h3>Self-Sizing Table View Cells</h3><blockquote><em>Mystery #4</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FC1-Thn3aYRAutL_.png" /></figure><h3>View Sizing</h3><ul><li>Certain views have an intrinsicContentSize You can use that when you are defining relationships to other views.</li><li>Constraints should define size when possible When not, you can override intrinsicContentSize, but make sure you invalidate</li><li>For self-sizing views, define size fully in constraints</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8iZ5tBEJcnd6JV58.png" /></figure><h3>Priorities</h3><blockquote><em>Mystery #5</em></blockquote><h3>Ambiguity</h3><p>If you have been doing Auto Layout for a while, you may have landed in a situation where views aren’t landing where you expect them to in regard their superview.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*K_5LmOW_Jq_0LJsx.png" /></figure><h3>Constraint Priorities</h3><p>So how do priorities work?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*L0NDz0jvt6zoYF-y.png" /></figure><h3>Constraint Priorities</h3><ul><li>How a view handles its content</li><li>By default, these are not set as required</li><li>Do not set as required</li><li>Can cause unsatisfiable constraints</li><li>Equal priorities can cause ambiguity</li><li>Types</li><li>Content hugging</li><li>Compression resistance</li></ul><p>Content hugging</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/584/0*sJ9vE7hB13aNVAN2.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*SJie4z4HOVVqT8At.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/598/0*cSjwxkEvohIhWtab.png" /></figure><p>TextView 249</p><p>→ The engine looks at your constraints and your priorities and say, oh the text view hugging priority is fairly important, but the button hugging priority is not at all important, so I can go ahead and stretch that away from its content to fill up this horizontal part of your view here.</p><p>TextView 251</p><p>→ The engine says, hey now I want to hug this button text really closely, and that means that I can stretch the text field in order to solve your layout.</p><p>Compression resistance</p><p>This is is how much a view resists its content getting squished.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/578/0*1OGPI24oAjRy3EDs.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/564/0*uEmC_e22ZVf2nKj3.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/562/0*Oy1RXzO42sZFg38k.png" /></figure><p>What if you localize this app?</p><p>I can either shrink the imageView or clip label.</p><p>→ If you wanted the label to always show all of its content and it was okay to shrink that image a little bit, all you have to do is set the labels content compression resistance priority slightly higher than that of the imageView.</p><h3>Priorities</h3><ul><li>Can help keep constraints from unsatisfiability</li><li>But look out for competing priorities!</li><li>Results are more consistent</li><li>Use content priorities to get to the right layout</li><li>Hugging priorities hug content</li><li>Compression resistance resist squishing</li></ul><h3>Alignment</h3><blockquote><em>Mystery #6</em></blockquote><ul><li>Use firstBaseline and lastBaseline</li><li>Aligns text better than top or bottom</li><li>Better control over changing views</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/0*eAxQxkjgVS3At0Sz.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*I03QvukN8V_c9d38.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/570/0*PkRSoGOGpVOqEtOp.png" /></figure><h3>Leading and Trailing</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_MHBlk_CbU2S8Qhy.png" /></figure><h3>Alignment Rects</h3><p>What the engine actually calculates. The engine takes all of your constraints, calculates the alignment rects, and uses them to actually layout views.</p><ul><li>Usually (not always) same as frame</li><li>Includes the critical content only</li><li>Does not change when view is transformed</li><li>Override alignmentRectInsets if needed</li><li>Find out the calculated rects</li><li>Use Show Alignment Rectangles in Debug menu</li><li>Get using alignmentRectForFrame:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/0*oykjPbbiKSEJkHHs.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/458/0*7Y_YbNoHfjW1BFVr.png" /></figure><h3>Alignment</h3><ul><li>First and last baseline for better aligned text</li><li>Leading and trailing instead of left and right</li><li>Override alignmentRectInsets to adjust alignment rects</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*l0-eCqNctg-ZOyzS.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FTUaMx8tBB9DWcMS.png" /></figure><h3>Summary</h3><ul><li>Stack Views help build easily maintainable layouts</li><li>Use activate and deactivate for constraints</li><li>Determine size through constraints</li><li>Override intrinsicContentSize judiciously</li><li>Use priorities to properly solve your layout</li><li>Alignment goes beyond top, bottom, and center</li><li>Keep localization in mind</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b22ce12feb7a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cocoa Touch Best Practices]]></title>
            <link>https://medium.com/@jjuou2/cocoa-touch-best-practices-5f0630ad7f18?source=rss-9b8f5f9360bb------2</link>
            <guid isPermaLink="false">https://medium.com/p/5f0630ad7f18</guid>
            <category><![CDATA[wwdc]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[uikit]]></category>
            <category><![CDATA[cocoa]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Jinha Park]]></dc:creator>
            <pubDate>Fri, 31 Jan 2020 04:49:17 GMT</pubDate>
            <atom:updated>2020-01-31T04:49:17.673Z</atom:updated>
            <content:encoded><![CDATA[<h3>Cocoa Touch Best Practices</h3><blockquote><em>📅 2020.1.30 (THU)</em></blockquote><blockquote>WWDC 2015 | Session : 231| Category : UIKit</blockquote><p>🔗 <a href="https://developer.apple.com/videos/play/wwdc2015/231/">Cocoa Touch Best Practices — WWDC 2015 — Videos — Apple Developer</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6w6HEOyFSwhQGC2l.png" /></figure><h3>App Lifecycle</h3><p>First best practice is launch quickly. That’s how you appear responsive when the user taps on your icon and right away they get your app ready to interact with.</p><h3>Launch Quickly Again</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2hatrf2pEsARftfs.png" /></figure><p>That app is the first on that’s going to die when the foreground app needs additional memory.</p><p>⬇️</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sK3pJ3sLLSUXUMPf.png" /></figure><h3>Leverage Frameworks</h3><blockquote><em>Properly manage version change</em></blockquote><ul><li>Target two most recent major release</li><li>Include version fallbacks</li><li>Have an else clause</li></ul><h3>Views and View Controllers</h3><h3>Layout on Modern Devices</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*iIjsLSFkQZ4EcANl.png" /></figure><p>No longer makes sense to build layouts that are built specific for a particular dimension that your ViewController expects to be in.</p><p>Instead, layout in general wants to think of itself as being done to proportions, and we do that by specifically avoiding hard-coded values in the layout of Views and ViewControllers.</p><h3>Layout to Proportions</h3><ul><li>Avoid hard-coded layout values</li><li>Either or both dimensions may scale</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/538/0*N-8QC-l3SyWLA-q0.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/542/0*EdoENreBypFj90C4.png" /></figure><h3>Size Classes</h3><ul><li>Some size thresholds trigger major change</li><li>Packaged in UITraitCollection</li></ul><h3>Properties, No Tags!</h3><p>Avoid setTag: and viewWithTag:</p><ul><li>Possible collisions with other code</li><li>No compiler warnings</li><li>No runtime errors</li></ul><p>Instance variables and properties provide better alternative</p><pre>class ViewController: UIViewController {<br>    	var imageView: UIImageView<br>    <br>    	overrride func viewDidLoad() {<br>    		super.viewDidLoad()<br>    <br>    		imageView = UIView(frame: CGRect(x: 0, y :0, widht: 50, height: 50))<br>    		view.addSubview(imageView)<br>    	}<br>    }</pre><p>Keep real reference to that view, also has better type information because viewWithTag: only is a type UIView.</p><h3>Make Timing Deterministic</h3><p>Leverage UIViewControllerTransitionCoordinator</p><p>(to know what the timings are for the animations that you have)</p><ul><li>Animate alongside a transition</li><li>Get accurate completion timing</li><li>Support interactive and cancelable animations</li></ul><h3>Auto Layout</h3><h3>Modify Constraints Efficiently</h3><ul><li>Identify constraints that get changed, added, or removed</li><li>Unchanged constraints are optimized</li><li>Avoid removing all constraints</li><li>Use explicit constraint references</li></ul><p>❌❌❌</p><pre>override func updateViewConstraints() {<br>    	super.updateViewConstraints()<br>    <br>    	view.removeConstraints(view.constraints())<br>    	view.addConstraints(self.genereatdConstraints())<br>    }</pre><p>✅✅✅</p><pre>override func updateViewConstraints() {<br>    	super.updateViewConstraints()<br>    <br>    	view.removeConstraints(imageViewHorizontalConstraint)<br>    	imageViewHorizontalConstraints = self.generatedImageViewHorizontalConstraint()<br>    	view.addConstraint(imageViewHorizontalConstraint)<br>    }</pre><h3>Constraint Specificity</h3><blockquote><em>De-duplicating constraints</em></blockquote><ul><li>Duplicates are implied by existing constraints</li><li>Duplicates causes excess work in layout engine It’s solving for these constraints because they are there, but didn’t actually need to solve for them.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*73T_m_krS9nS6m66.png" /></figure><p>This view hierarchy would have laid out exactly the same if I hadn’t specified the left margin of the bottom view.</p><p>Get rid of that we&#39;ll be faster.</p><blockquote><em>Create flexible constraints</em></blockquote><ul><li>Avoid hard-coded values</li><li>Describe constraints using bounds</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/584/0*ud84qBA8CJn8u0nE.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/0*O4STzcBEWnfzfl4I.png" /></figure><blockquote><em>Fully specify constraints</em></blockquote><ul><li>Underspecification generates ambiguity</li><li>Ambiguity is undefined View might come out different ways different times I run my app.</li></ul><blockquote><em>Testing and debugging</em></blockquote><p>-[UIView hasAmbiguousLayout] It will let you know if there’s ambiguity in you view.</p><ul><li>When called on UIWindow, returns result for entire view tree</li></ul><p>-[UIView _autolayoutTrace]</p><ul><li>Both can be used for unit testing</li></ul><h3>Table and Collection View</h3><h3>Self-Sizing Cells</h3><ul><li>Fully specify constraints</li><li>Width = input, height = output</li></ul><h3>Animation Height Changes</h3><ul><li>tableView.beginUpdates</li><li>Update model</li><li>Update cell contents</li><li>tableView.endUpdates</li></ul><h3>Fast Collection View Layout Invalidation</h3><blockquote><em>Modify only what is needed</em></blockquote><ol><li>Invalidate on bounds change</li><li>Build targeted invalidation context</li><li>Repeat as necessary</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5f0630ad7f18" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>