<?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 Umut SERIFLER on Medium]]></title>
        <description><![CDATA[Stories by Umut SERIFLER on Medium]]></description>
        <link>https://medium.com/@umuts?source=rss-228cee5bd152------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Vxa4094D3wKtZsGDU7eA8Q.jpeg</url>
            <title>Stories by Umut SERIFLER on Medium</title>
            <link>https://medium.com/@umuts?source=rss-228cee5bd152------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 21:58:13 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@umuts/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 publish Github Action to Github Marketplace (iOS/macOS Applications)]]></title>
            <link>https://umuts.medium.com/how-to-publish-github-action-to-github-marketplace-ios-macos-applications-e5c099c5bcf8?source=rss-228cee5bd152------2</link>
            <guid isPermaLink="false">https://medium.com/p/e5c099c5bcf8</guid>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[github-actions]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[apple]]></category>
            <dc:creator><![CDATA[Umut SERIFLER]]></dc:creator>
            <pubDate>Thu, 04 May 2023 11:01:49 GMT</pubDate>
            <atom:updated>2023-05-04T11:01:49.747Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JBGaGirN9WKAL8lzPG-WDw.png" /></figure><p>It is recommended to check out <a href="https://umuts.medium.com/github-actions-ci-cd-methods-for-ios-applications-c4ee0302153e">this article</a> to understand how the Github Action works and what the basic definitions are.<em> It is known that CI/CD tools are highly important for the projects’ quality and using resources efficiently.</em></p><p>We all agree that in the projects we work with nowadays, using CI/CD tools is highly important to increase efficiency, sustainability and performance, as well as to manage human resources effectively. In the light of this awareness, we must manage our projects efficiently via taking some actions using dedicated triggers.</p><p>There are a lot of different ways to achieve this. In other words, we can find many different tools or approaches working with CI/CD such as using Jenkins, Fastlane, Bitrise, or Github Actions — on which we’ll dive deep into creating our custom workflow and publishing it to the Github Marketplace to be able to use it across various projects. We certainly can identify a lot of differences in terms of advantages and disadvantages. However, besides its power, another reason to choose Github Action is that it is widely used and the company like Github stands behind it. Furthermore, it gives pretty much control to you that can be checked through the documentations.</p><p>It is time to start walking from broad perspective to narrowed topic. I’d like to mention <a href="https://github.com/marketplace">Github Marketplace</a> where we’ll publish our actions and we can find different actions or apps published by other developers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/318/1*_QWBm9azeb533Zcbw6ulOA.png" /><figcaption>Github Marketplace</figcaption></figure><p>You can visit the marketplace to check out different actions or apps developed by developers or companies, and do some investigation on them in case you want to use any of them for your projects.</p><p>There are some necessities to publish our custom actions to the Github Marketplace such as ensuring that the repository only includes the metadata file, code, and files for an action. Github also uses the action’s metadata on your Github Marketplace page.</p><p>When we want to publish an action to Github Marketplace, it is not reviewed by Github and immediately published as long as they meet the requirements which are listed below;</p><ul><li>The action must be in a public repository.</li><li>Each repository must contain a single action.</li><li>The action’s metadata file (action.yml or action.yaml) must be in the root directory of the repository.</li><li>The name in the action&#39;s metadata file must be unique.</li><li>The name cannot match an existing action name published on Github Marketplace.</li><li>The name cannot match a user or organization on Github, unless the user or organization owner is publishing the action. For example, only the Github organization can publish an action named github.</li><li>The name cannot match an existing Github Marketplace category.</li><li>Github reserves the names of Github features.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d27939acf4c00c8ee8b120899ceb5fd0/href">https://medium.com/media/d27939acf4c00c8ee8b120899ceb5fd0/href</a></iframe><h4>Metadata Syntax</h4><p>After checking and providing requirements list shown above, we should also decide an icon and a color for our action’s appearance in the marketplace. There is a <a href="https://feathericons.com/">website</a> where we can check which icons are available for badging. <strong>Some icons are omitted</strong>!</p><p>name <strong>Required</strong> The name of your action. Github displays the name in the Actions tab to help visually identify actions in each job.<br>author <strong>Optional </strong>The name of the action’s author.<br>description <strong>Required</strong> A short description of the action.<br>inputs <strong>Optional</strong> Input parameters allow you to specify data that the action expects to use during runtime.<br>Input has also some associated identifiers such as: <br>input_id, input_id_description, input_id_required, input_id_default, input_id_deprecationMessage.</p><p>We will mainly use required fields to keep the action simple for this article but it is recommended using all possible options to make your flow explanatory.</p><p>&lt;projectName&gt; : It stands for the project name which will be built and uploaded.</p><p>The next four definitions are copied from the certification process article from Github Documentation. <a href="https://docs.github.com/en/enterprise-server@3.4/actions/deployment/deploying-xcode-applications/installing-an-apple-certificate-on-macos-runners-for-xcode-development#add-a-step-to-your-workflow">Please check out it for details</a>.</p><p>&lt;certificateBase64&gt; <br>&lt;p12_Password&gt; <br>&lt;provisionProfileBase64&gt; <br>&lt;keychainPassword&gt;</p><p>Now, we need some keys and credentials to upload the created .ipa file to Testflight. Those can be found <a href="https://appstoreconnect.apple.com/access/api">App Store Connect API</a>. After providing the credentials, we should keep them in <a href="https://docs.github.com/en/actions/security-guides/encrypted-secrets">Github Secrets</a> to prevent for malicious intervenient access.</p><p>Let’s look at the process to understand how to generate these credentials;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XymBhykm2VwAJBE5jZD2jA.png" /><figcaption>ApiKey Creation</figcaption></figure><p>To create a new .p8 file, after pressing “ + ” button we should name and provide access level such as admin, app manager, developer, etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/490/1*r-qqPzEHY4qRnE-0zYb1pQ.png" /><figcaption>AuthKey_&lt;KeyId&gt;.p8</figcaption></figure><p>After the key has been created, AuthKey_&lt;KeyId&gt;.p8 file needs to be downloaded to copy encrypted data from inside. The copied key must be saved in Github Secrets to use in your workflow and it must be read by your published action when it is needed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S3SGzZ39IJX1LLQVDOgMcw.png" /><figcaption>Data in the AuthKey_&lt;KeyId&gt;.p8 file</figcaption></figure><p>We also need Issuer ID and Key ID which are seen in the image above (ApiKey Creation) where you can find. They are named appStoreApiId , appStoreApiIssuer in the workflow.</p><p>Depending on your action type, runs field can be defined from one of the available action types. This article contains a definition of actions for composite action type.</p><pre>runs:<br>  using: &#39;composite&#39;</pre><p>Last important thing for an action definition is setting shell using the shellkeyword. Details can be seen <a href="https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsshell">here</a>.</p><p>When the workflow is completed, it is time to create a public repository for our action. Yes, all actions, which will be published on the Github Marketplace, must be defined in a public repository.</p><p>The sample workflow can be copied from the link below;</p><p><a href="https://github.com/UmutSERIFLER/publish-ios-appstore">GitHub - UmutSERIFLER/publish-ios-appstore: Publish your iOS applications to Testflight - Appstore</a></p><p>After we’re done finalising our workflow, we must release via <br>Draft a new release button,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Mo326nnJtN3rCOzwYtSz8Q.png" /><figcaption>Draft a new release</figcaption></figure><p>We must also configure the settings for tagging and categorising from the menu which we’ll get as a second step.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UAf2hPMSMEIcBqJ8H9HxnQ.png" /><figcaption>Config Menu — Github Workflow</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/476/1*DWWtPNNu8v54obWaoxALUw.png" /></figure><p>Categorising is an important step to make our workflow more popular and to get more attention on it.</p><p>Finally, we’ll get Publish release button after we’ve completed all the steps explained above.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OoH8gyi7C2qlRZV7pwD_5A.png" /></figure><p><em>I hope you enjoyed reading. Please leave a comment if you have any question or suggestion.</em></p><p>Source:</p><ul><li><a href="https://docs.github.com/en/actions/learn-github-actions/understanding-github-actions">Understanding GitHub Actions - GitHub Docs</a></li><li><a href="https://docs.github.com/en/actions/using-jobs/using-jobs-in-a-workflow">Using jobs in a workflow - GitHub Docs</a></li><li><a href="https://docs.github.com/en/actions/deployment/deploying-xcode-applications/installing-an-apple-certificate-on-macos-runners-for-xcode-development">Installing an Apple certificate on macOS runners for Xcode development - GitHub Docs</a></li><li><a href="https://docs.github.com/en/actions/creating-actions/publishing-actions-in-github-marketplace">Publishing actions in GitHub Marketplace - GitHub Docs</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e5c099c5bcf8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[GitHub Actions: CI/CD methods for iOS applications]]></title>
            <link>https://umuts.medium.com/github-actions-ci-cd-methods-for-ios-applications-c4ee0302153e?source=rss-228cee5bd152------2</link>
            <guid isPermaLink="false">https://medium.com/p/c4ee0302153e</guid>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <category><![CDATA[github-actions]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[automation]]></category>
            <dc:creator><![CDATA[Umut SERIFLER]]></dc:creator>
            <pubDate>Fri, 24 Feb 2023 05:02:34 GMT</pubDate>
            <atom:updated>2023-02-24T05:02:34.530Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/821/1*H8AFoIUv8dWthd3zl_1PmA.png" /></figure><p><strong>GitHub Actions:</strong><br> It is a Continuous Integration / Continuous Delivery (deployment) platform <br> — Automates build / test / deployment pipeline<br> — Runs workflows that build and test repository or deploy it to production</p><p>Workflows, which are defined by a YAML file, are guidelines and triggered when an event occurs in the repository, such as a new branch being created or any change being pushed to a branch.</p><p>Let’s quickly look at how to set up GitHub Action:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/882/1*8uvZKARbQ5T1bFQ5ewoJmA.png" /></figure><p>You’ll get a start screen with four different categories:<br>1 — Automation<br>2 — Continuous Integration<br>3 — Deployment<br>4 — Pages</p><p>The beginning step is optional here which means either you can start using some ready-to-use workflows or you can create a new workflow under the branch where you want to save it. Alternatively, you can also use your existing .yml/.yaml file which is used for another CI/CD tool by modifying it for GitHub Actions.</p><p>Let’s start with creating a new workflow under the Actions section:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/680/1*j8xkKafKsc1lNNs21hf2jQ.png" /></figure><p>When you click the <strong>New workflow</strong> button, you’ll be directed to the Actions page which shows the workflows provided by GitHub.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ElCE0V1Bf8hhg3wuA5c3ZQ.png" /></figure><p>To reach more actions provided by other developers, you can visit the link below:</p><p><a href="https://github.com/marketplace?type=actions">Build software better, together</a></p><p><strong>!!! It is important to be careful about using actions which are developed by someone else or another company. In case they remove or stop maintaining the action, your CI/CD system might be outdated or fail during the process. Or, one of your steps might also have a dependency to another step in the workflow which will cause a process to fail.</strong></p><p>Let’s start by creating .yml/.yaml file in our repository:</p><p><strong>on</strong>: The on keyword lets you define the events that are triggered when the workflow runs. You can define multiple events here such as pull_request, create, delete, push, fork, etc.. Each of these events can also be defined for different branches and run on the machines individually.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5fd2e387224ec51911838efc900fa415/href">https://medium.com/media/5fd2e387224ec51911838efc900fa415/href</a></iframe><p><strong>jobs</strong>: A workflow is made up of one or more jobs, and they run in parallel by default. If you want to use multiple jobs and run them sequentially, they must have a unique id.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2da3a5cf7520626aa5fb1a2eeaff156c/href">https://medium.com/media/2da3a5cf7520626aa5fb1a2eeaff156c/href</a></iframe><p><strong>runs-on</strong>: This value defines the machine which your job will run on. It is important to be aware of the fact that using the GitHub-hosted runner causes running each job in a fresh instance of a runner image.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1bbaf52be462d2a29d878742df44ddae/href">https://medium.com/media/1bbaf52be462d2a29d878742df44ddae/href</a></iframe><p><strong>steps: </strong>Steps is the name of a sequence of tasks in a job. It can either set up tasks or run commands, or run an action in our repository, or an action published in a Docker registery. “Not all steps run actions, but all actions run as a step”.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c79d31643cf299ff1ca83d3c1e093e4f/href">https://medium.com/media/c79d31643cf299ff1ca83d3c1e093e4f/href</a></iframe><p><strong>run</strong>: The run keyword tells the job to execute a command on the runner.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8e21e09ca49dc1f7a4ebd9c1f8bdcc1a/href">https://medium.com/media/8e21e09ca49dc1f7a4ebd9c1f8bdcc1a/href</a></iframe><p>These are basics needs to be defined in the workflow, in the .yml / .yaml file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6718d8d441c2925d4e8c7d5a4bf85ea1/href">https://medium.com/media/6718d8d441c2925d4e8c7d5a4bf85ea1/href</a></iframe><p><em>To use an action in the workflow, </em><em>uses: keyword is used as a definition but to run any command for the step, </em><em>run: is used as a definition.</em></p><p>The workflow shown above contains quitely simple steps. It follows the steps listed below respectively;<br>1. When this workflow will run: It runs whenever a push event occurs.<br>2. Define jobs <br>build: job id &lt;unique&gt; <br>runs-on: GitHub-hosted runner, macos-latest is selected. <br>steps: There are 3 steps defined here: Checkout Repository Build Test<br>name: Step’s name will be printed in the workflow process view.</p><p>Workflows are mostly built up with more steps when you need to distribute to testers or to deploy your application to markets. So, there are other concepts you will need to use such as secrets, variables.</p><h4>Secrets</h4><p>Secrets are very useful variables that you can create in an organisation repository, or in a repository environment. Secrets can be added from the Settings tab in the repository, and under Secrets and variables title.<br>Secrets are not visible in the progress view and require confirmation to make any change on it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/556/1*v8wDi2V65OnaGu551MakEA.png" /></figure><p>You can use secrets for certifications, profiles or keys.</p><p>In a workflow, secrets can be read like ${{ secrets.defined_variable }}.</p><h4><strong>Variables</strong></h4><p>Variables provide a way to store and reuse non-sensitive configuration information. It can be used for server names, compiler flags, or usernames.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j5VUCVbaKa4fWrvHMhSONg.png" /></figure><p>The following rules apply to configuration variable names:</p><ul><li>Names can only contain alphanumeric characters ([a-z],[A-Z],[0-9]) or underscores (_). Spaces are not allowed.</li><li>Names must not start with the GITHUB_ prefix.</li><li>Names must not start with a number.</li><li>Names are not case-sensitive.</li><li>Names must be unique at the level they are created at.</li></ul><p>In a workflow, environment variables can be read like ${{env.MY_VARIABLE}}</p><h3><strong>Clean &amp; Build &amp; Test Application Workflow</strong></h3><p>Firstly, let’s analyse the steps individually with an explanation. Then, we can collect everything in to one workflow.</p><p><strong>Clean Project Step<br></strong>It checks out the repository and then using xcode command line tool to clean the project.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9f98f7a4552cf228cc55afc5701943cf/href">https://medium.com/media/9f98f7a4552cf228cc55afc5701943cf/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/754/1*R9vAQ-N7yRKlllDtf0WCWw.png" /></figure><p><strong>Build Project Step</strong><br>The workflow runs to build the project for testing for iPhone 14 Pro, OS=16.2 . It can be tested for different models and SDKs, other options can be checked from <a href="https://github.com/actions/runner-images/blob/main/images/macos/macos-12-Readme.md">here</a> under Installed SDKs title.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/aeedd033588ce3e2419f606948915a9b/href">https://medium.com/media/aeedd033588ce3e2419f606948915a9b/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GhS5u9lYorREyC6ITADdYQ.png" /></figure><p><strong>Test Project Step<br></strong>This workflow runs to test the project for iPhone 14 Pro, OS=16.2.<br>It runs all testing methods defined in Unit and UI testing classes.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/623bc2a5204b09009a3e5188e9aa49a7/href">https://medium.com/media/623bc2a5204b09009a3e5188e9aa49a7/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rOsBy4ZnQ11N7NqzI4VApg.png" /></figure><p>Let’s combine them together:</p><p>The workflow defined below runs when any change is pushed to the develop branch and the steps are cleaning, building and testing the application.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a6b3c103389cda805e57dbc96f1ffd10/href">https://medium.com/media/a6b3c103389cda805e57dbc96f1ffd10/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/1*gwhz0zeWy5V_oCGcAlNmEg.png" /></figure><p><em>I hope you enjoyed reading. Please leave a comment if you have any question or suggestion.</em></p><p>Source:</p><ul><li><a href="https://docs.github.com/en/actions/learn-github-actions/understanding-github-actions">Understanding GitHub Actions - GitHub Docs</a></li><li><a href="https://docs.github.com/en/actions/using-jobs/using-jobs-in-a-workflow">Using jobs in a workflow - GitHub Docs</a></li><li><a href="https://docs.github.com/en/actions/learn-github-actions/variables">Variables - GitHub Docs</a></li><li><a href="https://docs.github.com/en/actions/security-guides/encrypted-secrets">Using secrets in GitHub Actions - GitHub Docs</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c4ee0302153e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Advanced Drag&Drop in SwiftUI]]></title>
            <link>https://umuts.medium.com/advanced-drag-drop-in-swiftui-5c17e0d882da?source=rss-228cee5bd152------2</link>
            <guid isPermaLink="false">https://medium.com/p/5c17e0d882da</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[drag-drop]]></category>
            <dc:creator><![CDATA[Umut SERIFLER]]></dc:creator>
            <pubDate>Fri, 03 Feb 2023 06:57:19 GMT</pubDate>
            <atom:updated>2023-02-03T06:58:41.569Z</atom:updated>
            <content:encoded><![CDATA[<p>Moving content from one part of an app to another, or from one app to another app is provided by Drag&amp;Drop event handling.</p><p>Supports: iOS, iPadOS, Mac Catalyst 16.0+ / macOS 13+</p><p>Previously, I explained how to use simple Drag&amp;Drop functions by using Transferable protocol and also showed some basic concepts about the system default functions, which we can use without sweating a lot. To start, I recommend checking the <a href="https://medium.com/@umuts/drag-and-drop-in-swiftui-493aaa394cc1"><em>Drag&amp;Drop article</em></a><em> </em>before reading this more advanced article. Within this post, we’ll see different use cases for different content types.</p><p>Let’s shortly summarise some basic concepts:</p><h3>Transferable</h3><blockquote>A protocol that describes how a type interacts with transport APIs such as drag and drop or copy and paste.</blockquote><p>It is a Swift declarative way how models in an app can be serialised and deserialised for sharing and data transfer. Conforming Transferable protocol requires implementing <strong><em>TransferRepresentation</em></strong> property. <strong><em>TransferRepresentation</em> </strong>is used to import and export the item.</p><p>There are three important representations by default;</p><p>Data Transfer<br> — CodableRepresentation<br> — DataRepresentation<br><em>It is recommended to use CodableRepresentation rather than DataRepresentation if a model conforms to Codable.</em></p><p>File Transfer<br> — FileRepresentation<br><em>FileRepresentation is used to transfer a model which involves a large amount of data such as video.</em></p><p>Transfer Customisation<br> — ProxyRepresentation</p><p><strong>Definition</strong>:</p><blockquote>“ It is a Swift-first declarative way to describe how our models can be serialized and deserialized for sharing and data transfer “ <a href="https://developer.apple.com/videos/play/wwdc2022/10062/">WWDC Transferable</a></blockquote><p>We have to support sending our models over to a receiver inside our app or even in another application.</p><p>To give an example of where and when we want to use it, let’s assume there are two applications and we want to share any kind of data between them via ShareSheet, Drag&amp;Drop, Copy&amp;Paste or using some other app feature.</p><p>When we want to send something between two different apps, there is a lot of binary data that goes across. Determining what the data corresponds to is a quite important part. Either it might be text, video, url or data…</p><p>It is time to introduce <strong>UTType</strong> which is a structure representing the type of data that is used for loading, sending or receiving.</p><p>Official definition of UTType is:</p><blockquote>A structure that represents a type of data to load, send, or receive.</blockquote><p>UTType instance may represent any file type on disk, irrelevant hierarchical classification systems, or abstract data types which is not represented on-disk. In brief, when we have an object or data, no matter what it is or its type, and want to make it recognizable while sharing from one part of an application to another or between applications, we define a keyword, UTType , to represent the data or object. Each instance has a unique identifier and helpful properties such as <a href="https://developer.apple.com/documentation/uniformtypeidentifiers/uttype/3551552-preferredfilenameextension">preferredFilenameExtension</a> and <a href="https://developer.apple.com/documentation/uniformtypeidentifiers/uttype/3551553-preferredmimetype">preferredMIMEType</a> .</p><p>There are two ways of using a UTType instance in the app:<br>1. Using one of the existing types under <a href="https://developer.apple.com/documentation/uniformtypeidentifiers/uttype">Type Properties</a><br>2. Defining our own type in the app’s &lt;Info&gt;.plist</p><p>Using the first option is simpler and it mostly fits to general purpose of usage.<br>The second option is a more enhanced way but it requires a few more steps like following the instructions to name the identifier within the <a href="https://developer.apple.com/documentation/uniformtypeidentifiers/defining_file_and_data_types_for_your_app">defined rule list</a> or making the custom type unique.</p><p>It is shown in the code given below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/567/1*XhW6F68n6zk8mMeTnDa1NQ.jpeg" /><figcaption>ScrollView Right List</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/567/1*iqBqS1Nn7L-GjhRbiqebeg.jpeg" /><figcaption>ScrollView Left List</figcaption></figure><p>To use Drag&amp;Drop function with Transferable</p><pre>extension CellItem: Transferable {<br>    static var transferRepresentation : some TransferRepresentation {<br>        CodableRepresentation(contentType: .customType)<br>    }<br>}<br>extension UTType {<br>      static var customType: UTType { UTType(exportedAs: &quot;com.firstExample.identifier&quot;) }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/196/1*EiZG23p0dqlGSHAYI46lhA.gif" /><figcaption>Simple Drag&amp;Drop using Transferable</figcaption></figure><h3>NSItemProvider</h3><blockquote>An item provider for conveying data or a file between processes during drag-and-drop or copy-and-paste activities, or from a host app to an app extension.</blockquote><p>Since iOS 11 has been published, item providers play a central role in Drag&amp;Drop, and in Copy&amp;Paste. They are also still important for an app extension.</p><p>Before going deep, it is important to be aware that the system uses an internal queue when calling completion blocks for the <strong>NSItemProvider</strong> class. Using an item provider with Drag&amp;Drop essentially requires updating the UI on the main queue.</p><pre>DispatchQueue.main.async {<br>    // Work that impacts the user interface.<br>}</pre><p>NSItemProvider has multiple convenient initialisation methods, such as:<br> → <a href="https://developer.apple.com/documentation/foundation/nsitemprovider/1403911-init?changes=_8"><strong>init?(contentsOf: URL!)</strong></a><br> → <a href="https://developer.apple.com/documentation/foundation/nsitemprovider/4011311-init?changes=_8">init(contentsOf: URL, contentType: UTType?, openInPlace: Bool, coordinated: Bool, visibility: NSItemProviderRepresentationVisibility)</a><br>→ <a href="https://developer.apple.com/documentation/foundation/nsitemprovider/1403933-init?changes=_8">init(item: NSSecureCoding?, typeIdentifier: String?)</a><br> → <a href="https://developer.apple.com/documentation/foundation/nsitemprovider/2888323-init?changes=_8">init()</a><br> → <a href="https://developer.apple.com/documentation/foundation/nsitemprovider/2888328-init?changes=_8"><strong>init(object: NSItemProviderWriting)</strong></a></p><p>There are differences among them depending on the aim of use. In the following examples, I will demonstrate the two highlighted ones;</p><p>First approach is creating an instance with <strong>contentsOf</strong> init method:</p><pre>.onDrag {<br>  NSItemProvider(contentsOf: URL(string: cellItem.name))!<br>}</pre><p>For the <strong>onDrop</strong> method, we pass some parameters which are explained below:</p><pre>func onDrop(<br>    of supportedContentTypes: [UTType],<br>    isTargeted: Binding&lt;Bool&gt;?,<br>    perform action: @escaping ([NSItemProvider]) -&gt; Bool<br>) -&gt; some View</pre><p>supportedContentType: Describes the types of content this view can accept through Drag&amp;Drop. If it is used with unsupported types, isTargeted doesn’t update. <br>isTargeted: The binding’s value is true when the cursor is inside the area, and false when the cursor is outside.<br>action: Contains the dropped items, with types specified by supportedContentTypes .</p><pre>.onDrop(of: [.url],<br>        isTargeted: nil,<br>        perform: { providers in<br>    guard let replaceObjectIndex = objectList.firstIndex(where: { $0.id == cellItem.id }) else {<br>          return true<br>    }<br>    for item in providers {<br>        _ = item.loadObject(ofClass: URL.self) { url, _ in<br>             if let url = url {<br>                DispatchQueue.main.async {<br>                  objectList[replaceObjectIndex] = CellItem(name: url.absoluteString)<br>                }  <br>             }<br>          }<br>     }<br>  return true<br>})</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/196/1*ZnGpuPcrtmtUcPB5xClzNA.gif" /></figure><p>How it works: <br>Within the onDrag function, we provide an NSItemProvider instance using URL. This URL becomes a carrier to pass an important value for us to know which UTType is used and supported by the onDrop function. If the data you want to drag is not compatible with your supportedContentTypes, it shows notAllowed mark on the preview (shown below) and will not process the data as expected.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/124/1*yEOuXnLGF9UgmKr2bvTf0g.png" /><figcaption>Not Supported type for Drag&amp;Drop</figcaption></figure><p>Within the <strong>onDrop</strong> function, we firstly find an item’s index in the list to replace with the new data if all other requirements are met. Once the item index is ready, the dropped content type should be defined in order to get meaningful data. To make this transformation, one of the system methods loadObject can be used by providing an object type; hereURL.self . As a final step, with the data that we generated, &lt;itemIndex&gt; — &lt;url&gt;, we replace existing data with new one.</p><p>The second approach, which requires more effort due to its complexity, is creating an instance and using a custom type supported by DropDelegate:<br>There is a list of <a href="https://developer.apple.com/documentation/uniformtypeidentifiers/defining_file_and_data_types_for_your_app">naming conventions rules</a> you might want to check before going to the next step. After the naming of the custom type is clear, it must be added into the project &lt;Info&gt;.plist file following the hierarchy respectively Project Target → Info -&gt; Exported Type Identifiers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RbDh4oJXZiMneG6M1m6EFA.png" /><figcaption>Custom type definition Info .plist file</figcaption></figure><p>Here is a simple object definition:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*nwHo746YqxEIY0SAE5ysqQ.jpeg" /></figure><p>The <strong>onDrag</strong> function on the left-side list (Yellow), which is a transmitter list in our example, must embrace the NSItemProvider with an object. We use DraggableItem object as content and it gives a possibility of passing larger size of data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*0DMbLkCDY3RBmj2WC2OKIA.jpeg" /></figure><p>The <strong>onDrop</strong> function on the right-side list (Green), which is a receiver list in our example, must be contributed by providing supported types.<br>Even if there is a simple option, like shown below, this is not suitable for complex operations due to lack of flexibility:</p><pre>func onDrop(<br>    of supportedContentTypes: [UTType],<br>    isTargeted: Binding&lt;Bool&gt;?,<br>    perform action: @escaping ([NSItemProvider]) -&gt; Bool<br>) -&gt; some View</pre><p>The recommended option would be using a custom object, which is DraggableItemDelegate here, conforming to the <a href="https://developer.apple.com/documentation/swiftui/dropdelegate">DropDelegate</a> protocol which provides great methods such as validateDrop, dropEntered, dropUpdate, dropExited which you might need to use in different cases. Even though all are required methods, only dropUpdate doesn’t have a default implementation meaning we have to fill it in. We use the custom type here which we defined in the .plist file as a supported type.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*3OhZaVAuHE0DwJcrUZwdEA.jpeg" /><figcaption>onDrop Function Implementation</figcaption></figure><p>A parameter we gives into DraggableItemDelegate is a simple value that we use in the title of the list to show dropped data content.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*kCTSHMyaTuOFoFBFLMS3Qg.jpeg" /><figcaption>Custom object conforms to DropDelegate</figcaption></figure><p>In the performDrop method, we firstly check whether at least one item conforms to at least one of the specified UTIs (Uniform Type Identifier).</p><p>Then, we get an array of items and make type casting in order to turn the object into useful data for us.</p><p>Last step is using the data to update UI or save into the memory or in any way we want.</p><h3><strong>NSItemProviderWriting — NSItemProviderReading</strong></h3><blockquote><strong>NSItemProviderWriting</strong>: The protocol for implementing a class to allow an item provider to retrieve data from an instance of the class. A source app uses an object that conforms to this protocol to initialize an item provider for a copied or dragged item.</blockquote><blockquote><strong>NSItemProviderReading</strong>: The protocol for implementing a class to allow an item provider to create an instance of the class. A destination app uses an object that conforms to this protocol to consume pasted or dropped items.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*eBXLke7u8gGS2c2HXp6m5Q.jpeg" /><figcaption>NsItemProviderWriting</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*RSL_u8hNvmQCf8CFLzhJww.jpeg" /><figcaption>NSItemProviderReading</figcaption></figure><p>Here is the final result DropDelegate + Custom UTType:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/323/1*im8n6OZEwJq-Iu5gwKGiaw.gif" /><figcaption>Sample of Custom DropDelegate Usage</figcaption></figure><p><em>I hope you enjoyed reading. Please leave a comment if you have any question or suggestion.</em></p><p>Source:<br><a href="https://developer.apple.com/documentation/uniformtypeidentifiers/uttype">UTType</a> <br><a href="https://developer.apple.com/documentation/foundation/nsitemprovider">NSItemProvider</a><br><a href="https://developer.apple.com/design/human-interface-guidelines/patterns/drag-and-drop">Drag&amp;Drop Guideline</a><br><a href="https://developer.apple.com/documentation/uniformtypeidentifiers/defining_file_and_data_types_for_your_app">Defining File and data types</a><br><a href="https://developer.apple.com/documentation/bundleresources/information_property_list/utexportedtypedeclarations">Exported Types</a><br><a href="https://developer.apple.com/documentation/swiftui/drag-and-drop">Drag&amp;Drop Documentation</a><br><a href="https://developer.apple.com/documentation/foundation/nsitemproviderwriting">NSItemProviderWriting</a> || <a href="https://developer.apple.com/documentation/foundation/nsitemproviderreading">NSItemProviderReading</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5c17e0d882da" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Drag&Drop in SwiftUI]]></title>
            <link>https://umuts.medium.com/drag-and-drop-in-swiftui-493aaa394cc1?source=rss-228cee5bd152------2</link>
            <guid isPermaLink="false">https://medium.com/p/493aaa394cc1</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[drag-drop]]></category>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <dc:creator><![CDATA[Umut SERIFLER]]></dc:creator>
            <pubDate>Fri, 20 Jan 2023 21:40:17 GMT</pubDate>
            <atom:updated>2023-01-21T14:39:01.012Z</atom:updated>
            <content:encoded><![CDATA[<p>Moving content from one part of an app to another, or from one app to another is provided by Drag&amp;Drop event handling.</p><p>Supports: iOS, iPadOS, Mac Catalyst 16.0+ / macOS 13+</p><p>Depending on the userflow in the applications, we sometimes might need to drag&amp;drop content or item from one part of the app to another, or from one app to another. It is possible implementing this feature with various ways but choosing the way depends on how much time and resource we can allocate to finish it in time. Luckily, SwiftUI provides or accepts types that conforms <strong>Transferable </strong>protocol or inherits from <strong>NSItemProvider </strong>to our view modifiers. It is recommended using transferable items when possible.</p><h3>Transferable</h3><blockquote>A protocol that describes how a type interacts with transport APIs such as drag&amp;drop or copy&amp;paste.</blockquote><p>It is a Swift declarative way of serialising and deserialising models in app for sharing and data transfer. Conforming Transferable protocol requires implementing <strong><em>transferRepresentation</em></strong> property. <strong><em>transferRepresentation</em> </strong>is used to import and export the item.</p><p>There are three important representations by default;</p><p>Data Transfer<br> — CodableRepresentation<br> — DataRepresentation<br><em>It is recommended using CodableRepresentation rather than DataRepresentation if a model conforms to Codable.</em></p><p>File Transfer<br> — FileRepresentation<br>FileRepresentation is used to transfer a model involving a large amount of data such as video.</p><p>Transfer Customisation<br> — ProxyRepresentation</p><p>Before starting to make any change in our code, we should ask some questions to ourselves for drag&amp;drop function. I also strongly recommend reading, or at taking a glance at, the <a href="https://developer.apple.com/design/human-interface-guidelines/patterns/drag-and-drop">Drag&amp;Drop section in the Human Interface Guidelines</a> during the implementation.</p><ol><li>What do we want to achieve with Drag&amp;Drop?</li><li>How can we implement it in an effective way and reusable?</li></ol><p>For the first question; Even though there are many possible answers for it, finding the right answer is so important at this step because it will affect your workload and the code complexity. Depending on the objective, either we can use existing methods or define our custom methods. To keep this post simple, I’ll go with existing methods as solution.</p><p>For the second question: After we clarified our aim with Drag&amp;Drop, it is time to think how we can make it reusable when we need somewhere else in the app.</p><p>After we answered these questions, it is time to decide:<br><strong>Which type of representation should we use? or <br>Do we have to use any form of representation?</strong></p><p>We don’t always have to use a representation to achieve Drag&amp;Drop function but we have to use <strong>Transferable</strong> type.</p><p>The data we want to make draggable will take us to the answer, in other words, what kind of data needs to be transferred?</p><p>Let’s start coding to implement simple Drag&amp;Drop function:</p><ol><li>Let’s create a list which will contain our data to move</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/567/1*PfWyHgbtzP03Z4BUiGvcPA.jpeg" /><figcaption>Creates List for icons</figcaption></figure><p>With ForEach loop we can visualise our icons in the list like in the figure</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/50/1*ZiRVrI6MVYG87Z_GWOLk3g.png" /><figcaption>Icon List</figcaption></figure><p>Now we can easily make this Image draggable by adding instance method “<a href="https://developer.apple.com/documentation/swiftui/view/draggable(_:)">draggable</a>” to activate the view as the source of a drag operation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*usXRGt0KbbkcjibhMwRMMA.jpeg" /><figcaption>Draggable Function</figcaption></figure><p>The Draggable modifier function prototype is a defined generic type by Apple:</p><pre>func draggable&lt;T&gt;(_ payload: @autoclosure @escaping () -&gt; T) -&gt; some View where T : Transferable</pre><p>The “draggable” method takes a payload parameter as a single instance or a value conforming <strong>Transferable</strong>. Now it is ready to test for dragging:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/283/1*jNocAVEiji4uh-i4fDyvxw.gif" /><figcaption>Dragging Icons</figcaption></figure><p>Here, we need to define a property to keep our transferred data. We’ll use String type property but it might also be any other type of data such as Int, [Int], [String] etc..</p><pre>// Keep moved icon<br>@State private var movedIcon: Image = Image(systemName: &quot;x.circle&quot;)</pre><p>It is better giving some information about how the droppable function works or which parameters we need to provide and can use from it. As it was mentioned before, the dropped content type can be provided as binary data, file URLs, or file promises but here since we drag string in our example it has to be <strong>String.self</strong> .</p><p>The DropDestination function prototype is a defined generic type by Apple:</p><pre>func dropDestination&lt;T&gt;( for payloadType: T.Type = T.self,<br>                         action: @escaping ([T], CGPoint) -&gt; Bool,<br>                         isTargeted: @escaping (Bool) -&gt; Void = { _ in } ) -&gt; some View where T : Transferable</pre><p><strong>payloadType</strong>: The expected type of the dropped models</p><p><strong>action</strong>: A closure has two parameters: first parameter is dropped items, second parameter is the drop location of this view’s coordinate space.</p><p><strong>isTargeted</strong>: A closure that is called when a Drag&amp;Drop operation enters<br>or exits the drop target area. This feature can be used for animation or changing the UI like showing approve/cancel process icons.</p><p>If it is clear until now, let’s add the drop area to leave our data in and use a defined property to assign a new value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*_qHvvZOOGYPCWjWlPZEnXw.jpeg" /></figure><p>Let’s add this DraggableImageArea into our code</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*rHzipXBtpLV6DSQKmRxe9A.jpeg" /><figcaption>Droppable Area with Title, Button</figcaption></figure><p>This code above will present us text, image and button combination where an image is designated as a type droppable. It is very important defining a type of item for dropDestion function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/266/1*IMU_0ZD6tI45kG0acSh1lQ.png" /><figcaption>Image is droppable</figcaption></figure><p>The drop destination is has same size and position as this movedIcon view.</p><p><strong>Code</strong>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cf8be41fdfb97f082c7cc2edbdb15529/href">https://medium.com/media/cf8be41fdfb97f082c7cc2edbdb15529/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8954787016b08580148e782d19c774e0/href">https://medium.com/media/8954787016b08580148e782d19c774e0/href</a></iframe><p>The code is above designs the icon list and the image with clear button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/323/1*i5Q4toBVapiq0s7bSo9zlw.gif" /><figcaption>Example for dragging function</figcaption></figure><p>As it is shown in the sample above, after the item is selected from the left list it is ready to drag. Dropping the selected item is available only when the item is on image area.</p><p><em>I hope you enjoyed reading. Please leave a comment if you have any question or suggestion.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=493aaa394cc1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Animated Toggles with SwiftUI]]></title>
            <link>https://umuts.medium.com/animated-toggles-with-swiftui-4a678c01b704?source=rss-228cee5bd152------2</link>
            <guid isPermaLink="false">https://medium.com/p/4a678c01b704</guid>
            <category><![CDATA[animation]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[toggle]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swiftui]]></category>
            <dc:creator><![CDATA[Umut SERIFLER]]></dc:creator>
            <pubDate>Fri, 13 Jan 2023 18:10:05 GMT</pubDate>
            <atom:updated>2023-01-13T18:10:05.213Z</atom:updated>
            <content:encoded><![CDATA[<p>Supports: iOS, iPadOS, Mac Catalyst, tvOS 13.0+ / macOS 10.15+ /<br>watchOS 6.0+</p><p>One of the most common UI control components is Toggle which controls states between on and off.</p><p>Usage:</p><pre>@State private var isSelected: Bool = false<br>Toggle(isOn: $isSelected){ }</pre><p>As it can be seen in the example above, defining a label is not mandatory.</p><figure><img alt="Default Toggle Stlye" src="https://cdn-images-1.medium.com/max/118/1*EKFWDnk8icUNQvut9YyUsw.gif" /><figcaption>Default Toggle Style</figcaption></figure><p>Using a basic text-only label is quite simple. Convenience initialiser makes the title string the first parameter (localized string key) which is easier than trailing closure. When a label is used within Toggle, it is placed to the left side by default.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/288/1*y9qrqq45t-aL8xob8-qzPg.gif" /></figure><pre>Toggle(&quot;\(isSelected ? &quot;&quot; : &quot;Not &quot;)Selected&quot;, isOn: $isSelected)</pre><p>In most cases, using different default styles such as switch ,checkbox ,button as Toggle is enough. However, what should we do if we want to make it more fancy and effective? The keyword is ToggleStyle.</p><p><strong>ToggleStyle</strong></p><p>Toggle is set to .automatic by default for all platforms. DefaultToggleStyle is different depending on the platform. As it can be seen in the list below, macOS uses checkbox style (only available for macOS) by default; meanwhile, iOS/iPad/watchOS platforms use switch ToggleStyle by default.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7474d11d6fbc8ad836948d58adfb2b43/href">https://medium.com/media/7474d11d6fbc8ad836948d58adfb2b43/href</a></iframe><h4>Button Style (ButtonToggleStyle):</h4><blockquote>A toggle style that displays as a button with its label as the title</blockquote><p>With button ToggleStyle, blue foreground color is added to the button by default when it is selected.</p><figure><img alt="ButtonToggleStyle for iOS" src="https://cdn-images-1.medium.com/max/228/1*9wTgvGBWm2Xs0hdO_EQJYA.gif" /><figcaption>ButtonToggleStyle (iOS)</figcaption></figure><figure><img alt="ButtonToggleStyle for macOS" src="https://cdn-images-1.medium.com/max/190/1*SS2Y7GEkuujngE_j1pJrOw.gif" /><figcaption>ButtonToggleStyle (macOS)</figcaption></figure><pre>Toggle(&quot;\(isSelected ? &quot;&quot; : &quot;Not &quot;) Selected&quot;, isOn: $isSelected)<br>.toggleStyle(.button)<br>.foregroundColor(.black)</pre><h4>Switch Style (SwitchToggleStyle):</h4><p>Switch ToggleStyle is one of the most used UI components in the applications. However, by default, there is a small difference between macOS and iOS version which is the tint colour. This might cause an inconsistency between shared design view. So, it might need to be considered.</p><figure><img alt="SwitchToggleStyle for iOS" src="https://cdn-images-1.medium.com/max/336/1*82wl9yhvlTY9hWCxHPcwTQ.gif" /><figcaption>SwitchToggleStyle (iOS)</figcaption></figure><figure><img alt="SwitchToggleStyle for macOS" src="https://cdn-images-1.medium.com/max/190/1*WhUmKPF9GgWujG9il1GTjQ.gif" /><figcaption>SwitchToggleStyle (macOS)</figcaption></figure><pre>Toggle(&quot;\(isSelected ? &quot;&quot; : &quot;Not &quot;) Selected&quot;, isOn: $isSelected)<br>.toggleStyle(.switch)</pre><h4>Checkbox style (CheckboxToggleStyle):</h4><blockquote>A toggle style that displays a checkbox followed by its label.</blockquote><p>CheckboxToggleStyle is available only for macOS platform.</p><figure><img alt="CheckboxToggleStyle for macOS" src="https://cdn-images-1.medium.com/max/118/1*Ws7Bg2VzoCTTR1Cfo8OFgw.gif" /><figcaption>CheckboxToggleStyle — macOS</figcaption></figure><h3>Custom ToggleStyle</h3><p>Even though default ToggleStyles are mostly enough to use in the applications, we sometimes might want to give better visualisation to the users (also depends on your imagination). That’s why we should start talking about using Custom ToggleStyle that makes Toggle “flashy” and remarkable.</p><p>Before going deep, we should touch two concepts;<br>1. Body (View)<br>2. Configuration (ToggleStyleConfiguration)</p><p>Body:</p><blockquote>A view that represents the appearance and interaction of a toggle.</blockquote><p>This is a generally known associatedtype automatically based on the View by SwiftUI which is provided from makeBody function as return object <a href="https://developer.apple.com/documentation/swiftui/togglestyle/makebody(configuration:)">makeBody(configuration: Self.Configuration)</a>.</p><p>We’ll design our toggle button within this makeBody function.</p><p>ToggleStyle.Configuration:</p><blockquote>The properties of a toggle instance.</blockquote><p>When we want to use custom ToggleStyle, we should define a type which conforms to the ToggleStyle protocol. With this protocol, there is a method which we use for our Toggle appearance and behaviour, makeBody. This method requires ToggleStyleConfiguration parameter as input. There are some properties such as Label, isOn, isMixed. We can use these provided data for labelling the Toggle’s content and stating/binding Toggle status.</p><pre>func makeBody(configuration: Configuration) -&gt; some View {<br>     HStack {<br>        Image(configuration.isOn ? images.on : images.off)<br>             .resizable()<br>             .aspectRatio(contentMode: .fill)<br>             .overlay(<br>                 Circle()<br>                   .foregroundColor( configuration.isOn ? .yellow.opacity(0.8) : .clear)<br>                   .padding(.all, 5)<br>                   .offset(x: configuration.isOn ? 10 : 40)<br>                 )<br>                 .cornerRadius(25)<br>                 .onTapGesture {<br>                    withAnimation( .linear(duration: 3), {<br>                      configuration.isOn.toggle()<br>                    })<br>                  }<br>         }.frame(width: 50, height: 25)<br>    }</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/196/1*fk3GDpr92IpkUHHtVc9soQ.gif" /><figcaption>Dark / Light Mode toggle</figcaption></figure><p>Different animations can be applicable like below:</p><pre>Image(toggleImg)<br>   .resizable()<br>   .rotation3DEffect(.degrees(180), axis: (x: 0, y: positionStatus, z: 0))<br>   .aspectRatio(contentMode: .fit)<br>   .frame(width: 20, height: 20)<br>   .offset(x: configuration.isOn ? -10 : 40, y: 10)</pre><figure><img alt="Driving car as within custom toggleStyle" src="https://cdn-images-1.medium.com/max/186/1*eD2j8P91LjYA2a_KKLvnNQ.gif" /><figcaption>Enable / Disable Toggle</figcaption></figure><p>Source: <br><a href="https://developer.apple.com/documentation/swiftui/togglestyle">https://developer.apple.com/documentation/swiftui/togglestyle</a><br><a href="https://developer.apple.com/documentation/swiftui/togglestyleconfiguration">https://developer.apple.com/documentation/swiftui/togglestyleconfiguratio</a>n</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4a678c01b704" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>