<?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 Kresimir Bakovic on Medium]]></title>
        <description><![CDATA[Stories by Kresimir Bakovic on Medium]]></description>
        <link>https://medium.com/@kresimir.bakovic_27448?source=rss-a12f65145e96------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*E4I6tiilZNr3ypWB.jpg</url>
            <title>Stories by Kresimir Bakovic on Medium</title>
            <link>https://medium.com/@kresimir.bakovic_27448?source=rss-a12f65145e96------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 22:49:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kresimir.bakovic_27448/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[CI/CD in iOS development]]></title>
            <link>https://medium.com/azikus/ci-cd-in-ios-development-1e522769f3ed?source=rss-a12f65145e96------2</link>
            <guid isPermaLink="false">https://medium.com/p/1e522769f3ed</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[bitrise]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[continuous-integration]]></category>
            <dc:creator><![CDATA[Kresimir Bakovic]]></dc:creator>
            <pubDate>Tue, 06 Jun 2023 11:05:33 GMT</pubDate>
            <atom:updated>2023-06-06T11:05:33.700Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IakNmINgCrBLMKcIGgLPVA.jpeg" /></figure><p><strong>Your app is ready for internal or external testing, and you want to publish it as soon as possible to your testers, right? Every iOS developer knows what the next steps are → running the tests and creating a new build. This part of the development process is repetitive and time-consuming, so in this blog post we will go through it and check how it can be shortened and made more robust. A time-saving and proper solution for this is to set up CI/CD on your project. Let‘s cover basic definitions so we can move on to more important how-to sections. 🙂</strong></p><p><strong>Continuous integration (CI) is a DevOps software development practice where developers regularly merge their code changes into a central repository, after which automated builds and tests are run.</strong></p><p><strong>Continuous delivery (CD) is a software development practice where code changes are automatically prepared for a release to production. With continuous delivery, every code change is built, tested, and then pushed to a non-production testing or staging environment.</strong></p><h3>CI/CD flows</h3><p>If you want to set up <strong>CI/CD</strong> flow for your application, you can do it in multiple ways, but implementations can be separated into two main groups: <br>• <strong>Drag-and-drop implementations</strong> → offered by some of the providers (<a href="https://bitrise.io/"><strong>Bitrise</strong></a>), are easier to set up but usually cost more<br>• <strong>Custom script implementations</strong> → setup process is a little bit more complicated, but it‘s usually cheaper (<a href="https://github.com/"><strong>GitHub</strong></a>, <a href="https://bitbucket.org/product"><strong>Bitbucket</strong></a>)</p><p>In later sections, I will go through one example that requires writing of your own script for <strong>CI/CD</strong> flow. Also, I will make a short comparison between the providers mentioned above.</p><h3>GitHub Actions</h3><p>GitHub is for sure one of the most popular code managing systems out there. In 2018 <strong>GitHub</strong> introduced their platform-native automation tool called <strong>GitHub Actions</strong>. <strong>GitHub Actions</strong> is designed to help simplify workflows with flexible automation and offer easy-to-use <strong>CI/CD</strong> capabilities built by developers for developers. When it comes to pricing, there are several things to mention. First of all, <strong>GitHub actions</strong> is free for standard GitHub-hosted runners in <strong>public repositories</strong> and for <strong>self-hosted runners</strong>. On the other side, if you have a <strong>private repository</strong>, you will get free minutes based on your product. One image is worth 1000 words, so please take a look at the free tiers on the next image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AosDT2G3TQbVWr09P3DzQw.png" /><figcaption>Image 1. Free storage and minutes for private repositories</figcaption></figure><p>At first sight, this looks very promising and cheap, but like always, there is a catch. For <strong>macOS</strong> runners (sure, we need those), the minutes from the previous image are multiplied by 0.1😔 This means that we can only use <strong>GitHub Free</strong> for 200 minutes per month. If you are using <strong>Windows</strong> Runner, your minutes will be multiplied by 0.5 (still way better than <strong>macOS</strong>). All multipliers are shown in the next image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eBYC3OyB9OdR-CAKr-_WIA.png" /><figcaption>Image 2. Minute multipliers</figcaption></figure><p>The great thing about <strong>GitHub Actions</strong> is that it responds to web-hook events. It means that you can trigger desired workflows based on events defined in your repository. In my opinion, <strong>GitHub</strong> is nice and easy to use, and you can have everything (code, project boards, <strong>CD</strong> flow) in one place. I will list some of <strong>GitHub‘s</strong> pros and cons in the next couple of bullet points.</p><p><strong>Pros</strong></p><ul><li>ability to have everything in one place</li><li>webhook events</li><li>supports self-hosted runners</li><li>unlimited running minutes for public repositories</li></ul><p><strong>Cons</strong></p><ul><li>minutes for <strong>macOS</strong> runners are multiplied by 0.1</li><li>it takes some time to configure more complicated workflows</li></ul><h3>CI/CD flow using GitHub Actions</h3><p>In this section, two workflows that will cover the <strong>CI</strong> and <strong>CD</strong> parts of the development process will be explained. The first workflow will be designed for executing the <strong>tests</strong> on each pull request to the dev branch. The second workflow will be responsible for <strong>building the application</strong> (on the chosen branch) and uploading it to <strong>TestFlight</strong>.</p><p>Maybe we should take one step back and describe what a workflow is? Workflow is a configurable, automated process made up of one or more jobs. Jobs are some actions that are executed one after another, and you define their order of execution inside the <strong>YAML</strong> file. More information can be found on <a href="https://docs.github.com/en/actions/learn-github-actions/understanding-github-actions">Github‘s page</a>.</p><p>In order to start writing the scripts for the workflows, you need to create <strong>.github</strong> file in your project‘s folder. Files that start with a dot are hidden by default, so you can press <strong>SHIFT+COMMAND+DOT</strong> in order to see them. Inside <strong>.github </strong>folder, create a folder called <strong>workflows</strong>, where you will define all workflows that will be visible on the <strong>GitHub</strong> page of your repository. Those workflows will be later triggered by some action or manually by someone from your team (this will be described later on).</p><h3>Setting up CI flow</h3><p>This workflow will be triggered on each PR to <strong>dev</strong> branch (or manually), and it will run <strong>tests</strong> to ensure that the code that needs to be merged is passing all the tests and isn‘t breaking existing implementations and functionalities. This script, called <strong>testing_workflow.yaml</strong>, will be placed in the previously mentioned <strong>workflows</strong> folder. The script will not be explained in detail because it has meaningful and descriptive comments. Content of <strong>testing_workflow.yaml</strong>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f6be5e6bb39947e3e385e90a1ac97a38/href">https://medium.com/media/f6be5e6bb39947e3e385e90a1ac97a38/href</a></iframe><h3>Setting up CD flow</h3><p>This <strong>workflow</strong> will be triggered manually by the developer. You can choose the branch from which you want to upload your build to <strong>TestFlight</strong>. In order to make this work, we need to set up a couple of things first.</p><ul><li>Create a new workflow named <strong>build_export_workflow.yaml</strong> and put it inside the <strong>workflows</strong> folder</li><li>Make a scripts folder within .<strong>github </strong>folder</li><li>Create <strong>certs</strong> folder inside <strong>.github</strong> folder</li></ul><p>Now we have all the folders needed, and we can start adding <strong>scripts</strong> and <strong>certificates</strong> to them. In folder <strong>scripts,</strong> add the <strong>set_certificates.sh</strong> script:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d0ce869f9d2511e61e2cebc61f3dc5c9/href">https://medium.com/media/d0ce869f9d2511e61e2cebc61f3dc5c9/href</a></iframe><p>We will run this script from our workflow to decrypt our encrypted files, import the <strong>certificate</strong> to the new <strong>keychain,</strong> and set up the <strong>provisioning profile</strong>. In order for our build and export workflow to run on a remote machine, we need to configure some things:</p><ul><li>Encrypt a <strong>distribution certificate</strong> and <strong>provisioning profile</strong></li><li>Create an app-specific password for your <strong>Apple ID</strong></li><li>Configure <strong>Encrypted secrets</strong> in <strong>GitHub</strong>.</li></ul><p>Let‘s start with the encryption of the <strong>distribution certificate</strong> and <strong>provisioning profile</strong>. Go to the profiles section on your <strong>Apple developer</strong> account and create a <strong>provisioning profile</strong> for your iOS application. Download that profile and save it somewhere where you can find it. 😂</p><p>Now open your <strong>keychain</strong> and press on <strong>My certificates </strong>tab. There, you should be able to find the <strong>distribution certificate</strong> that you set for your <strong>provisioning profile</strong> in your <strong>Apple developer</strong> account. Press on that certificate, and its private key should appear below it. Right-click on that key and select <strong>Export</strong>. Enter a password when prompted to protect it, and write the password down — we will need it later.</p><p>The next step is to encrypt the exported <strong>certificate</strong> and <strong>profile</strong>. For encryption and decryption, we’ll use a tool called <strong>gpg;</strong> it uses one-way cryptographic algorithms to provide military-grade encryption.<br>Open <strong>Terminal</strong> and type <strong>brew install gpg </strong>to get it set up on your machine. Then, for each file, run <strong>gpg — symmetric — cipher-algo AES256 your_file&gt; </strong>and enter a passphrase. Please write the passphrases down, as we will use them later for the file decryption.<br>Please rename both of these encrypted files like this: <strong>app.mobileprovision.gpg</strong> and <strong>app.p12.gpg</strong>. After that, place those files in the <strong>certs</strong> folder (we previously created it).</p><p>In order to create an <strong>App-specific password</strong>, please visit this <a href="https://appleid.apple.com/sign-in">page</a>.<br>After a successful login, go to the <strong>App-specific password</strong> section. There, you can generate <strong>App-specific password</strong> needed for <strong>GitHub Actions</strong>. Write down the generated password because it will be used later on.</p><p><strong>GitHub Actions</strong> secrets are next on the list. Secrets let you store sensitive information right in your <strong>GitHub</strong> repository. Navigate to <strong>Settings</strong> in your repository, then <strong>Secrets → Actions</strong>. We need to add four items that we created earlier:</p><ul><li><strong>APP_SPECIFIC_PASS</strong> <strong>→ Apple ID</strong> specific password (one that you generated in the previous step)</li><li><strong>DECRYPTION_PASS_CERTIFICATE → </strong>certificate encryption passphrase</li><li><strong>DECRYPTION_PASS_PROFILE → </strong>profile encryption passphrase</li><li><strong>KEYCHAIN_EXPORT →</strong> password for exporting your <strong>.p12</strong> file from the keychain</li></ul><p>The next step is to add actual workflow code to the existing <strong>build_export_workflow.yaml</strong> file like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/796dfcbfcc0f51c29e1dd0e83d867571/href">https://medium.com/media/796dfcbfcc0f51c29e1dd0e83d867571/href</a></iframe><p>The last step is to add a F<strong>astlane</strong> folder to the root of your project and add a <strong>Fastfile</strong> file to it. The content of the <strong>Fastfile</strong> is explained and listed below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/acf4f386a4b5f47b0ce182cda3990c39/href">https://medium.com/media/acf4f386a4b5f47b0ce182cda3990c39/href</a></iframe><p>In the next image you can see contents of <strong>workflows</strong> folder mentioned earlier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iPFdjwjG078NLaWIFbp8NA.png" /><figcaption>Image 3. Contents of <strong>worflows</strong> folder</figcaption></figure><h3>How to run workflows?</h3><p>The<strong> CI</strong> flow that we created and explained in the sections above will be automatically run when some of the developers make PRs to the base branch (dev in our example).<br>If you want to run the newly created <strong>CD</strong> workflow, go to the <strong>GitHub</strong> page of your project and open the <strong>actions</strong> tab. On the right side, you will see all available workflows. Press on created <strong>build_export_workflow </strong>and on the right side, tap on the <strong>Run workflow </strong>button. Select the branch on which you want to run the workflow from the drop-down, and that’s it; pressing the green button will start the selected workflow, and when it’s finished, your app will be available for testing on <strong>TestFlight</strong>. 🚀</p><h3>Bitrise</h3><p>If you want the easiest solution for your <strong>CI/CD</strong> flow, <strong>Bitrise</strong> is the option that you are looking for. A nice looking UI and drag-and-drop configuration of the workflow ensure quick setup. <strong>Bitrise</strong> offers a wide range of integrations with popular tools and frameworks like Xcode, Cocoapods, Carthage, and Fastlane, which allow developers to build and test their iOS apps on virtual machines (VMs) or real devices. <strong>Bitrise</strong> also offers automatic code signing, which simplifies the process of signing your app with your <strong>Apple Developer</strong> account. It offers a powerful workflow editor that allows you to create custom workflows that define the steps of your <strong>CI/CD</strong> process. You can add steps to build, test, and deploy your app, and even add custom scripts to automate specific tasks. You can also define triggers for your workflows, such as triggering a build when a new code change is pushed to your repository. <strong>Bitrise</strong> makes it easy to deploy your iOS app to Apple’s <strong>App Store</strong> or other distribution channels, such as <strong>TestFlight</strong>. It also supports multiple distribution channels and offers a range of integrations with popular deployment tools like Fastlane and <strong>HockeyApp</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dbJMaZ9ZIa2zTs7v-zoQcg.png" /><figcaption>Image 4. Bitrise steps</figcaption></figure><p><a href="https://devcenter.bitrise.io/en/getting-started.html">Here</a> you can find more info about Bitrise setup.</p><h3>Pricing comparison</h3><p>In this section, I am going to compare pricing options for the providers mentioned in the text above (GitHub, Bitrise, Bitbucket).</p><p>I think that the best overview of the prices can be shown in a chart, so I made one below. I am going to compare the <strong>Free plan </strong>for all of the providers, and you can find more info about other plans on the links at the bottom of this section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P-khQdpEgU5ZZ4ShJcasbA.png" /><figcaption>Image 5. Free minutes for macOS runners</figcaption></figure><p>On the chart above, you can see that <strong>GitHub</strong> gives the most minutes in the <strong>Free plan </strong>(200 minutes).<strong> </strong>In second place is Bitrise with 150 minutes, and last is Bitbucket with just 50 minutes in the free tier. More info about the prices for all available tiers can be found on the pages of the mentioned providers: <a href="https://docs.github.com/en/billing/managing-billing-for-github-actions/about-billing-for-github-actions">GitHub</a>, <a href="https://bitrise.io/pricing#Comparison-Section">Bitrise</a>, and <a href="https://www.atlassian.com/software/bitbucket/pricing?tab=cloud-tab">Bitbucket</a>.</p><h3>What is Apple providing in terms of CI/CD?</h3><p><strong>Xcode Server</strong> is a continuous integration tool for iOS apps, built by Apple. It comes bundled in the Xcode app, beginning with Xcode 9. It automatically checks out your project, builds the app, runs tests, archives the app for distribution, and lets you know if anything went wrong.<br><strong>Xcode Server</strong> runs locally on a Mac. It is designed to be installed and run on a dedicated machine, such as a Mac mini, which can be used as a build and test server. When you set up <strong>Xcode Server</strong>, you can configure it to connect to your source code repository (such as <strong>GitHub</strong> or <strong>Bitbucket</strong>) and automatically build and test your code whenever changes are committed to the repository.</p><p>However, it’s worth noting that you can also use <strong>Xcode Server</strong> to distribute your app to testers or users over the internet, through methods such as <strong>TestFlight</strong> or in-house distribution. In this case, the app would be hosted on a web server or cloud service, rather than running directly on <strong>Xcode Server</strong>.</p><p>Overall, <strong>Xcode Server</strong> is primarily designed for local use, to automate the build, test, and deployment processes of your app development workflow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*neCkCbEprCdzVDbNd6pA_g.png" /><figcaption>Image 6. Working graph of Xcode server</figcaption></figure><p>Setting up the <strong>Xcode server</strong> is not a difficult process that can be completed quickly by following <a href="https://developer.apple.com/library/archive/documentation/IDEs/Conceptual/xcode_guide-continuous_integration/adopt_continuous_integration.html#//apple_ref/doc/uid/TP40013292-CH3-SW1">Apple’s documentation</a>. In the next couple of bullet points, I am going to list some of the pros and cons of using <strong>Xcode Server</strong> for your <strong>CI/CD</strong> flow:</p><p><strong>Pros</strong></p><ul><li>Provides a comprehensive set of tools for building, testing, and deploying iOS and macOS apps</li><li>Easy to set up and use, with a user-friendly interface</li><li>Offers detailed reporting and analysis of build and test results, with automatic notifications</li><li>Provides tools for automating distribution and deployment to a variety of platforms, including the <strong>App Store</strong>, <strong>TestFlight</strong>, and in-house distribution</li></ul><p><strong>Cons</strong></p><ul><li>Requires a dedicated Mac machine to run <strong>Xcode Server</strong>, which can be expensive and take up physical space</li><li>There may be issues with compatibility between <strong>Xcode Server</strong> and other tools in your development workflow</li><li>Some features, such as automated testing, may require additional setup and configuration outside of <strong>Xcode Server</strong></li><li>The build and test process can be slow, especially for large or complex projects, which can impact developer productivity</li></ul><h3>Conclusion</h3><p>So what‘s the best way to set up the <strong>CI/CD</strong> flow? This answer isn‘t and can‘t be a one-way street. The correct answer is determined by the technology stack you are using as well as your personal preferences. The true efficacy of your <strong>CI/CD</strong> solution can be quantified in the number of minutes saved from manually debugging and building, thus highlighting the value of an automated process.</p><p>It‘s worth mentioning that projects that require builds every month, or even less often, are not actually great candidates for setting up your <strong>CI</strong>/<strong>CD</strong> environment. The real need and power of <strong>CI</strong>/<strong>CD</strong> setup can be seen on projects that require new builds every couple of days or even more frequently. In the beginning, <strong>Bitrise</strong> can be the easiest option to setup, but later on, I suggested using your own machine (<strong>runner</strong>).</p><p>With that said, we have come to the end of this blog. Feel free to share it with your colleagues and let the knowledge spread. If you have any questions, do not hesitate to post them in the comments section. 🏁</p><p><em>Krešimir is a valuable member of our iOS team.<br>At Azikus, we design and develop top notch mobile and web apps.<br>We are a bunch of experienced developers and designers who like to share knowledge, always staying up to date with the latest and newest technologies.<br>To find out more about what we do, feel free to check out our </em><a href="http://www.azikus.com/"><em>website</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1e522769f3ed" width="1" height="1" alt=""><hr><p><a href="https://medium.com/azikus/ci-cd-in-ios-development-1e522769f3ed">CI/CD in iOS development</a> was originally published in <a href="https://medium.com/azikus">Azikus</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building the Pokédex in iOS using Core ML]]></title>
            <link>https://medium.com/azikus/building-the-pok%C3%A9dex-in-ios-using-core-ml-db32e6089e6b?source=rss-a12f65145e96------2</link>
            <guid isPermaLink="false">https://medium.com/p/db32e6089e6b</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[pokemon]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Kresimir Bakovic]]></dc:creator>
            <pubDate>Tue, 06 Dec 2022 15:10:51 GMT</pubDate>
            <atom:updated>2022-12-06T15:10:51.708Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EEb7e5aH_2J1HAY2OhHk-g.jpeg" /></figure><p><strong>Who’s that Pokemon? I bet you’ve heard this question more than once in your life. There aren’t many people that exactly know every Pokemon’s name and their evolutions😏. <br>In our opinion, this is a good reason for making the detector that will tell you everything about the Pokemon that you are trying to scan using your phone’s camera. The scanning concept comes from the Pokemon cartoon, where the main characters are getting information about all kinds of different Pokemons using their special scanning device called the Pokedex. <br>Without further ado, let’s see how to transform your device into the nice-looking Pokedex!</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/567/1*FhnGQxKUPMaiGjI4c3-gtA.gif" /><figcaption>Video 1. Pokedex</figcaption></figure><p>Let’s split scanning implementation into a couple of steps that we need to follow:</p><ol><li><em>Define tools that should be used to make the detector</em></li><li><em>Find a large data set of Pokemon images</em></li><li><em>Split data in three sets (training, validation, testing)</em></li><li><em>Train your model</em></li><li><em>Import trained model into the Xcode project</em></li><li><em>Connect the camera to the classifier</em></li><li><em>Make a fancy UI that will blow user</em>’<em>s minds🤯</em></li></ol><h3>Tools and data</h3><p>Probably the first question that comes to your mind is: “<em>How are we going to implement detection and which tools should be used to accomplish that?</em>” The answer to that question is by combining the phone’s camera with <strong>machine learning</strong>. Let’s first start with the exact definition of what <strong>machine learning</strong> is.</p><blockquote><strong>Machine learning </strong>is a type of <strong>artificial intelligence (AI)</strong> that allows software applications to become more accurate at predicting outcomes without being explicitly programmed to do so. <strong>Machine learning</strong> algorithms use historical data as input to predict new output values.</blockquote><p>Our task is to create a <strong>machine learning model</strong> that will get one image from the device camera as input and throw out one Pokemon name as computed output. Since there can be multiple possibilities on the model’s output, that classification model is called a <strong>multi-class (multinomial)</strong> <strong>classifier</strong>. There are 905 Pokemons in total (by the time this blog was written), but our model will be able to detect only the first generation of Pokemons(first 150). To create a <strong>model</strong> that will do the <strong>classifying</strong> for us, we need to make him learn. <br>The learning process is done by feeding the <strong>model</strong> with large amounts of data so it can memorise different patterns in each data chunk. If you want a model with a nice percentage of valid predictions, you need a lot of data. <strong>Machine learning</strong> is data-hungry by its nature, and the more data you have, the more precise your model will be in its predictions. For this image processing purpose, we merged a couple of data sets and ended up with a large data set containing approximately 17000 Pokemon images. That set needs to be split into three different groups: <strong>training (70%)</strong>, <strong>validation (15%)</strong> and <strong>testing (15%)</strong>.</p><ul><li><strong>Training data set</strong> → used for model training</li><li><strong>Validation data set</strong> → used for validating how well the model performs</li><li><strong>Testing data set</strong> → used for testing the model</li></ul><p>Data separation was done using the Python script in the image below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ngh6PQsRkMk0Oa7QUMCHVA.png" /><figcaption>Image 1. Data separation</figcaption></figure><p>The split ratio of the data set can be different from the one that we picked. For example, <strong><em>80%</em></strong> for the <strong>training set</strong>, <strong><em>10%</em></strong> for the <strong>validation set</strong> and <strong><em>10%</em></strong> for the <strong>testing set</strong>. The optimum split depends on a specific use case, data dimensions, model structure etc. After successful model training, you can use 100% of your data set to train your model once more. With this step, you add more data to your model, but you shouldn’t be changing your model parameters after this step. Doing that can be considered cheating because your model already saw those images and model predictions can’t be marked as valid.</p><blockquote>It’s important to mention that you shouldn’t use images from the <strong>validation</strong> set or <strong>test</strong> set for training, because doing so you wouldn’t be able to estimate the quality of your <strong>model</strong>.</blockquote><p>When it comes to machine learning implementation on iOS devices, Apple provides an awesome framework called <a href="https://developer.apple.com/documentation/coreml"><strong>Core ML</strong></a><strong>. </strong>It supports <a href="https://developer.apple.com/documentation/vision"><strong>Vision</strong></a> for analyzing images, <a href="https://developer.apple.com/documentation/naturallanguage"><strong>Natural Language</strong></a> for processing text, <a href="https://developer.apple.com/documentation/speech"><strong>Speech</strong></a> for converting audio to text, and <a href="https://developer.apple.com/documentation/soundanalysis"><strong>Sound Analysis</strong></a> for identifying sounds in audio. This framework is going to be used in our case for training the built-in <strong>multi-class classifier</strong>. In the next chapter, we are going to explain how to do that.</p><h3>Training the model</h3><p>For our image processing purposes, we are going to use the built-in <strong>image classifier</strong>. You can create one by selecting <strong>XCode → Open Developer Tool → Create ML.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W0DTktQJ_fvpDEdxS7JEWQ.png" /><figcaption>Image 2. Template choosing</figcaption></figure><p>On the next menu, you can choose one from multiple options that are shipped with the <strong>Core ML</strong>. Since the purpose of this blog is to explain image classification, we are going to select the <strong>Image Classification</strong> template. Hit next and you will end up on a screen like the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4syCwi_XMb2yJvXBosfAPA.png" /><figcaption>Image 3. Image classifier</figcaption></figure><p>In the image above, you can see the visual presentation of our machine learning model. In the <strong>Data</strong> section, there are three different categories that each represent their own data set. In the previous chapter, we already split our large data set into <strong>training</strong>, <strong>validation</strong> and <strong>testing</strong> parts, so now we can just import them into the respective sections. You can see actual folders contained inside the test data set in the image below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NgaGz8YpQuJ6_mVXXW2m_w.png" /><figcaption>Image 4. Folders inside the test set</figcaption></figure><p>Each folder contains multiple images of one Pokemon from the first generation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XFkTaAhwbmNIRynSJ0n0-w.png" /><figcaption>Image 5. Gastly testing images</figcaption></figure><p>In the <strong>Parameters</strong> section, you can set the number of iterations. An iteration is defined as one passing through the entire training set, so by setting it to 35 iterations (also known as epochs), the model can look at each image 35 times. The default value of this property is 25, but if you set it to more than that, your training period will get longer accordingly. There are more options to play with, but I suggest that you invest some time and read about them if you are interested (<strong>Blur</strong>, <strong>Crop</strong>, <strong>Flip</strong> etc).</p><p>After filling up all the sections and setting the desired parameters, you are able to start training your <strong>model</strong> by pressing the <strong>train</strong> button in the upper left corner of the screen. The extracting features process will take some time, but at the end of the training process, you will end up on the screen below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gdH9RShk4x5E2J1y9UZ31A.png" /><figcaption>Image 6. Training and validation accuracy comparison</figcaption></figure><p>In the image above, you can see a comparison between the <strong>training</strong> and <strong>validation</strong> sets according to the number of iterations that have been executed. It’s clear that the model learned to recognize different Pokemons because at the end of the training phase we have an accuracy of nearly 98%. Accuracy for the validation phase is around 80%. This can be improved by using a larger data set and by filtering <em>“broken”</em> images. By the term “<em>broken</em>”, I mean images that have multiple objects inside them and really are not good representations of selected Pokemon. In the image below, you can see some of the images from the training data set that are considered to be “<em>broken</em>”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eWYAW5VIFdqTBJjlOQScUQ.jpeg" /><figcaption>Image 7. Broken Images</figcaption></figure><p>If you want better results, feel free to check every image inside your data set and remove broken ones, but be aware that it can take some time.⏰</p><p>Two useful pieces of information about how well your model is performing are <strong>precision</strong> and <strong>recall</strong>. Let’s give two examples for each definition in order to explain what these two terms actually mean. <strong>Precision</strong> shows the percentage of all the images that the model evaluated as <em>“Bulbasor”</em> and that were actually <em>“Bulbasor”</em>. On the other hand, <strong>recall</strong> gives us a percentage of how many <em>“Bulbasors” </em>models are found among all “<em>Bulbasor”</em> images. In the next image, you can see the precision and recall percentages for some of the Pokemons from the training set.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IKt1k6t6tWlIV06p0Y47Yg.png" /><figcaption>Image 8. Precision and recall for some of the Pokemons</figcaption></figure><p>At this moment, we have trained our model and we can save it somewhere on our machine (by clicking the <strong>Get </strong>icon in the Output section) and finally start using it on real world examples inside the application.🤳🏼</p><blockquote>If you try scanning something that’s not Pokemon, you can get very weird results. For the scanned banana, the model can say it’s a Pikachu with very high certainty because the image contains a lot of yellow color that can be interpreted as the mentioned Pokemon. This is happening because a model tries to put a scanned banana into one of the Pokemon categories that it’s been trained on and it’s considered normal for all image classification models.</blockquote><h3>Pokemons scanner mobile app</h3><p>After data collection and model training, fancy UI and nice looking animations are must-have for every iOS professional. Actually, we went one step further and made the whole application for Pokemons classification called <strong>Dex Scanner. </strong>With this app, you can capture a photo of any Pokemon from the first generation using your phone’s camera, and get valuable information like: hp, abilities, evolutions, moves etc. After successful scanning, Pokemons are unlocked and your real-life Pokedex starts talking🔊. In a couple of seconds without reading a single word, you have all the basic information about scanned Pokemon. Isn’t that cool?😎 In the next video, you can see how the scanner works in real life example.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/354/1*Oe6ddi1OS5ovmcAWpH7ckQ.gif" /><figcaption>Video 2. Pokemon scanning</figcaption></figure><p>We can all agree that ability to scan your favourite Pokemon using one tap on your decice is pretty cool and revolutionary. You can try building your own Pokedex or you can check ours. Our application is up and running in the <a href="https://apps.apple.com/hr/app/dex-scanner/id1636828685"><strong>AppStore</strong></a>, and you can check it out on the link below. If you have any questions, feel free to reach me out in the comments section. Thanks for your time and feel free to share this blog post among your colleagues and friends. Happy coding and remember, <a href="https://www.youtube.com/watch?v=rg6CiPI6h2g&amp;ab_channel=kerwinpogi092"><strong>you gotta catch em all</strong></a>😄</p><p><a href="https://apps.apple.com/hr/app/dex-scanner/id1636828685">‎Dex Scanner</a></p><p><em>Krešimir is a valuable member of our iOS team.<br>At Azikus, we design and develop top notch mobile and web apps.<br>We are a bunch of experienced developers and designers who like to share knowledge, always staying up to date with the latest and newest technologies.<br>To find out more about what we do, feel free to check out our </em><a href="http://www.azikus.com/"><em>website</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=db32e6089e6b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/azikus/building-the-pok%C3%A9dex-in-ios-using-core-ml-db32e6089e6b">Building the Pokédex in iOS using Core ML</a> was originally published in <a href="https://medium.com/azikus">Azikus</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building 3D Avatars in iOS using SceneKit]]></title>
            <link>https://medium.com/azikus/building-3d-avatars-in-ios-using-scenekit-a10353aac11?source=rss-a12f65145e96------2</link>
            <guid isPermaLink="false">https://medium.com/p/a10353aac11</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[ar]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[football]]></category>
            <category><![CDATA[3d-modeling]]></category>
            <dc:creator><![CDATA[Kresimir Bakovic]]></dc:creator>
            <pubDate>Thu, 25 Nov 2021 11:59:39 GMT</pubDate>
            <atom:updated>2021-11-25T11:59:39.023Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L9nvswSn2RJky7WK0wx02A.jpeg" /></figure><p><strong>While playing around with your smartphone, there must have been a situation when you saw a 3D object on the screen and you wondered how it was constructed under the hood.<br>In this article I will explain the key concepts of modeling a 3D object in the SceneKit and mention the requirements that were requested by our client — </strong><a href="https://www.thefootballclub.com/"><strong>The Football Company GmbH</strong></a><strong>. Also, I will also describe challenges that were resolved on the way to a complete solution.<br>Here are some key functionalities requested by our client at the beginning of our 3D journey:</strong></p><ul><li><em>Make a 3D avatar that will be shown in multiple places in the application</em></li><li><em>User needs to be able to dress the avatar and exchange all kinds of different clothes on it</em></li><li><em>Avatar should support both genders as well as multiple skin colors</em></li><li><em>Avatar needs to support custom gestures like taps, rotation, zoom, etc.</em></li><li><em>User should be able to place his avatar inside the real world</em></li></ul><p>At first sight this sounds like a complicated thing to do, and it’s not easy, trust me, but we have managed to do it, and here’s one screenshot of our masterpiece!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ysniliLAaGzrTN7iAUCbMQ.png" /><figcaption>1. 3D Avatar</figcaption></figure><h3>Choosing the right file format</h3><p>The first thing that was discussed among our teammates was choosing the proper file format for 3D objects. After some research we found out that Scene Kit supports these file extensions by default: <strong>DAE</strong>, <strong>ABC</strong>, <strong>SCN</strong>, <strong>OBJ </strong>etc. Keep in mind that the client requested an application for both mobile platforms(Android and iOS), so we needed to choose a file format that will be supported and used on all existing mobile devices. After some googling and consultations with the 3D design team, we agreed that the best thing to do is to try a couple of different file formats and see which one matches our requirements. We choose the next file formats: <strong>OBJ</strong>, <strong>GLTF </strong>and <strong>GLB</strong>. Designers exported all kinds of test models to the mobile teams and we agreed that we were going to use <strong>GLTF</strong> files. There were couple of reasons for choosing this file format and I will list some of them:</p><ul><li><strong>GLTF</strong> supports links to the external files like textures, shaders and animation data (unlike <strong>GLB</strong> format)</li><li><strong>GLTF</strong> is way more efficient in terms of size then <strong>OBJ</strong> file</li><li><strong>GLTF</strong> supports scene graph hierarchy</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gurJDSYV71V0JYsdfWQhgQ.png" /><figcaption>2. Structure of 3D object in GLTF file format</figcaption></figure><p>The image above represents the structure of one 3D object constructed using a <strong>GLTF</strong> file. The biggest advantage of this file type is that textures are separated from the node structure and therefore you can link all different kinds of images to your base object. The real power of this can be seen by taking a look at the bottom part of the first image where all different kinds of sweatshirts are constructed using the same base <strong>GLTF</strong> file and different external textures. Maybe you are asking yourself:</p><blockquote>Why doesn’t every sweatshirt have it’s own <strong>GLTF</strong> file?</blockquote><p>When you are constructing something like a 3D object, you need to take care of memory management and loading time. Therefore, with having one <strong>GLTF</strong> file for all of the items from the same category, you are saving tons of memory. We also implemented <strong>LRU </strong>(<strong>L</strong>east <strong>R</strong>ecently <strong>U</strong>sed) cache for all of the <strong>GLTF </strong>files and their textures. With cache implementation items are stored in the device memory and, by doing so, they are loaded faster.</p><h3>Scene, lights, camera 📸</h3><p>In this section I will explain the basic scene setup that was constructed for the avatar on the first image. Firstly, there are 4 different types of lights inside the scene kit:</p><ul><li>Omni light → point light which illuminates all directions from a single point</li><li>Ambient light → light that illuminates from all directions with equal effect; orientation and position of the light node can be omitted</li><li>Directional light → this type of light illuminates from one direction, so the position of its node is ignored</li><li>Spot light → this type of light illuminates a cone-shaped area, the orientation and the position of the light are defined by its node’s properties</li></ul><p>For the scene we used directional light in combination with a custom <strong>HDR</strong> file that was used as a background for the whole scene. On the first image you can see how beautiful shadows are constructed due to the directional light position in front of the avatar. Also, eyes of the avatar are made from glossy material and because of that, light can be seen inside avatar’s eyes which gives a more realistic look. You wouldn’t be able to see your avatar inside the scene if the camera wasn’t there, so make sure to add the camera and position it wherever you want. You can also play with some of many camera settings and get some really fascinating results. We implemented custom gestures so the user is able to zoom and rotate the avatar. Avatar rotates by default and can be stopped with a single tap on the screen. The avatar rotation and items exchange are displayed below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*rAUxtgtbZCodMlRXD1dSkg.gif" /><figcaption>Video 1. Items exchange</figcaption></figure><h3>Morphing</h3><p>Morphing was by far the most complicated topic in the whole development process.</p><p>3D objects can have multiple geometries (imagine those like states) and a set of weights associated with each. When you apply weight to some geometry, your 3D object changes it’s appearance and can look completely different than the initial one. An image that can describe this in a real world scenario is one from the Apple’s <a href="https://developer.apple.com/documentation/scenekit/scnmorpher">documentation</a>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aJFuv4XPWz-x2MOi11q_iQ.png" /><figcaption>3. Morphing across 3 different geometries</figcaption></figure><p>All objects in the previous image have exactly the same <strong>GLTF</strong> file, but inside the file there are 3 different geometries that you can change across. Transitions between those geometries can be animated as well. If you still can’t see where this morphing thing can be useful, I will show you in a moment. Imagine having your avatar fully dressed and your client presents a new collection of different scarves for the avatar. Everything sounds good to you, but when you put your new scarf on the avatar, as well as some hoodie, you can see some clippings:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9ZRyPt07aLjeoKeIw58IPQ.jpeg" /><figcaption>4. Clippings between hoodie and scarf</figcaption></figure><p>This is where morphing comes into play. If you have multiple geometries both for the hoodie and the scarf, you are able to switch between different states of each item and fine-tune it to remove the clippings. We have developed our own algorithm for automated adjusting of geometry weights to ensure there is no clipping between items. The result can be seen on the image below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QC4v3Oz5e1yYVrfVSis7tw.png" /><figcaption>5. Avatar without clippings</figcaption></figure><p>I encourage you to invest some more time in morphing and you will see how cool things can be achieved using this feature.</p><blockquote>“Don’t settle for average. Bring your best to the moment. Then, whether it fails or succeeds, at least you know you gave all you had.” — Angela Bassett</blockquote><h3>Avatar in the real world 😍</h3><p>One of the things that our client requested was a showing of a 3D avatar in the real world. So we did it. In the next video you can see me walking down the park when suddenly my avatar showed up.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*32MKpnTC5lZpGu5xafBc3A.gif" /><figcaption>Video 2. Avatar inside the real world</figcaption></figure><p>Showing of the avatar in the real world was done by using the AR Kit. AR Kit is Apple’s framework used for showing all kinds of different 3D objects inside the real world using the phone’s camera. If you are playing with 3D objects, this feature is a MUST HAVE inside your application.</p><h3>Conclusion</h3><p>In this article I explained the complete development process and some difficulties I encountered while creating a 3D avatar from scratch. There are a lot of things to do in the middle of each step I mentioned in this blog post, but I left those steps to the ones that want to learn and try some things by themselves. I hope that you enjoyed reading this blog and that you learned something. If you have any questions feel free to reach out to me using the comments section. At the end you can download the application and play with your own avatar. Here are the links to the <a href="https://apps.apple.com/hr/app/the-football-club/id1571720739?l=hr">App Store</a> and <a href="https://play.google.com/store/apps/details?id=com.agency04.tfc">Google Play</a>:</p><ul><li><a href="https://apps.apple.com/hr/app/the-football-club/id1571720739?l=hr">‎The Football Club</a></li><li><a href="https://play.google.com/store/apps/details?id=com.agency04.tfc">The Football Club - Apps on Google Play</a></li></ul><p>Thank you and have fun.😇</p><p><em>Krešimir is a valuable member of our iOS team.<br>At Azikus, we design and develop top notch mobile and web apps.<br>We are a bunch of experienced developers and designers who like to share knowledge, always staying up to date with the latest and newest technologies.<br>To find out more about what we do, feel free to check out our </em><a href="http://www.azikus.com/"><em>website</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a10353aac11" width="1" height="1" alt=""><hr><p><a href="https://medium.com/azikus/building-3d-avatars-in-ios-using-scenekit-a10353aac11">Building 3D Avatars in iOS using SceneKit</a> was originally published in <a href="https://medium.com/azikus">Azikus</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Collapse and expand UITableView cells like a Pro]]></title>
            <link>https://medium.com/azikus/collapse-and-expand-uitableview-cells-like-a-pro-df4a2fd85287?source=rss-a12f65145e96------2</link>
            <guid isPermaLink="false">https://medium.com/p/df4a2fd85287</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[app-development]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[product-design]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Kresimir Bakovic]]></dc:creator>
            <pubDate>Thu, 22 Apr 2021 17:25:41 GMT</pubDate>
            <atom:updated>2021-04-22T17:25:41.753Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*scaTmd7-u0cXW2hf4bxvhQ.png" /></figure><p><strong>Animations are among the key factors that distinguish between the regular and outstanding user experience. <em>UITableView</em> provides us out-of-the box solution to animate list. In most of the cases this can be implemented very easy without any troubles and it will look very beautiful and professional, but sometimes, there is a situation where this is not the case.</strong></p><p>In this blog post I will show basic implementation of this problem and give you some valuable advices to make your table view expand in some more elegant way. So without further ado let‘s get started.</p><h3>Getting started!</h3><p>Imagine you are working on a new feature. User story for this feature with acceptance criteria might look like this:</p><p>As a <strong>User</strong> I want to be able to see and edit my profile information.</p><p><strong>Acceptance criteria:</strong></p><ul><li><em>user information is divided into groups: personal (name, gender, nickname…), payout method (Aircash, PayPal, Visa…), notifications (email, push…)</em></li><li><em>every group (section) needs to be expandable and collapsable</em></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KKDECDQ-7PvuhlTo9c7Hfw.png" /></figure><p>If you want to now how to solve this problem, check the next part of article.</p><p>Hang tight, things are going to become interesting!</p><h3>Step by step explanation</h3><p>So the first thing that comes to your mind when someone says section inside table view is of course <strong>header</strong>. Every section will have its own header at the top, and there will be three different types of sections inside our table view:</p><ul><li><strong>Personal</strong> → holds the standard information about the user: username, email, password etc.</li><li><strong>Payout</strong> <strong>method</strong> → all different payment options user can use</li><li><strong>Notifications</strong> → section in which user is supposed to control upcoming notifications from different providers</li></ul><h4>1. Configuration of UITableView</h4><p>Create <strong>EditProfileViewController</strong> and add tableView inside it. Pin all sides of tableView to view‘s edges. ViewControllers inside this project would not have any other UI elements because of simplicity and to keep focus on expanding and collapsing feature. You can find details about configuring <strong>table</strong> <strong>view</strong> inside EditProfileViewController class.</p><p>All registered cells are inside Cells folder and I would‘t explain how to make these. Focus will be on <strong>EditProfileHeaderView</strong> and handling of it inside EditProfileViewController. Enum <strong>EditProfileCellType</strong> is made for easier handling of all tableView cell‘s inside view controller. It accepts arguments that are view models of different cell types (personal, payMethod, notification). <strong>EditProfileHeaderViewModel</strong> is consisted of:</p><ul><li><strong>titleText</strong> which corresponds to the desired title of a section</li><li><strong>cells</strong> which are children cells of each section</li><li>variable <strong>isExpanded </strong>which gives information about section state</li></ul><p>Data source for table view is moved inside <strong>EditProfileDataSource</strong> class to make code a bit cleaner and easier to follow. We assume that data fetched from server comes in nested format so our mocked data source has child data inside header data. Here is the code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4be075717f3dd59e293bf6cf60d056ec/href">https://medium.com/media/4be075717f3dd59e293bf6cf60d056ec/href</a></iframe><p>Everything to this point is pretty straightforward but now comes the fun part, magic of expanding and collapsing!</p><h4>2. EditProfileHeaderViewDelegate</h4><p>Expanding and collapsing should be done by clicking on header view of each section. Because of that simple tap gesture recognizer is added to view inside the class initializer. <strong>EditProfileHeaderViewDelegate</strong> notifies view controller that tap has happened and sends tapped header through <strong>toggleSection() </strong>function. Here you can see delegate implementation:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/40234a71805c71d5c18919483c30a124/href">https://medium.com/media/40234a71805c71d5c18919483c30a124/href</a></iframe><h4>3. Expanding and collapsing 🧨</h4><p>Let‘s start by looking at <strong>toggleSection()</strong> function on EditProfileViewController:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e913ba88a40c4c3e2e5c3ff441854076/href">https://medium.com/media/e913ba88a40c4c3e2e5c3ff441854076/href</a></iframe><p>First thing that needs to be done is to find index of tapped header using <strong>indexOfHeader()</strong> method. Next step is to check if section is expanded or collapsed and according to that hide or show cells inside table view. Implementation of finding tapped header index and hiding and showing of cells is shown here:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3130bef830799c69db2db2a026c006ad/href">https://medium.com/media/3130bef830799c69db2db2a026c006ad/href</a></iframe><p>After finding children index paths using <strong>findChildIndexPathsOfHeader()</strong> function we are ready to insert and delete that child cells. Deleting and inserting of UITableView rows is pretty easy and it‘s done with <strong>deleteRows()</strong> and <strong>insertRows()</strong> functions. “With” parameter inside both functions is in charge for animating deletion and insertion of cells. I encourage you to play around with it and find option that suits you the best. Run your program and you will be able to expand and collapse your table view cells for different section. Cool right, and it wasn‘t so hard?</p><blockquote>Note: Insertion and deletion of cells could be done using <strong>reloadSection()</strong> function. Downside of this approach is that each time function is called it reloads all cells inside given section <strong>including the header</strong>.That causes strange behaviour of the arrow in the upper right corner when you try to animate it.</blockquote><h3>Downsides of this solution</h3><p>Aldo you made a really nice looking feature inside your application there are some downsides of this implementation. Continue reading to find out how to fix them.🔨</p><h4>Flickering when expanding and collapsing</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/240/1*5lf3ojBP4OqMYQmq4h1Z6g.gif" /><figcaption>Flicker when tapping same header multiple times</figcaption></figure><ul><li>In some cases if you click multiple times on same header inside of table view, header will preform some type of strange looking jump. If you are perfectionist as I am, it is obvious that you want to fix this.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/240/1*_n8WnKey4gX6pWWkzfqBFw.gif" /><figcaption>Poor looking collapse animation</figcaption></figure><ul><li>Second strange thing that will occur is poor looking collapse animation. Maybe at this moment you don‘t see what am I talking about but when upgraded version comes to place, everything should be clearer. You now what they say: “You don‘t know how good a Ferrari really is, till the first time you drive it.”</li></ul><h3>Problem fix</h3><p>In order to fix this problem, we will create <strong>EditProfileFixViewController. </strong>Main difference compared to <strong>EditProfileViewController </strong>will be implementation of section headers. At the new view controller, header will be implemented as <strong>UITableViewCell</strong>. Because of that dataSource will be converted to <strong>flatDataSource</strong> model for easier handling of data. Table view on the EditProfileFixViewController<strong> </strong>will have just one section.</p><h4>1. <strong>EditProfileFixCellType</strong></h4><p>As I said in the previous segment, header of <strong>EditProfileFixViewController</strong> will be implemented as UITableViewCell. For that reason <strong>EditProfileFixCellType</strong> looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bc6514a3a19ff2d855462046ad617419/href">https://medium.com/media/bc6514a3a19ff2d855462046ad617419/href</a></iframe><blockquote><strong>Note</strong>: Don‘t forget to register <strong>EditProfileFixHeaderCell</strong> when configuring your table view, without doing so your application will crash</blockquote><h4>2. EditProfileFixDataSource</h4><p>Data source for table view will be transformed from two-dimensional array to one-dimensional array. That is done by calling <strong>flatDataSource()</strong> function which will save flat data to <strong>flattenDataSource </strong>property of EditProfileFixDataSource. If you take some time and think about UI of table view, you will see that there is no reason to construct two-dimensional array at all. All cells inside of table view are just one list of elements and really they shouldn‘t be nothing more than that. So building dataSource for our table view at his way is far more elegant and sophisticated.</p><h4>3. UITableViewDataSource functions</h4><p>Data source functions are same as ones on the EditProfileViewController but with minor differences. Number of sections inside table view is set to 1 and there is one more case to handle when switching on flattenDataSource(header cell).</p><h4>4. DidSelectRowAt function</h4><p>With section header implemented as UITableViewCell we don‘t need to implement any delegates because we can react on tap with <strong>didSelectRowAt() </strong>function. Function implementation is done like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cf49da08e589a1fcd8abc6194078ffce/href">https://medium.com/media/cf49da08e589a1fcd8abc6194078ffce/href</a></iframe><p>We can see that logic is same as the one for EditProfileViewController. After every click flattenDataSource is updated accordingly by calling <strong>flatDataSource()</strong> function. Hiding and showing cells is implemented with exact same functions as for the first example and would‘t be discussed one more time. So what we have done by making all these changes? Let‘s find out at results chapter.😎</p><h3>Results</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/240/1*WIB-nqDfadwqbOSYzkSEsQ.gif" /><figcaption>Header flicker fix</figcaption></figure><ul><li>We can see that there is no flickering of header when exact same header is clicked multiple times. First problem solved.💪🏼</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/240/1*9eOT1u_DfKrupP21yY1DJA.gif" /><figcaption>Collapsing smooth as silk</figcaption></figure><ul><li>Collapsing animation is much more smooth and there is now strange behavior at headers.🍾</li></ul><h3>Result comparison</h3><p>Both view controllers are put inside tab bar so you can easily switch between of two and see the difference. I hope you can see that one on the right side is the way to go if you want smooth and good looking UI. On the next image you can see pros and cons of each implementation:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_X9HgsvIb2iRyAnm36ulPw.png" /></figure><h3>Conclusion</h3><p>At the end of the story we can say that <strong>EditProfileFixViewController</strong> is far more elegant solution by terms of UI. By using this approach, your table view will look professional and easy to use. Flickers and UI bugs will be gone, and users wont’t be confused with some odd-looking animations. This may look like a small and unessential thing, but these things separate good apps from the best ones. Hope you learned something reading this article and if so, share it with your colleagues and let the knowledge spread.<br>Thank you and feel free to post questions and comments below.</p><h3>Materials📚</h3><p>You can find all project materials here:</p><p><a href="https://github.com/azikus/BlogProject">azikus/BlogProject</a></p><p><em>Krešimir is a valuable member of our iOS team.<br>At Azikus, we design and develop top notch mobile and web apps.<br>We are a bunch of experienced developers and designers who like to share knowledge, always staying up to date with latest and newest technologies.<br>To find out more about what we do, feel free to check our </em><a href="https://www.azikus.com/"><em>website</em></a><em>.</em></p><p><a href="http://azikus.com/">AZIKUS - full service digital agency</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=df4a2fd85287" width="1" height="1" alt=""><hr><p><a href="https://medium.com/azikus/collapse-and-expand-uitableview-cells-like-a-pro-df4a2fd85287">Collapse and expand UITableView cells like a Pro</a> was originally published in <a href="https://medium.com/azikus">Azikus</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>