<?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 Karthick Selvaraj on Medium]]></title>
        <description><![CDATA[Stories by Karthick Selvaraj on Medium]]></description>
        <link>https://medium.com/@karthickselvaraj?source=rss-251b31c2631f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*iYCGgvzyA_pR5BuqtLbYIA.jpeg</url>
            <title>Stories by Karthick Selvaraj on Medium</title>
            <link>https://medium.com/@karthickselvaraj?source=rss-251b31c2631f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 12:48:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@karthickselvaraj/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to solve the lock delay issue in iPhone 13?]]></title>
            <link>https://karthickselvaraj.medium.com/how-to-solve-the-lock-delay-issue-in-iphone-13-8eb1ba82e57b?source=rss-251b31c2631f------2</link>
            <guid isPermaLink="false">https://medium.com/p/8eb1ba82e57b</guid>
            <dc:creator><![CDATA[Karthick Selvaraj]]></dc:creator>
            <pubDate>Sat, 25 Feb 2023 03:44:31 GMT</pubDate>
            <atom:updated>2023-02-25T03:44:31.203Z</atom:updated>
            <content:encoded><![CDATA[<p>Everything was normal until I noticed a <strong>slight delay in locking my device</strong> using the side button. Usually display light will go off instantly when we press the side button. However, it took around a second to turn off my display light after pressing the side button. As soon as I noticed the delay, I recalled whatever I had done on my device in recent days. Like,</p><ol><li>New apps download</li><li>Developer mode status change</li><li>Background app refresh status change</li><li>Etc.</li></ol><h3><strong>How did I solve it?</strong></h3><p>Firstly I connected with the apple support team using the Apple Support app as I have an active warranty. Apple support person connected with me on live chat and asked me to run Diagnostics on my device. After completing the diagnostic, they said everything had passed, and the device looked normal.</p><p>Then I checked my side button response speed in the setting app(Settings &gt; Accessibility &gt; Side Button &gt; Click Speed. It was set to <strong>default</strong> as expected.</p><p>Finally, I suddenly remembered that I had turned on the <strong>Guided Access</strong> option recently for some testing.</p><p><strong><em>✅ Turning guided access off helped me to fix the issue.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*o0gX5sSDby6cWm2jZKgjOA@2x.jpeg" /></figure><p>I don’t know why guided access is making my device lock action slow. Anyway, my device lock is working as expected.</p><p>It might help someone who are facing the same issue on iPhone 13 devices.</p><p>:)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8eb1ba82e57b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to upload missing dSYM file to Firebase Crashlytics]]></title>
            <link>https://karthickselvaraj.medium.com/how-to-upload-missing-dsym-file-to-firebase-crashlytics-3310fd66ae7d?source=rss-251b31c2631f------2</link>
            <guid isPermaLink="false">https://medium.com/p/3310fd66ae7d</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[crash-reporting]]></category>
            <category><![CDATA[debugging]]></category>
            <dc:creator><![CDATA[Karthick Selvaraj]]></dc:creator>
            <pubDate>Fri, 30 Jul 2021 11:48:25 GMT</pubDate>
            <atom:updated>2021-07-30T11:48:25.184Z</atom:updated>
            <content:encoded><![CDATA[<p>You might have integrated <a href="https://firebase.google.com/products/crashlytics/">Firebase Crashlytics</a> in your app to analyse the performance of your app and crashes in both staging and production environment. Assume your client or external tester is getting an unexpected crash in your app which you haven’t faced during the development phase. How can you identify the cause of the crash and fix it?</p><p>Logical mistakes can be reproduced based on your clients or testers inputs. But it’s really hard to debug and fix system-level causes, like thread misuse or some unknown cases. You can use Crashlytics to capture and fix these kind of unexpected crashes.</p><p>Crashlytics will automatically upload the dSYM(<a href="https://developer.apple.com/documentation/xcode/building_your_app_to_include_debugging_information">debug symbols file</a>) file using a Run script which you should have added during <a href="https://firebase.google.com/docs/crashlytics/get-started?platform=ios">Crashlytics configuration</a>. Crashlytics uses the dSYM file to generate the crash report.</p><p>For some reasons, dSYM files might not be uploaded to the Crashlytics and you can see below error message in your crashlytics console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uOnUuzGscz4sC7Mt8cyYrg.png" /></figure><p>In this case, Crashlytics can’t provide you with useful crash reports. You need to upload the missing dSYM file to get the crash report to understand what went wrong with your version.</p><p>You will be provided with steps to upload the missing dSYM files when you click the Upload dSYMs button in the alert in Crashlytics console. You can also see a table with UUID, Status and Crash count just below the upload steps. You will need to upload separate dSYM for each listed UUID in this list.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ihs9oWwl3_b9HSQGzJnJJw.png" /></figure><blockquote>NOTE: You should have Xcode archived file in your local to proceed with below steps.</blockquote><h3>Follow below steps to upload your missing dSYM file,</h3><ol><li>Copy the UUID from the missing dSYMs list in the Crashlytics console</li><li>Open your project in the Xcode</li><li>Open Xcode organiser, Window -&gt; Organiser</li><li>Select your app from the apps list on the left side</li><li>Select the archived file by matching version and build number from missing dSYMs list in Crashlytics console</li><li>Right-click the particular archived file and click Show in Finder. Now you can see your .xcarchive file in the finder.</li><li>Select the file, Right-click -&gt; Show Package Contents</li><li>Select the dSYMs folder</li><li>Find the dSYM file which is named as the copied UUID from the crashlytics in step 1. Copy and paste that particular file in your desktop for easy use.</li><li>Go back to Xcode, expand Pods in your project.</li><li>Select, FirebaseCrashlytics -&gt; Right click -&gt; Show in Finder</li><li>You should see an executable file called <strong>upload-symbols</strong>. You will be using this to upload your missing dSYM which you just copied to the desktop.</li><li>Go back to Xcode, select your <strong>GoogleService-Info.plist</strong> and get its path by Right click -&gt; Show in Finder</li><li>You need 3 paths, <strong><em>missing dSYM</em> file’s</strong> path, <strong><em>upload-symbols</em> file’s</strong> path and <strong><em>GoogleService-Info.plist</em></strong> file’s path.</li><li>Form your upload command,</li></ol><pre>&lt;Upload-symbol path&gt; -gsp &lt;GoogleService-Info.plist path&gt; -p ios &lt;missing dSYM file path&gt;</pre><blockquote><em>Example: /Users/karthick/Desktop/SampleProject/Pods/FirebaseCrashlytics/upload-symbols -gsp /Users/karthick/Desktop/SampleProject/GoogleService-Info.plist -p ios /Users/karthick/Desktop/EEAA5588–1234–1234–1234–243322DDEE66.dSYM</em></blockquote><p>Open the terminal and paste the command you just formed in above step and hit enter/return key. If you see a message, <strong>Successfully uploaded Crashlytics symbols</strong>, your dSYM file is uploaded</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TTsYRsJSTvd1ZdB0EzSbgQ.png" /></figure><p>You should wait for 5 to 10 minutes to allow Crashlytics to process the uploaded dSYM file and generate the crash report. You can analyse and find the root cause of your crash and fix it as soon as your crash report is prepared.</p><p>Thanks! 👨🏻‍💻</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3310fd66ae7d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Workout tracking app using SwiftUI — Open Sourced my Code]]></title>
            <link>https://karthickselvaraj.medium.com/workout-tracking-app-using-swiftui-open-sourced-my-code-77777b25f3dc?source=rss-251b31c2631f------2</link>
            <guid isPermaLink="false">https://medium.com/p/77777b25f3dc</guid>
            <category><![CDATA[workout]]></category>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Karthick Selvaraj]]></dc:creator>
            <pubDate>Fri, 23 Apr 2021 02:17:57 GMT</pubDate>
            <atom:updated>2021-04-23T02:17:57.249Z</atom:updated>
            <content:encoded><![CDATA[<h3>Workout tracking app using SwiftUI — Open Sourced my Code</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DUK7hKQbZg2XdWrFSKuSuw.png" /><figcaption>Few Screenshots from the App</figcaption></figure><p>I have started learning SwiftUI during the pandemic lockdown. <strong>SwiftUI</strong> was comparatively easy and challenging for me due to its <em>declarative</em> nature of development. Initially, I have concentrated on the fundamentals of SwiftUI and spent more time playing with the learned concepts in Xcode.</p><p>Later, I have decided to develop a complete working app using SwiftUI to monitor my workouts progress which I’m using in my daily routine. I have posted many videos and blogs based on the experience and learnings from the app.</p><ul><li><a href="https://betterprogramming.pub/view-life-cycle-methods-in-swiftui-b7fa9f0e8dfb">Lifecycle Methods in SwiftUI</a></li><li><a href="https://betterprogramming.pub/property-wrappers-in-swiftui-63bae630bb5a">A Guide to Property Wrappers in SwiftUI</a></li><li><a href="https://betterprogramming.pub/integrating-widgetkit-in-existing-swiftui-apps-ff285faa2896">Integrating WidgetKit in Existing SwiftUI Apps</a></li></ul><p>I was developing the app in private for my personal use. Later, I have decided to <strong>open source</strong> it to receive feedback and comments about the code structure and approach that I have used on it.</p><p>You can find the complete source code of the app from the below repo,</p><p><a href="https://github.com/karthironald/BodyProgress">GitHub - karthironald/BodyProgress: Simple workout and progress tracking app for fitness freaks with Widget support.</a></p><h3>Features</h3><p>Here are the features of the <strong>workout app</strong>. Take a look at the repo’s <a href="https://github.com/karthironald/BodyProgress">Readme</a> file for screenshots.</p><h4><strong>Workout:</strong></h4><ul><li>CRUD (Can create unlimited workout)</li><li>Favourite and unfavourite (My favourite workouts are chest and biceps. You can favourite and unfavourite your workouts too)</li></ul><h4><strong>Exercise:</strong></h4><ul><li>CRUD (Can create unlimited exercises in a workout)</li><li>Exercise references (Can add video links as reference which can be accessed whenever needed)</li></ul><h4><strong>Set:</strong></h4><ul><li>CRUD (Can create unlimited sets in an exercise)</li><li>Bulk update (Can update the weights and reps of the multiple sets easily in few taps)</li></ul><h4><strong>Today:</strong></h4><ul><li>Start today workout (Can start your today workout with duration timer and log your each set)</li><li>Rest timer (Automatic or manual rest timer for perfect rest planning between your sets)</li></ul><h4><strong>History:</strong></h4><ul><li>History with filters (Can filter you workout history based on <strong>body part</strong>, <strong>completion status</strong> or <strong>time period</strong>)</li><li>Continue incomplete workouts (Can continue your incomplete workout)</li><li>Pie-Chart summary and its split-up (Provides clear view on each body part and its workout history details)</li></ul><h4><strong>Settings:</strong></h4><ul><li>Local Notification (Reminds you to start you workout on time)</li><li>Haptic Feedbacks (Provides Rigid haptic feedback for the interactions with the app)</li></ul><h4>Others:</h4><ul><li>Widget (A configurable widget to get the summary of your workout history)</li></ul><h3>Conclusion</h3><p>My code might not be the perfect. But you can get some idea to learn how easy it is to develop an app using SwiftUI. Have a look at my source code and let me know your feedbacks in comments.</p><p>Thanks 👨🏻‍💻</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=77777b25f3dc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Integrating WidgetKit in Existing SwiftUI Apps]]></title>
            <link>https://medium.com/better-programming/integrating-widgetkit-in-existing-swiftui-apps-ff285faa2896?source=rss-251b31c2631f------2</link>
            <guid isPermaLink="false">https://medium.com/p/ff285faa2896</guid>
            <category><![CDATA[mobile]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Karthick Selvaraj]]></dc:creator>
            <pubDate>Tue, 02 Feb 2021 14:07:06 GMT</pubDate>
            <atom:updated>2021-02-02T14:07:41.179Z</atom:updated>
            <content:encoded><![CDATA[<h4>Add awesome widgets to your iOS 14 application</h4><figure><img alt="Image of iOS tablets." src="https://cdn-images-1.medium.com/max/1024/0*dMj3IuwbxKaikSJs" /><figcaption>Photo by <a href="https://unsplash.com/@miguelavtomas?utm_source=medium&amp;utm_medium=referral">Miguel Tomás</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>I know that I’m late to the party 😅. Probably you might have heard what are widgets in iOS 14 and their use cases. I have started developing an app for personal use using SwiftUI to track my workout progress. I have started it as learning, and later I have added more features because I use the app on a daily basis.</p><p>I check my workout summary on a weekly basis to see how much time I have spent and which body parts particularly. Here is the screen of the workout summary widget:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/462/1*tD9C0a1ZVTkIY_xCxYOC1Q.png" /></figure><p>Apple has introduced WidgetKit in WWDC20, which got my attention, and so I added Widgets support in my app’s to-do list. There are plenty of articles to give support for a SwiftUI app from scratch but very less for migrating an existing app with Core Data support and live data.</p><p>Let’s get started and see what are the steps to update your existing app with Widget support. I have used CoreData as my local storage.</p><ol><li>Adding App Groups</li><li>Migrating CoreData to shared place</li><li>Accessing CoreData from a shared container in Widget</li></ol><h3>Adding App Groups</h3><p>By default, all the data saved in CoreData or UserDefaults will be accessible only on the host app —which means your main app. Your widget will not get any access to the data saved by your host app.</p><p>You need to save the data in a shared place to make the data accessible by both Main app and app extension(Widget in our case). You need to configure App Group in Apple Developer Portal to create a shared container.</p><p>Follow the below steps to configure the shared container:</p><ol><li>Log in to your Apple developer account</li><li>Choose Certificates, Identifiers &amp; Profiles from the side menu</li><li>Choose Identifiers from the side menu</li><li>Click Plus(<strong>+</strong>) button and choose App Groups from the list</li><li>Provide your identifier for the group and description</li><li>Click Continue and then click Register</li></ol><p>Your App Group Id is ready now. Next step: link your App Group ID to your App ID.</p><ol><li>Select your App ID from the available App IDs list</li><li>Select App Groups in the capabilities list</li><li>Configure button will be enabled as soon as you check App Groups and click it.</li><li>Choose the newly created App Group ID from the app groups list and click Continue</li><li>Click Save</li><li>Read the message in the alert, and click Confirm. Basically, you need to create a new provisional profile after adding / removing any capabilities to your App Id.</li></ol><p>Get back to Xcode, and Add new App group capability. Choose the newly created App Group ID on both Targets — your Main App and Widget.</p><h3>Migrating CoreData to Shared Container</h3><p>I have created custom logic to migrate my local CoreData files to the shared container as below. I’m maintaining a bool in UserDefaults to check whether the DB is already migrated to a shared container and proceeding only if it is not migrated yet. The below code should be self-explanatory:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/990304bf14513da1f20c01d6b8c53e5e/href">https://medium.com/media/990304bf14513da1f20c01d6b8c53e5e/href</a></iframe><h3>Accessing CoreData From Shared Container in Widget</h3><p>You should be able to access your existing core data file and the existing data from your widget with the following code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/617e7ca768ecbcbfad9a035229bd8918/href">https://medium.com/media/617e7ca768ecbcbfad9a035229bd8918/href</a></iframe><p>NOTE: Make sure that all your necessary files are shared to your Widget as well in Target Membership.</p><h3>Conclusion</h3><p>A widget is the right choice for glanceable contents. Use it wisely with other powerful frameworks like CoreData.</p><p>Thanks 👨🏻‍💻</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ff285faa2896" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/integrating-widgetkit-in-existing-swiftui-apps-ff285faa2896">Integrating WidgetKit in Existing SwiftUI Apps</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[Explore the New Features in SwiftUI for Building Progress Views]]></title>
            <link>https://medium.com/better-programming/explore-the-new-features-in-swiftui-for-building-progress-views-ecba9a478910?source=rss-251b31c2631f------2</link>
            <guid isPermaLink="false">https://medium.com/p/ecba9a478910</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[wwdc-2020]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Karthick Selvaraj]]></dc:creator>
            <pubDate>Wed, 01 Jul 2020 21:49:49 GMT</pubDate>
            <atom:updated>2020-07-02T02:51:05.672Z</atom:updated>
            <content:encoded><![CDATA[<h4>Loading indicators and progress bars just got a whole lot better</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cd3nsmvuIBsdwKANra7Mbw.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@yingchih_hao?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Yingchih</a> on <a href="https://unsplash.com/s/photos/progress?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Apple has released major updates to the SwiftUI framework at WWDC20. We might need to show visual feedback to the user about what’s happening and the progress of the tasks like uploading or downloading a file or fetching data from the server. Earlier we were depending on UIViewRepresentable to import and use UIActivityIndicatorView from UIKit in SwiftUI or on custom implementation using solid shapes.</p><p>With the latest updates in SwiftUI, we have a dedicated native view for showing determinate and indeterminate progress in the SwiftUI app: <a href="https://developer.apple.com/documentation/swiftui/progressview?language=objc">ProgressView</a>.</p><ul><li>Indeterminate: To show whether the process is happening</li><li>Determinate: To show the percentage completion of the task</li></ul><p>Let’s get started and see how can we implement the progress view in the SwiftUI app. You need Xcode 12 beta to try this out as ProgressView available from iOS 14.</p><h3>Indeterminate Progress View</h3><h4>Loading indicator</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/367/1*nmoMQqd_1d6qy6n75foftw.gif" /></figure><p>You can add the continuous spinning activity indicator in just a few lines, as below. The indicator starts animating as soon as you add it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/56b341306dbc530ef951a022e488ce0d/href">https://medium.com/media/56b341306dbc530ef951a022e488ce0d/href</a></iframe><p>You need to use CircularProgressViewStyle(tint: ) as progressViewStyle to set the tint color of your progress view. I have used scale effect to increase the size of the progress view for visibility.</p><h4>Loading indicator with info text</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/367/1*G_spOgxtbnyJpOnQ68Y05w.gif" /></figure><p>You can add any meaningful text with your progress view easily, as below. Passing tint color using CircularProgressViewStyle(tint: ) will set only the spinning loading indicator. You need to set a foreground color separately for the label.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/085262d2ef649401b711af6546d94e25/href">https://medium.com/media/085262d2ef649401b711af6546d94e25/href</a></iframe><h4>Loading indicator with a custom view</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/367/1*JpBd5QFTw2wss9dfvfBtTA.gif" /></figure><p>You might want to have the Cancel button with your progress view. You can add any type of view with your progress view, as below. I have added a cancel button with the progress view.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d3937672402e1ecc9f21bc2ddd926d02/href">https://medium.com/media/d3937672402e1ecc9f21bc2ddd926d02/href</a></iframe><h3>Determinate Progress View</h3><h4>Horizontal progress bar</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/367/1*2AWXmtw297TX2XYO_VwjCQ.gif" /></figure><p>You can add a simple determinate progress view with total progress value in total param and completed progress value in value param.</p><p>Notice that I have applied a custom progress view style to set different colors when progress is ongoing and completed. You can do any type of customization to your progress view by creating a custom progress style which conforms to <a href="https://developer.apple.com/documentation/swiftui/progressviewstyle?language=objc">ProgressViewStyle</a> protocol.</p><p>I have used a Timer to simulate progress animation for the demo. You can change this part with your actual progress value.</p><blockquote>Hint: Applying a negative progress value to a determinate progress view will convert it to an indeterminate progress view.</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/08bf630eb212966dfbfc88c209130268/href">https://medium.com/media/08bf630eb212966dfbfc88c209130268/href</a></iframe><p>I have added another custom style called CustomLinearProgressViewStyle2. Just change from CustomLinearProgressViewStyle1 in the above code and you will get below result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/367/1*WBGqtd01p-2HYVA9TfXmNA.gif" /></figure><h4>Horizontal progress bar with info text</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/367/1*egpOQc1rS0a2wxvxCjT3cA.gif" /></figure><p>As with the indeterminate progress view, you can add info text to your determinate progress bar, as below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4e395834119307907cf4253d86fdd3a8/href">https://medium.com/media/4e395834119307907cf4253d86fdd3a8/href</a></iframe><h4><strong>Horizontal p</strong>rogress <strong>bar with a custom view:</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/367/1*vaSXCdVA-mOD0qz2cWU6CQ.gif" /></figure><p>As with the indeterminate progress view, you can add custom views to the determinate progress view type. I have added two images are either side of my horizontal progress bar.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0dadf2563c749c294fb55b66e1d0a2f4/href">https://medium.com/media/0dadf2563c749c294fb55b66e1d0a2f4/href</a></iframe><h3>Conclusion</h3><p>The new ProgressView will work only from iOS 14.0+, macOS 11.0+, Mac Catalyst 14.0+, tvOS 14.0+, and watchOS 7.0+ . For older versions, you need to write your own progress view logics.</p><p>You can get the <a href="https://github.com/karthironald/NativeProgressView/tree/master">complete code here</a>.</p><p>You can check this <a href="https://github.com/karthironald/ProgressIndicator">repo</a> if you want to add a progress view for iOS 13, as well.</p><p>Thanks.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ecba9a478910" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/explore-the-new-features-in-swiftui-for-building-progress-views-ecba9a478910">Explore the New Features in SwiftUI for Building Progress Views</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[Getting Started With Neumorphism in SwiftUI]]></title>
            <link>https://medium.com/better-programming/getting-started-with-neumorphism-in-swiftui-459843ad05a6?source=rss-251b31c2631f------2</link>
            <guid isPermaLink="false">https://medium.com/p/459843ad05a6</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[mobile]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[xcode]]></category>
            <dc:creator><![CDATA[Karthick Selvaraj]]></dc:creator>
            <pubDate>Thu, 25 Jun 2020 15:16:13 GMT</pubDate>
            <atom:updated>2020-06-25T15:16:13.217Z</atom:updated>
            <content:encoded><![CDATA[<h4>How to design neumorphic buttons</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gSrjkkjzSdvsXDCX2P95PQ.png" /><figcaption>Neumorphism effect using SwiftUI (Image courtesy of the author)</figcaption></figure><p>I was looking for the latest UI and UX design trends in <a href="https://dribbble.com/">dribble</a>, and I heard of a concept often called <em>neumorphism</em>.</p><p>Design communities believe it to be 2020’s design trend, one which mimics a real-world feel in UI components. You can get plenty of design templates and references on <a href="https://dribbble.com/search/neumorphism">dribble</a>.</p><p>Explaining what neumorphism is and its history is beyond the scope of this article. You can learn more about neumorphism in “<a href="https://uxdesign.cc/neumorphism-in-user-interfaces-b47cef3bf3a6">Neumorphism in User Interfaces</a>,” “<a href="https://medium.muz.li/skeuomorphism-neumorphism-ui-trend-e7b78792bd21">Skeuomorphism / Neumorphism UI Trend</a>,” and “<a href="https://medium.com/@openGeeksLab/neumorphism-the-next-big-thing-in-ui-design-11e703df3ab0">Neumorphism. The Next Big Thing In UI Design</a>?”</p><p>Okay, let’s get started and see how you can implement neumorphism in your next iOS app using SwiftUI. As you might aware, SwiftUI enables us to implement any sort of complex UI and UX with minimum efforts, no matter whether it’s the trend of the year or not.</p><p>Check out the image above to see what we’re going to implement before proceeding further. As you might have guessed, we are going to use default solid shapes provided by SwiftUI with default modifiers like fill(), frame(), shadow(), blur(), opacity() and mask().</p><h3>Color Matters</h3><p>I found color is the main player here, so choosing the right colors is important. If you don’t choose the right shades of color, you will waste a lot of time, just like I did.</p><p>We need three shades of the same color: one for the main background and the other two for light and dark shadows. Open the Assets.xcassets file and add the below colors (use the same name for brevity).</p><ol><li>Background color: <strong>#</strong>DFE4EB (name it kMainBg)</li><li>Light shadow color: #FFFFFF (name it kLightShadow)</li><li>Dark shadow color: #A2B0C5<strong> </strong>(name it kDarkShadow)</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x6uLa1svFEIrNpa-JHLkjw.png" /><figcaption>Adding color to assets</figcaption></figure><ol><li>Select Assets.xcassets file.</li><li>Click + button at the bottom left corner.</li><li>Select the New Color Set option from the menus. On clicking, the new color set will be added and the popover will be dismissed automatically.</li><li>Select the newly added color, which will be named ‘Color’ by default. I have chosen the name which I have added already for the demo.</li><li>Select the color shade that is added for a universal device.</li><li>Change the Input Method to 8-bit Hexadecimal from the dropdown, enter the color Hex value provided above, and hit Enter.</li></ol><p>You’re done. Add all three color shades by following the above steps.</p><h3>Effect 1.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*yDZM_qMGLTFKHepUdn9f0g.png" /><figcaption>Neumorphism Effect 1</figcaption></figure><p>We are going to use the default RoundedRectangle<strong> </strong>shape to get this effect. This is the simple one among the remaining three.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fa9c81e38e99ac9c2a9e23d0b011c764/href">https://medium.com/media/fa9c81e38e99ac9c2a9e23d0b011c764/href</a></iframe><ol><li>First, add a VStack as the container of our actual content and set the frame to go edge-to-edge across the screen. Then set the VStack background color as Color(“kMainBg”) using the background() modifier.</li><li>Create a RoundedRectangle shape inside VStack with cornerRadius = 20.</li><li>Apply the main background color (Color(“kMainBg”) ) of the rectangle using the fill() modifier.</li><li>Set the size of the rectangle as 150 X 150 using the frame() modifier. (I hear you, yes, it’s a rounded square now, not a rectangle. You can choose a different width to get the rectangle, or you can use any size, based on your need.)</li><li>Add the shadow using the dark color (“kDarkShadow”) that we added in asset with radius = 5 and offsets x = -10 and y = -10. Radius defines the shadow’s size and offset defines the position of the shadow relative to the view (a rectangular shape, in our case). This adds a dark shadow at the left and top sides of the rectangle.</li><li>Add another shadow using the light color (“kLightShadow”) that we added in asset with radius = 5 and offsets x = 10 and y = 10. This adds a dark shadow at the right and bottom sides of the rectangle.</li><li>Optionally, you can add an overlay to the rectangle using the overlay() modifier if you would like to have any content above the rectangle. I have added an Image view as overlay.</li><li>You’re done with your Effect 1. Enable preview or run the app in a simulator or device to check the result.</li></ol><h3>Effect 2.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*edU0MzxpfV1-YcB7USSCmQ.png" /><figcaption>Neumorphism Effect 2</figcaption></figure><p>We are going to use the default RoundedRectangle<strong> </strong>shape to get this effect. This is very similar to Effect 1.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e5b6310c0360abec11909e34b51aec80/href">https://medium.com/media/e5b6310c0360abec11909e34b51aec80/href</a></iframe><ol><li>Follow steps 1 to 6 in Effect 1.</li><li>Apply blur with radius = 5. Radius defines the radial size of the blur, and blur is more spread out when its radius is large.</li><li>Optionally, you can add an overlay to the rectangle using the overlay() modifier if you would like to have any content above the rectangle. I have added an Image view as overlay.</li><li>You’re done with your Effect 2. Enable preview or run the app in a simulator or device to check the result.</li></ol><h3>Effect 3.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*7U3VMSlbIcrfCaC1ID9G3w.png" /><figcaption>Neumorphism Effect 3</figcaption></figure><p>We are going to use three RoundedRectangle<strong> </strong>shapes, one over the other and with different sizes, along with the mask RoundedRectangle.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3a5ad230e0059e3d60f47e0be24b0a20/href">https://medium.com/media/3a5ad230e0059e3d60f47e0be24b0a20/href</a></iframe><ol><li>First, add a VStack as the container of our actual content and set the frame to go edge-to-edge across the screen. Then set the VStack background color as Color(“kMainBg”) using the background() modifier.</li><li>Add the ZStack container to maintain three RoundedRectangles, one over the other.</li><li>Add the first layer of RoundedRectangle with radius = 20. Set the fill using Color(“kMainBg”) and set the frame = 150 x 150. This is going to act as the base layer for your remaining two rectangles.</li><li>Add the second layer of RoundedRectangle with radius = 20. Set the fill using Color(“kMainBg”) and set the frame = 135 x 135. We set the frame smaller than the first rectangle to allow the shadow to move from the second layer to the first layer. The shadow will fill the gap between the two layers.</li><li>Add the third layer of RoundedRectangle with radius = 20. Set the fill using Color(“kMainBg”) and set the frame = 150 x 150, just like the second layer.</li><li>Apply the blur with radius = 15 and opacity = 0.7 to both the second and third layers of RoundedRectangle. This time we need to apply blur and opacity before applying shadow. The order of the modifiers is important.</li><li>Apply the dark color (“kDarkShadow”) shadow to the second layer with radius = 5 and offsets x = -10 and y = -10. This adds a shadow to the left and top sides of the rectangle.</li><li>Apply the light color (“kLightShadow”) shadow to the third layer with radius = 5 and offsets x = 10 and y = 10. This adds a shadow to the right and bottom sides of the rectangle.</li><li>Finally, you need to add a RoundedRectangle with radius = 20 mask to ZStack using themask() modifier. (This is important.)</li><li>You will get Effect 2’s look and feel if you don’t add the mask. But if you add a mask to Effect 2, you won’t get Effect 3 since we have played with different layers of RoundedRectangles with different frames.</li><li>Optionally, you can add an overlay to the rectangle using the overlay() modifier if you would like to have any content above the rectangle. I have added an Image view as an overlay.</li><li>You’re done with your Effect 3. Enable preview or run the app in a simulator or device to check the result.</li></ol><h3>Effect 4</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*aLzpMwkakbpXIzrnJkl3ug.png" /><figcaption>Neumorphism Effect 4</figcaption></figure><p>We are going to use three Circle shapes one, over the other with different sizes, along with the mask Circle.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b35b1ac66e4836035f2a8f7242ab5df9/href">https://medium.com/media/b35b1ac66e4836035f2a8f7242ab5df9/href</a></iframe><ol><li>First, add a VStack as the container of our actual content and set the frame to go edge-to-edge across the screen. Then set the VStack background color as Color(“kMainBg”) using the background() modifier.</li><li>Add the ZStack container to maintain three Circles, one over the other.</li><li>Add the first layer of Circle with Color(“kMainBg”) fill and set frame = 150 x 150. This is going to act as the base layer for your remaining two Circles.</li><li>Add the second layer of Circle with Color(“kMainBg”) fill and set frame = 100 x 100. We are giving a smaller size to this circle for the same reason as in Effect 3.</li><li>Add the third layer of Circle with Color(“kMainBg”) fill and set frame = 80 x 80.</li><li>Add blur to the second layer with radius = 20. We want to hide the layer, but we need it shadowed. No need to add blur to the third layer as we need it to be visible.</li><li>Add a kDarkShadow color shadow(radius = 40, x = -18, y = -18) to the second layer to the left and top sides of the circle and add kLightShadow color shadow(radius = 40, x = 18, y = 18) to the bottom and right sides of the circle.</li><li>Add a kLightShadow color shadow(radius = 12, x = -7, y = -7) to the third layer, to the left and top sides of the circle and add the kDarkShadow color shadow (radius = 12, x = 7, y = 7) to the bottom and right sides of the circle.</li><li>Finally, you need to add a Circle mask to ZStack using the mask() modifier. (This is important.)</li><li>Optionally, you can add an overlay to the rectangle using the overlay() modifier if you would like to have any content above the rectangle. I have added an Image view as an overlay.</li><li>You’re done with your Effect 4. Enable preview or run the app in a simulator or device to check the result.</li></ol><h3>Conclusion</h3><p>You can implement a neumorphism effect on any sort of shape or view by playing with modifiers like shadow(), fill(), blur(), opacity(), frame(), and mask(). Take this as an idea and implement your UI / UX based on your need.</p><p>You can find <a href="https://github.com/karthironald/Neumorphism">complete code here</a>.</p><p>Thanks!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=459843ad05a6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/getting-started-with-neumorphism-in-swiftui-459843ad05a6">Getting Started With Neumorphism in SwiftUI</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[Create an Awesome Loading State Using SwiftUI]]></title>
            <link>https://medium.com/better-programming/create-an-awesome-loading-state-using-swiftui-9815ff6abb80?source=rss-251b31c2631f------2</link>
            <guid isPermaLink="false">https://medium.com/p/9815ff6abb80</guid>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[animation]]></category>
            <category><![CDATA[mobile]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Karthick Selvaraj]]></dc:creator>
            <pubDate>Thu, 04 Jun 2020 11:54:39 GMT</pubDate>
            <atom:updated>2020-06-04T11:54:39.972Z</atom:updated>
            <content:encoded><![CDATA[<h4>Beautiful loading states</h4><p>Creating an intuitive animation is very simple and efficient in Apple’s brand new framework, <strong>SwiftUI</strong>. Before getting started, check out the video below to get to know what we are about to discuss.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FwaNxPt4HhCU%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DwaNxPt4HhCU&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FwaNxPt4HhCU%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/5dd8ec56ec34b90603a0bd17cc0cba12/href">https://medium.com/media/5dd8ec56ec34b90603a0bd17cc0cba12/href</a></iframe><p>In the above video, you saw five simple activity animations using different inbuilt <a href="https://www.hackingwithswift.com/quick-start/swiftui/swiftuis-built-in-shapes">solid shapes</a> in SwiftUI.</p><p>In SwiftUI, we can add animation to view animatable properties using <strong><em>.animation()</em></strong> modifier. There are the list of animatable properties in a view, like:</p><ol><li>Opacity</li><li>Offset</li><li>Scale</li><li>Frame</li><li>etc…</li></ol><p>You should apply any one of the animatable properties to your view to get an animation effect using the .animation() modifier. A view with the .animation() modifier without any animatable property does nothing. Being this said, let’s get started.</p><blockquote>Note: The animation GIFs are just for reference. Run the code in Xcode or check the above video to get actual animation smoothness.</blockquote><h3>3 Sliding Circles</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/1*hShXr9hDtKxHbHe3jQ_DQw.gif" /><figcaption>3 Sliding Circles GIF</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c840b31876260fd4ca169ed3596b5867/href">https://medium.com/media/c840b31876260fd4ca169ed3596b5867/href</a></iframe><ol><li>Create three circles using <strong>Circle</strong> shape in SwiftUI with 20x20 width and height.</li><li>Here, we are animating the <strong>offset</strong> of the circles, which makes circles move from left to right(➡️) and from right to left(⬅️).</li><li>We have added a <strong>Timer</strong> which will trigger every 1.6 seconds to swap the offset value. Initially, offset will be at <strong>100 </strong>(leftOffset), which makes circles move from left to right; after 1.6 seconds, leftOffset will be swapped as <strong>-100</strong>, which makes circles to move from right to left.</li><li>Why a <strong>1.6</strong>-second timer? <strong><em>1.6</em></strong><em> seconds = 1 circle animation duration (</em><strong><em>1</em></strong><em>) + 2nd circle delay (</em><strong><em>0.2</em></strong><em>) + 3rd circle delay (</em><strong><em>0.4</em></strong><em>).</em></li><li>We have reduced the opacity of the circles to add a nice feel when moving from one side to another.</li><li>Did you notice a <strong>delay</strong> in the second and third circles? Yes, delay helps to start the animation after waiting for the mentioned delay. In our case, delay helps us to move circles one by one. If we didn’t mention delay, all circles would move at the same time.</li><li>We have used default <strong>easeInOut</strong> animation with a<strong> one-second </strong>duration. There are plenty of animations available by default, like easeIn, easeOut, spring, etc… go ahead and play with it.</li></ol><h3>Horizontal Sliding Bar</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/556/1*I1-Kb8mVdEY8Z5hD4fOrvA.gif" /><figcaption>Horizontal sliding bar GIF</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8879a426d2de22ba764ae65a15b90f58/href">https://medium.com/media/8879a426d2de22ba764ae65a15b90f58/href</a></iframe><ol><li>Create a <strong>RoundedRectangle</strong> shape with cornerRadius as <strong>10 </strong>and<strong> </strong>frame of 80x20.</li><li>Here we are animating the <strong>offSet</strong> of the view. But this time, we have achieved the animation without the <strong>Timer. </strong>We have added <strong>shouldAnimate</strong> <em>@State</em> variable instead.</li><li>Whenever we change the <strong>shouldAnimate</strong> value, SwiftUI will re-render the view’s body property again. Initially, we have set it as false and <a href="https://medium.com/better-programming/view-life-cycle-methods-in-swiftui-b7fa9f0e8dfb"><strong><em>.onAppear()</em></strong></a> we have set it as true, which triggers the animation.</li><li>How view comes back without swapping offset? 🤔 It might be because of <strong>.repeatForever(autoreverses: true) </strong>(🔁). This makes the view to animate continue forever with nice reverse animation.</li><li>Try changing autoreverses as <strong>false</strong>, and see what happens. 😅</li><li>We have used default <strong>easeInOut</strong> animation with a<strong> 1-second </strong>duration.</li></ol><h3>5 Vertical Bars</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/538/1*Kr0i6XlnHE1-oAx_sNp-hQ.gif" /><figcaption>5 Vertical bars GIF</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0761e0a63165b53f644b661b5690c310/href">https://medium.com/media/0761e0a63165b53f644b661b5690c310/href</a></iframe><ol><li>Create a <strong>Capsule</strong> shape with style as <strong>continuous </strong>and<strong> </strong>frame of 10x50.</li><li>Here, we are animating container view <strong>HStack</strong> instead of a capsule by changing its width and spacing based on <strong>shouldAnimate</strong> state variable.</li><li>Look how child views are animated nicely when we change the container view’s width and spacing.</li><li>Using <strong>easeInOut</strong> animation with .<strong>repeatForever(autoreverses: true) </strong>to get a nice reverse animation with a <strong>1-second</strong> duration.</li></ol><h3>3 Scaling Circles</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/530/1*55EegehSCK1AtqFdHu7NRg.gif" /><figcaption>3 scaling circles GIF</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f707f6e110a182e6cbcb1f6eda3de978/href">https://medium.com/media/f707f6e110a182e6cbcb1f6eda3de978/href</a></iframe><ol><li>Create three circles using <strong>Circle</strong> shape in SwiftUI with a 20x20 width and height.</li><li>Here we are animating the <strong>scale</strong> property of the circle using <strong><em>.scaleEffect()</em></strong> modifier based on <strong>shouldAnimate </strong>state variable</li><li>The delay in the second and third circles avoids all circles scaling up and down at the same time.</li><li>Use <strong>easeInOut</strong> animation with .<strong>repeatForever(autoreverses: true) </strong>to get a nice reverse animation with a <strong>0.5 </strong>second duration.</li></ol><h3>Circle with Waves</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*gwQB_VLm07m11ZLyO35d2g.gif" /><figcaption>Circle with waves GIF</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e28c6baf9880b47ada15c88c26760d4b/href">https://medium.com/media/e28c6baf9880b47ada15c88c26760d4b/href</a></iframe><ol><li>Create a base circle using the <strong>Circle</strong> shape in SwiftUI with a 30x30 width and height.</li><li>Here we are animating <strong>scale</strong> property of the overlay circles using <strong><em>.scaleEffect()</em></strong> modifier based on <strong>shouldAnimate </strong>state variable.</li><li>We have added different scale values for overlay circles to get a wave effect.</li><li><strong><em>stroke()</em></strong> is like a border, which is recommended for shapes. <strong><em>stroke()</em></strong> applies the border half inside and half outside of the shape.</li><li>Use <strong>easeInOut</strong> animation with .<strong>repeatForever(autoreverses: false) </strong>to get one-way animation with a<strong> 1 </strong>second duration.</li></ol><h3>Conclusion</h3><p>We can create any complex animations with less code and effort using SwiftUI. We have seen the basics level of it. Play with default animation provided by SwiftUI to craft your animation using the <strong><em>.animation()</em></strong> modifier as you need it.</p><p>The complete code is available <a href="https://github.com/karthironald/ActivityAnimations">here</a>.</p><p>Thanks 👨🏻‍💻</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9815ff6abb80" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/create-an-awesome-loading-state-using-swiftui-9815ff6abb80">Create an Awesome Loading State Using SwiftUI</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[Accessing static members using Self in Swift 5.1]]></title>
            <link>https://karthickselvaraj.medium.com/accessing-static-members-using-self-in-swift-5-1-dcd909935742?source=rss-251b31c2631f------2</link>
            <guid isPermaLink="false">https://medium.com/p/dcd909935742</guid>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[xcode]]></category>
            <dc:creator><![CDATA[Karthick Selvaraj]]></dc:creator>
            <pubDate>Thu, 14 May 2020 13:35:56 GMT</pubDate>
            <atom:updated>2020-05-14T13:35:56.716Z</atom:updated>
            <content:encoded><![CDATA[<p>You might have declared static properties or functions in your type (class or structs) to organize the type-specific data for better readability.</p><p>Static properties belong to the type itself rather than an instance of the type, which means you no need to create an instance of the type to access the static properties. Check below code snippet for the example.</p><p>I have declared a <strong>ContentView</strong> and its static property <strong>names</strong>. I have accessed it directly from it type <strong>ContentView </strong>rather than an instance of the<strong> ContentView() </strong>and used it in my <strong>List </strong>to show it in UI.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/675f0d935d294ce7469ca12e3b10db7e/href">https://medium.com/media/675f0d935d294ce7469ca12e3b10db7e/href</a></iframe><p>Everything in the works fine.</p><p>What if you have changed the type name something like <strong>ContentViewWithVeryLargeName?</strong></p><ol><li>Readability gets compromised</li><li>You need to update the same in all places where you accessed static <strong>names </strong>using type names.</li></ol><p>That’s where Swift 5.1 update helps us, we can access the static properties using <strong>Self </strong>(capital S)<strong> </strong>instead of the type name. No need to type such a long type name and worry about readability. We can simply access like below,</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/06f94dde24c0fb97715ce18bcc8e7655/href">https://medium.com/media/06f94dde24c0fb97715ce18bcc8e7655/href</a></iframe><p>Reference: <a href="https://github.com/apple/swift-evolution/blob/master/proposals/0068-universal-self.md">SE-0068</a></p><p>Thanks! 👨🏻‍💻</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dcd909935742" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Guide to Property Wrappers in SwiftUI]]></title>
            <link>https://medium.com/better-programming/property-wrappers-in-swiftui-63bae630bb5a?source=rss-251b31c2631f------2</link>
            <guid isPermaLink="false">https://medium.com/p/63bae630bb5a</guid>
            <category><![CDATA[mobile]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Karthick Selvaraj]]></dc:creator>
            <pubDate>Thu, 07 May 2020 03:52:18 GMT</pubDate>
            <atom:updated>2020-05-11T15:31:38.971Z</atom:updated>
            <content:encoded><![CDATA[<h4>@State, @Published, @EnvironmentObject, and more</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pF35bGJMa6gukB01" /><figcaption>Photo by <a href="https://unsplash.com/@punttim?utm_source=medium&amp;utm_medium=referral">Tim Gouw</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a>.</figcaption></figure><p>SwiftUI has a number of property wrappers for different purposes to make developers’ lives easier. I would like to share some notes about these wrappers. Let’s get started.</p><h3><strong>@State</strong></h3><ul><li>We can modify the value of the struct by using this struct as a value type.</li><li>This is meant to store simple types like String, Int, Bool, etc.</li><li>We need to use this inside a view and it’s recommended to make it private.</li><li>We should provide a default value.</li><li>It can be used as a binding.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4ff1ba9863f9d17afbb4626e2168265f/href">https://medium.com/media/4ff1ba9863f9d17afbb4626e2168265f/href</a></iframe><h3><strong>@ObservedObject</strong></h3><ul><li>We can use this when we want to pass a complex object between views, and all views will be notified when the object changes.</li><li>The type should conform to the ObservableObject protocol.</li><li>We need to mark properties in the object as @Published to indicate changes to the view that is actively using the object.</li><li>The object type should be a class.</li><li>We should provide a default value.</li><li>Let’s assume we have a MenuData class that conforms to ObservableObject<strong> </strong>and<strong> </strong>marked one of its property menus as @Published.<strong> </strong>Whenever this menu changes, it will notify all actively using views. In our case, it’s ContentView:</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c0b95d0fb7b57a4e40bea55621b040a4/href">https://medium.com/media/c0b95d0fb7b57a4e40bea55621b040a4/href</a></iframe><ul><li>If none of the views actively are using the object, the published data will be ignored.</li></ul><h3><strong>@EnvironmentObject</strong></h3><ul><li>It is similar to @ObservedObject.</li><li>The type should conform to the ObservableObject protocol.</li><li>We need to mark properties in the object as @Published to indicate changes to the view that is actively using the object.</li><li>The object type should be a class.</li><li>There’s no need for the default value because it can read the default value from the environment. If the object is not available in the environment, the app will crash.</li><li>There’s another major difference: Say we have five views(V1…V5). If we want to pass an object directly from V1 to V5, we could use @EnvironmentObject rather than @ObservedObject. Set the data to be passed in the environment from V1 and retrieve it in V5 (or wherever needed). The code will be much simpler.</li><li>We can have only one instance of a type at a time in the environment.</li><li>It is purely based on views. If a parent view sets the environment object, all of its children can make use of it. If another parent view sets another environment object, their children can make use of it:</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d90200630d828cc387a416bafc5bf6db/href">https://medium.com/media/d90200630d828cc387a416bafc5bf6db/href</a></iframe><h3>@Environment</h3><ul><li>We can use this to get system-related values, like whether the app is running in Light or Dark mode, core data’s managed object context, size classes, etc.</li><li>We need to provide proper keys to access the value because it can hold the same data type against multiple keys:</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2475c3321c1843ab985c6307da7e2660/href">https://medium.com/media/2475c3321c1843ab985c6307da7e2660/href</a></iframe><h3><strong>@Binding</strong></h3><ul><li>This is used to maintain shared data between views.</li><li>The best example is presenting a sheet from View 1 and initiating a dismiss action from View 2.</li><li>We need to declare a property using @Binding.</li><li>There’s no need for a default value, as it will set it from another view.</li></ul><h3><strong>@GestureState</strong></h3><ul><li>This is similar to @State.</li><li>The only difference is as soon as gestures end, the default value gets set. Whereas in @State, the last set value is persisted.</li></ul><h3>@Published</h3><ul><li>This is used to make an announcement to the view to rerender its body property whenever a property is updated in an object.</li><li>We need to use this with the ObservableObject protocol.</li><li>If a class conforms to the ObservableObject, we can mark one or all properties in the class as @Published.</li><li>SwiftUI will make an announcement to all views that are actively using the object whenever data is changed in the class’ @Published properties:</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e260b8d5ded455d33246b3976f84fc1b/href">https://medium.com/media/e260b8d5ded455d33246b3976f84fc1b/href</a></iframe><h3><strong>@FetchRequest</strong></h3><ul><li>We can use this to fetch data from core data and directly use it in a view. There’s no need to write any extra logic.</li><li>We need to pass the entity name and sort descriptor to fetch the data from core data.</li><li>We can provide an option predicate as well.</li><li>This implicitly has the behavior of @ObservedObject, so whenever an object changes, the view will be updated automatically:</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2d45c48e6ff65cd5a17c6f6962ae8253/href">https://medium.com/media/2d45c48e6ff65cd5a17c6f6962ae8253/href</a></iframe><h3>Conclusion</h3><p>These are a few important property wrappers in SwiftUI. All of them are designed to make the development process easy and less error-prone.</p><p>Thanks for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=63bae630bb5a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/property-wrappers-in-swiftui-63bae630bb5a">A Guide to Property Wrappers in SwiftUI</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[How to Pick an Image From Your Camera or Photo Library in SwiftUI]]></title>
            <link>https://medium.com/better-programming/how-to-pick-an-image-from-camera-or-photo-library-in-swiftui-a596a0a2ece?source=rss-251b31c2631f------2</link>
            <guid isPermaLink="false">https://medium.com/p/a596a0a2ece</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[mobile]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[swiftui]]></category>
            <dc:creator><![CDATA[Karthick Selvaraj]]></dc:creator>
            <pubDate>Sun, 03 May 2020 02:46:58 GMT</pubDate>
            <atom:updated>2020-05-17T23:53:50.799Z</atom:updated>
            <content:encoded><![CDATA[<h4>Add your phone’s photos to your SwiftUI app</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Itdjt0pPvXrMPwkBYI0qag.png" /></figure><p>SwiftUI is a wonderful announcement from WWDC19. As SwiftUI is a framework that is less than one year old, we don’t have rich declarative APIs for a lot of basic needs like picking an image from the photo library or camera, maps, etc.</p><p>As Apple always provides multiple options to achieve our needs in one way or another, we do have a few things in SwiftUI to integrate our existing UIView and UIViewControllers from UIKit with SwiftUI.</p><p>Those are called <a href="https://developer.apple.com/documentation/swiftui/uiviewrepresentable">UIViewRepresentable</a> and <a href="https://developer.apple.com/documentation/swiftui/uiviewcontrollerrepresentable">UIViewControllerRepresentable</a> protocols.</p><ul><li>The UIViewRepresentable protocol is used to integrate UIKit views with SwiftUI.</li><li>The UIViewControllerRepresentable protocol is used to integrate UIKit ViewControllers with SwiftUI.</li></ul><p>We are not going to talk in detail about those protocols today, there is a nice talk in WWDC19, please check out <a href="https://developer.apple.com/videos/play/wwdc2019/231/">this video</a> for more details.</p><p>We are going to use UIViewControllerRepresentable as we need to integrate UIImagePickerController (which is a ViewController in UIKit) with SwiftUI for accessing photos from the photo library or capturing a live photo from the camera.</p><h3>Final Result</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FC20VuwZE8No%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DC20VuwZE8No&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FC20VuwZE8No%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/583c29c447a43c96250b26658849da0f/href">https://medium.com/media/583c29c447a43c96250b26658849da0f/href</a></iframe><h3>What Is UIViewControllerRepresentable?</h3><ul><li>A protocol that we need to adopt in our custom SwiftUI view for integrating UIKit ViewControllers.</li><li>UIViewControllerRepresentable has two mandatory methods to conform to, makeUIViewController(…) and updateUIViewController(…).</li><li>ViewController initialization logics will go inside the makeUIViewController(…) method. We need to initialize UIImagePickerController in this method, we’ll do that in a while.</li><li>We need to update the instance of the initialized ViewController in the updateUIViewController(…) method whenever asked by SwiftUI to render the view on the screen to respond to state changes.</li><li>We have one more optional method in this protocol which is called makeCoordinator(). The coordinator manages communication between the ViewController and SwiftUI, such as the ViewController’s targets, actions, delegates, etc.</li><li>We will see all the above methods in action soon. Please check the below code and I will explain what’s inside of it.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c4e1e7bb0ef337dcd58660f82590207/href">https://medium.com/media/3c4e1e7bb0ef337dcd58660f82590207/href</a></iframe><h3>Explanation</h3><ul><li>Line 11: SUImagePickerView is the custom view struct with three properties that is adopted to the UIViewControllerRepresentable protocol.</li><li>Line 13 to 15: I have declared a property to mention the sourceType of the PickerController and two binding properties to notify the view which initialized the SUImagePickerView as soon as the user picks the image or cancels.</li></ul><p>Note: The @Binding property wrapper is used to share common data between views.</p><ul><li>Line 17: makeCoordinator(). Here we have initialized and returned our custom coordinator class.</li><li>Line 21: We are initializing UIImagePickerController with proper sourceType and setting the delegate as coordinator. This is our custom coordinator that is going to manage the image picker delegates and return the initialized image picker controller.</li><li>Line 28: As we don’t have anything to update in the image picker controller, we can leave it empty. You might get an error if you remove this method.</li><li>Line 34: This is our custom coordinator that handles the image picker controller’s delegate methods, extracts the user-selected image, and sets it in the shared image binding property.</li><li>Line 44 to 53: You may be aware of image picker controller delegate methods, which is where we will get a callback when the user picks an image or clicks the cancel button.</li><li>Line 46: We are creating SiwftUI’s Image using the returned UIImage from the picker controller and assigning it to a shared @Binding property.</li><li>Line 52 and 48: It is important to set the self.isPresented = false to dismiss the presented SUImagePickerView.</li></ul><h3>Code</h3><p>Please check the below code snippet for details on how we have initialized and presented our custom SUImagePickerView<strong><em> </em></strong>from the ContentView.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/de1065bb6256057b21ca21b5c4b6b339/href">https://medium.com/media/de1065bb6256057b21ca21b5c4b6b339/href</a></iframe><h3>Explanation</h3><p>In ContentView.swift, I have added logic to present the ActionSheet when the user taps on the image to ask for camera or photo library options.</p><p>As soon as the user taps any option, I will be presenting SUImagePickerView with the respective sourceType.</p><p>You can download and use SUImagePickerView.swift in your project. Please have a look at <a href="https://github.com/karthironald/SUImagePickerView">my GitHub repo</a> for the complete code.</p><h3>Conclusion</h3><p>You can almost integrate any UIViewController with SwiftUI.</p><p>The code in the ContentView.swift and SUImagePickerView.swift will be a little confusing if you read this without knowing about property wrappers like Binding, State, and view modifiers.</p><p>Reading a few basic details about these topics could be helpful to understand the flow.</p><p>Thanks!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a596a0a2ece" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/how-to-pick-an-image-from-camera-or-photo-library-in-swiftui-a596a0a2ece">How to Pick an Image From Your Camera or Photo Library in SwiftUI</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>
    </channel>
</rss>