<?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 Cyril Cermak on Medium]]></title>
        <description><![CDATA[Stories by Cyril Cermak on Medium]]></description>
        <link>https://medium.com/@cyrilcermak?source=rss-85e41d5ab945------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*uBWnO1bcFRP4w9VTbAny0Q.jpeg</url>
            <title>Stories by Cyril Cermak on Medium</title>
            <link>https://medium.com/@cyrilcermak?source=rss-85e41d5ab945------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 02:30:11 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@cyrilcermak/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[Swift: Is passing by value faster than passing by reference?]]></title>
            <link>https://medium.com/@cyrilcermak/swift-is-passing-by-value-faster-than-passing-by-reference-d30b6522d065?source=rss-85e41d5ab945------2</link>
            <guid isPermaLink="false">https://medium.com/p/d30b6522d065</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Cyril Cermak]]></dc:creator>
            <pubDate>Sat, 06 Jun 2020 17:55:54 GMT</pubDate>
            <atom:updated>2021-11-04T19:51:34.737Z</atom:updated>
            <content:encoded><![CDATA[<p>Have you ever wondered which one is faster?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Br-Q5wBZ5V4FYQGtZ6I09Q.jpeg" /></figure><p>As developers, we want our code to run as fast as possible, we are designing it to be safe, easily modifiable, readable, aesthetic etc. This article shows the speed difference between passing around value types vs reference types.</p><h3>Types in Swift</h3><p>When it comes to <a href="https://developer.apple.com/swift/blog/?id=10">types</a> in Swift there are those two:</p><p><strong>Reference type<br></strong>A class, where instance shares a single copy in memory that is being referenced by a pointer to the memory. When a reference type is passed as an argument into a function or closure the actual pointer to the object in memory is passed.</p><p>Changing a passed variable value within a called function will be reflected in the callers’ reference.</p><p><strong>Value type<br></strong>Any struct, enum, primitives(int, bool, …), closure, tuples, and probably some others are all value types. Value types are being <strong>copied</strong> when passed into another function as an argument.</p><p>Changing a variable value within a called function will not affect the callers’ reference.</p><h3>What is happening under the hood?</h3><p>When a value type is being passed into another function its value is being copied onto a stack. From the stack, the values can be easily accessible for the CPU. No need to say, there is the downside of copying the value onto the stack.</p><p>When a reference type is created, a space for the object is dynamically allocated in memory also so-called heap. A CPU will take longer time to access via pointers reference the object on the heap in comparison to the values placed on the stack.</p><p>No need to mention that there will be some breaking point where the value types are faster than the reference types and vice versa. Keep reading to know where the breaking point is. :)</p><h3>Benchmarking</h3><p>For measuring, I chose the beloved struct and class types. Measurement was done with a compiler optimization(production AppStore build) and ran on iPhone 5s running iOS 12.4.4.</p><p>Testing objects are as shown below. A simple model of anAddress and aUser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kgRzSYnXhLBQ04ofWCvwew.png" /><figcaption>Models</figcaption></figure><p>The measured function simply accesses all values on those objects and returns the sum of all values as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z_-DWpsR2AP6pDHoifTZUQ.png" /><figcaption>Measured function</figcaption></figure><p>Finally, the benchmarking function that creates the address, user and within a measure closure passes them 1_000_000 times to create the user id.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/998/1*uPt_vl9fP3cLSpWd1wvNeA.png" /><figcaption>Benchmark function</figcaption></figure><h3>Results</h3><p>Each benchmark (1_000_000 operations) was measured 5 times.</p><p><strong>Passed by reference(class User):</strong></p><ol><li><strong>1.0879960060119630</strong></li><li><strong>1.0761229991912842</strong></li><li><strong>1.0753719806671143</strong></li><li><strong>1.0964360237121582</strong></li><li><strong>1.0846699476242065</strong></li></ol><p>AVG: <strong>1.08411939</strong></p><p><strong>Passed by value(struct User):</strong></p><ol><li><strong>1.0615510940551758</strong></li><li><strong>1.0725200176239014</strong></li><li><strong>1.0685210227966309</strong></li><li><strong>1.0658539533615112</strong></li><li><strong>1.0635479688644410</strong></li></ol><p>AVG: <strong>1.06639881</strong></p><p>Passing by value in this practical example was 0.01811 faster than passing by reference. In my opinion, this is a very insignificant difference.</p><h3>Passing big object</h3><p>As mentioned at the beginning of the article, the passing speed of a struct differs with its size. In the next measurement, everything is the same except the size of the User. The user object has now 32 variables as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hYQraeQ3xnNVYUNx32ehgA.png" /><figcaption>Large struct</figcaption></figure><p>Results of performing the same benchmarking with the bigger object passed:</p><p><strong>Passed by reference(class User):</strong></p><ol><li><strong>1.0702630281448364</strong></li><li><strong>1.075631022453308</strong></li><li><strong>1.0900360345840454</strong></li><li><strong>1.0741839408874512</strong></li><li><strong>1.092007040977478</strong></li></ol><p>AVG: <strong>1.0804242134094237</strong></p><p><strong>Passed by value(struct User):</strong></p><ol><li><strong>1.6252110004425049</strong></li><li><strong>1.597877025604248</strong></li><li><strong>1.6124770641326904</strong></li><li><strong>1.6013799905776978</strong></li><li><strong>1.6155270338058472</strong></li></ol><p>AVG: <strong>1.6104944229125977</strong></p><p>For big structs, this test showed the passed by value is at around 65% slower than passing the same object by reference. The pass by reference has almost the same results as from the first example.</p><p>The reason for it is that the pointer is still the same. However, the allocated memory on the heap has changed.</p><h3>The point of break</h3><p>In <a href="https://stackoverflow.com/questions/22840120/pass-by-value-faster-than-pass-by-reference">theory</a>, the point of the break should be where the size of the value type is bigger than the size of the pointer. Value types of size lower than pointer size should be faster in passing.</p><p>In the first example where the results were nearly similar, the size of the User struct was 96 bits (12 bytes). The size of the pointer on a 64-bit architecture where the benchmark was performed is 64 bits(8 bytes). With the reference type, the CPU needed to take some extra steps to dereference the pointer and get the value to the registers. Which could be the difference of why even though the struct was 4 bytes bigger than the pointer size the struct was still slightly faster.</p><p>In the second benchmark where the struct is significantly slower, the size of the struct is 768 bits or 96 bytes. While the size of the pointer remains 8 bytes.</p><h3>In conclusion</h3><p>This article demonstrated that the speed between passing reference types vs value types differs significantly based on the size of the value type. Keep that in mind. :)</p><p>Thanks for reading.</p><p>If you like what you read please share and give a clap or fifty. :)</p><p>If you liked this article and want to know more then please have a look at my book <a href="https://leanpub.com/modular-architecture-on-ios-and-macos">Modular Architecture on iOS and macOS — Building large scalable iOS and macOS apps and frameworks with Domain Driven Design</a> where I keep the latest development practices I learnt along the way. Or simply get in touch on <a href="https://www.linkedin.com/in/cyril-cermak-210a8b6b/">LinkedIn</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d30b6522d065" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exploring iOS-es Mach-O executable structure]]></title>
            <link>https://medium.com/@cyrilcermak/exploring-ios-es-mach-o-executable-structure-aa5d8d1c7103?source=rss-85e41d5ab945------2</link>
            <guid isPermaLink="false">https://medium.com/p/aa5d8d1c7103</guid>
            <category><![CDATA[kernel]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Cyril Cermak]]></dc:creator>
            <pubDate>Mon, 01 Jun 2020 09:07:13 GMT</pubDate>
            <atom:updated>2021-11-04T19:52:18.814Z</atom:updated>
            <content:encoded><![CDATA[<p>Let’s have a look under the hood of iOS executable format, Mach-O.</p><p>In this article, we are going to explore the <a href="https://en.wikipedia.org/wiki/Mach-O">Mach-O</a> (Mach-Object) executable, which is a native format for executables on macOS, iOS and other systems based on Mach-kernel.</p><p>First things first, let’s create an IPA file so we can explore it.</p><h3>iOS App Store Package (IPA)</h3><p>To create an IPA in Xcode, archive an App first, click distribute in the organizer and then select export for development teams.</p><p>When the exporting is finished and your IPA is created, simply exchange the .ipa extension for .zip and unzip it. In the unzipped folder will be a directory called Payload that will contain the App.</p><p>For the demonstration purposes, I created IPA that is targeting iOS 10 up to the latest iOS 13 from <a href="https://github.com/prateek147/DVIA-v2">this</a> repository.</p><p>If you don’t have an app to practice on you can download a compiled DVIA-v2 app <a href="https://github.com/prateek147/DVIA-v2">here</a>.</p><p>Now let’s have a look at the binary. Since the app targets iOS 10 which supports 32-bit architecture the produced binary by Xcode should be a fat binary. Wait, what is a fat binary?</p><h3>Fat binary</h3><p>The term fat binary is quite known but what does it really mean and how to recognize it? Also is the binary really fat? Why? Not enough cardio?</p><p>Fat binary simply means that the executable can run on more than one CPU architecture, for example in the iOS world it can beamrv7 and arm64. Where the armv7 is a 32bit architecture (e.g iPhone 3GS/4/4S…) and arm64 is a 64-bit architecture starting with iPhone 5S.</p><p>For a simple analyzation of Mach-O executables Apple ships otool with macOS. A tool that can explore the Mach-O binary. To know the supported architectures of the binary it is necessary to pass -fv flags. Where -f prints fat headers and -v translate the output into known symbols.</p><p>The output of the following command otool -fv ~/RE/DVIA-v2/Payload/DVIA-v2.app/DVIA-v2could look like this:</p><pre>Fat headers<br>fat_magic FAT_MAGIC<br>nfat_arch 2<br>architecture armv7<br>    cputype CPU_TYPE_ARM<br>    cpusubtype CPU_SUBTYPE_ARM_V7<br>    capabilities 0x0<br>    offset 16384<br>    size 2964496<br>    align 2^14 (16384)<br>architecture arm64<br>    cputype CPU_TYPE_ARM64<br>    cpusubtype CPU_SUBTYPE_ARM64_ALL<br>    capabilities 0x0<br>    offset 2981888<br>    size 3573088<br>    align 2^14 (16384)</pre><p>If the output is blank that simply means the executable is not a fat binary and only one architecture is targeted. To know what is the target architecture when the output is blank it is necessary to have a look at the Mach-O header, explained below.</p><p>We will explore more what the output means in the next section, which is focusing on the Mach-O format.</p><h3>Mach-O format</h3><p>As mentioned before the <a href="https://en.wikipedia.org/wiki/Mach-O">Mach-O</a> is a format for native macOS and iOS executables. The format consists of many commands and data types which are represented by C structs. All structs can be easily explored via Xcode.</p><p>I will go through the defined structures in order as they are placed in the compiled binary.</p><h4>Disassembled Mach-O part of a binary</h4><p>There are many disassemblers that can be used for exploring Mach-O files. My two favourites are Hopper and Radare2. For this demonstration, I used Hopper to disassemble the binary and explore the Mach-O part in it. A full disassembled output can be found <a href="https://gist.github.com/CyrilCermak/8fcfc0cc567636edc0fd09f05017028f">here</a>.</p><p>A sneak-peek that contains the header and a segment commands can be seen on the snippet below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*snPe6FLlCbMi5v2R9CD-IQ.png" /><figcaption>Example of Mach-O structs used within the compiled binary</figcaption></figure><p>In the very beginning of the binary is Mach-O header so let’s start with it.</p><h4>Mach-O header</h4><p>Each Mach-O binary starts with a header. The otool program will help us here again. Passing to otool the parameter h will output the Mach-O header or headers if it is a fat binary. The command otool -hv ./DVIA-v2 will result in the following output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xyKxKy6de1iZtMxOYtXOgQ.png" /><figcaption>Mach-O headers</figcaption></figure><p>Because I have a fat binary the output of otool produces two results one for ARM(32-bit) and one for ARM64(64-bit).</p><p>Where did the header come from?</p><p>The answer sits in /usr/include/mach-o/loader.h. A struct mach_header and mach_header_64 is declared there that contains all values that the otool output produced. The struct comment helps a lot in its understanding.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PeSaYGQb7OInwVr-33Iv2A.png" /><figcaption>Declaration of Mach-O header</figcaption></figure><p>Let’s have a look at some of the parameters the header contains.</p><p><strong>uint32_t magic </strong>is declared within the loader.h as well and posses those two declarations:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FSdii07sJuRDoVDO-rK5fA.png" /><figcaption>MH_MAGIC for Mach-O executable</figcaption></figure><p><strong>cputype </strong>is declared in /usr/include/mach/machine.h and there sits the CPU_TYPE_ARM and CPUT_TYPE_ARM64 alongside with all other supported CPU architectures by Mach-O.</p><p>The rest of the parameters in the header struct I will leave for your own exploration. :)</p><p>After the header in the binary comes the Mach-O segment.</p><p><strong>Mach-O segment</strong></p><p>A segment represents a part of the executable that is loaded into the memory. It is the app itself alongside with all linked libraries and frameworks with a linker. Fortunately, segments struct comment speaks for itself.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iTwkIcrKCreFBRFICyYbww.png" /><figcaption>Mach-O segment struct</figcaption></figure><p><strong>Mach-O section</strong></p><p>The previously mentioned segment command is made up of zero or more sections. When you are in a program runtime inlldb you can explore all sections of the app via image dump sections command. That will dump all segments and their sections. On the image below is output of all sections within DVIA-v2 segment which is the main executable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L4IygFrAxtyXhvdIx0DqLA.png" /><figcaption>Sections dump for DVIA-v2 segment, the main executable</figcaption></figure><p>To get a segment of a loaded 3rd party framework the command can be executed with the name of the included library. E.g image dump sections Realm would produce the following output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*foE-yb2NNugBjW-COFiWvg.png" /><figcaption>Sections dump for Realm segment, a third-party framework</figcaption></figure><p>A section struct looks as follows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wxOR1DU6Fpx-0lI6jiikPw.png" /><figcaption>Mach-O section struct</figcaption></figure><p>There is so much more to explore, I would highly recommend reading through the whole loader.h file, as it is full of interesting stuff so as machine.h and mach.h.</p><p><strong>…</strong></p><p>Next, I will list only names of structs/commands that are being used in their specific order within the binary.</p><pre>__macho_dyld_info_command<br>__macho_symtab_command<br>__macho_dysymtab_command<br>__macho_dylinker_command<br><strong>__macho_uuid_command<br>__macho_version_min_command<br></strong>__macho_load_command<br><strong>__macho_entry_point_command<br></strong>__macho_load_command<br><strong>__macho_dylib_command</strong><br>__macho_rpath_command<br>__macho__linkedit_data_command</pre><p>Let’s have a brief look at the highlighted commands. Thanks to their struct comments there is no need for much of a further explanation. Thanks, Apple!</p><p><strong>__macho_uuid_command</strong></p><p>This struct declares the unique app install identifier that the app developer can and sometimes must rely on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u7nbspoCbI2NwMTvcy0fww.png" /><figcaption>Mach-O uuid-command struct</figcaption></figure><p><strong>__macho_version_min_command</strong></p><p>This is a command that identifies OS version the executable can run on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6lF7YiBP_C4SDwgss5kbfw.png" /><figcaption>Mach-O version_min_command struct</figcaption></figure><p><strong>__macho_entry_point_command</strong></p><p>A command that points to the <strong>main</strong> function. The main function is the programs entry point.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mxDdY6JlmYVo0RWcdVkLVQ.png" /><figcaption>Mach-O entry_point_command struct</figcaption></figure><p><strong>__macho_dylib_command</strong></p><p>With the dylib_command, the dynamic frameworks and libraries are defined and then by a <a href="https://developer.apple.com/library/archive/documentation/DeveloperTools/Conceptual/DynamicLibraries/100-Articles/OverviewOfDynamicLibraries.html">dynamic linker</a> -dyld loaded into the app memory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WNa2HU1cogw5caABdEBm1w.png" /><figcaption>Mach-O dylib_command struct</figcaption></figure><h4>In Conclusion</h4><p>This article gives an overview of how Mach-O executable format looks like in a practical explorational way. I hope that it gave enough information to continue with the exploration on your own.</p><p>For more detail information about this topic, I would highly recommend studying these articles:</p><p><a href="https://www.mikeash.com/pyblog/friday-qa-2012-11-30-lets-build-a-mach-o-executable.html">Mike Ash — Let’s build a Mach-O executable</a><br><a href="https://github.com/aidansteele/osx-abi-macho-file-format-reference">OSX ABi Mach-O File Format reference</a><br><a href="https://developer.apple.com/library/archive/documentation/DeveloperTools/Conceptual/MachOTopics/1-Articles/building_files.html#//apple_ref/doc/uid/TP40001828-SW1">Apple — Mach-O topics</a></p><p>If you like what you read please share and give a clap or fifty. :)</p><p>If you liked this article and want to know more then please have a look at my book <a href="https://leanpub.com/modular-architecture-on-ios-and-macos">Modular Architecture on iOS and macOS — Building large scalable iOS and macOS apps and frameworks with Domain Driven Design</a> where I keep the latest development practices I learnt along the way. Or simply get in touch on <a href="https://www.linkedin.com/in/cyril-cermak-210a8b6b/">LinkedIn</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aa5d8d1c7103" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Goals achieving, the ultimate guide]]></title>
            <link>https://medium.com/@cyrilcermak/goals-achieving-the-ultimate-guide-319eea1ec7b4?source=rss-85e41d5ab945------2</link>
            <guid isPermaLink="false">https://medium.com/p/319eea1ec7b4</guid>
            <category><![CDATA[goals]]></category>
            <category><![CDATA[achieving-goals]]></category>
            <category><![CDATA[motivation]]></category>
            <category><![CDATA[coaching]]></category>
            <category><![CDATA[mobile-apps]]></category>
            <dc:creator><![CDATA[Cyril Cermak]]></dc:creator>
            <pubDate>Sat, 11 Apr 2020 08:56:00 GMT</pubDate>
            <atom:updated>2020-04-11T13:40:02.151Z</atom:updated>
            <content:encoded><![CDATA[<h3>Achieve your goals, the ultimate guide</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MUJbFpfQFH-njKnKJ_wIqw.png" /></figure><p>In this article, you will learn the best practices for setting up and achieving goals for yourself so as using AchieveMe, an app that will help along the way.</p><h3>Achieving goals</h3><h4>Why set a goal?</h4><blockquote>“If you aim for nothing, you’ll hit it every time.”</blockquote><p>Setting goals for yourself is very important. It is the easiest way of tracking your progress in life. It does not matter what kind of goal it is, all that matters is that it pushes you forward, makes you a better person, strive the best out of you. I mentioned the world <strong>YOU </strong>many times here, as that is exactly what it is about. It’s not about setting a goal of being better than Elon, it is about being better today than you were yesterday. It is about making small steps, constantly, all over again, tirelessly, even when you don’t feel like it. Those small steps will lead you to a path with bigger and better opportunities.</p><blockquote>“It does not matter how slowly you go as long as you do not stop.”<br>Confucius</blockquote><p>Now let’s have a look on how to achieve goals.</p><h4>Define the goal</h4><p>Goals should not be set out of anything. It takes a while to set a worthwhile goal and takes practice in doing so. Give it a lot of thought before you set one. Once the goal is set take it as it is written into stone. You cannot change the overall high-level goal outcome. However, the path towards it can be adjusted as you will walk on it. Tackling small steps one after the other will bring the courage to walk and finish the defined path.</p><p>Obviously, there is a big difference between goals like buying a house or building one and getting better shape for swimsuits. Nevertheless, the conscious works similarly in both cases. Therefore, it is crucial to treat both goals with the same importance in mind. The overall resistance against procrastinating on the path will be improving heavily with every achieved step.</p><h4>Clarity</h4><p>Be very clear in what you want to accomplish. The clarity is the key to identify whether the goal was a success or not. Sometimes it helps to write everything down and read it out loud to see whether it makes sense and whether it is clearly defined.</p><h4>Track the progress</h4><p>It’s good to know where you are standing on the path towards a goal. Tracking progress will help you determine how you are doing. Maybe it is time to push a little bit harder, maybe some part will take much more time than expected, maybe you need to take extra steps etc. That being said, a goal refinement might be needed at any time.</p><h4>Goal refinement</h4><p>Something might not go as defined from the very beginning, therefore a refinement is necessary. Refinement of a goal should happen as often as possible alongside the progress review. Refinement same as progress review keeps the mind focus on the goal, which is very important.</p><p>Not only progress towards the goal gets refined. Refinement also takes the whole goal outcome into an account. It clarifies and improves the vision of success for the goal. The vision of success could change while making steps towards it. The refinement tracks those changes and adjusts the outcome.</p><h4>Subconscious programming</h4><p>A very helpful technique for achieving anything in life is subconscious programming. It is about acting like the goal was already achieved.</p><blockquote>Fake it till you make it.</blockquote><p>This technique usually does not work out of the box and takes practice to benefit from it. However, there are many people who used this technique to become successful or achieved their goals with it.</p><p><em>Jim Carry</em> is my favourite example when it comes to this technique, he drew himself a check for 10 million dollars and he gave himself 3 years. Jim placed the check into his wallet and kept saying to himself that he will have the money. Most importantly he also acted on it. Back then he did not have that much but he acted as he had it already.</p><p>Guess what, he made it… He shot <em>Dumb and Dumber</em> that brought him exactly this amount of money and became famous.</p><p>You can watch it <a href="https://www.youtube.com/watch?v=aWTH7Kp2lfE">here</a>, this story starts at 16:20.</p><h4>Reward</h4><p>Once the goal is achieved, be proud of it. Give yourself credit, it was hard. Alongside achieving the goal you have most probably acquired a lot of new skills, confidence, self-awareness and hopefully even more that brought you here.</p><p>Celebrate the achievement, share it with your friends, help others to achieve their goals, that’s how we all can grow.</p><h4>Repeat</h4><p>Once you start feeling like continuing with some other challenges and goals for yourself, start the whole process again. Improve the process, learn from it and help others with it. ✌️</p><h3>Achieve goals with AchieveMe 📱</h3><p>AchieveMe is an app designed to help achieve your goals like described above.</p><h4>Create a goal</h4><p>Let’s create some challenging goal, like buy a property. It’s very straightforward. Just click plus and you will be guided through a goal creating wizard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eLSk_XLrg9pjntAXCBtw2A.png" /><figcaption>AchieveMe, goal creating flow</figcaption></figure><p>During the wizard, you will be able to create custom checkpoints to track the progress of the goal or set repetitive checkpoints that will follow some common pattern.</p><p>Once the goal is created it is placed into the In Progress goals.</p><h4>Achieve Scientifically</h4><p><em>Achieve Scientifically, </em>is AchieveMe feature for achieving goals in a scientific way. That means the goal is able to be refined, checkpoints timeline can be adjusted at any time and you will be guided to do <em>Subconscious Programming </em>with the goal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PVUCyFZnzXptFCBAEDOoOg.png" /><figcaption>AchieveMe, Achieve Scientifically flow</figcaption></figure><p>AchieveMe notifies about the upcoming checkpoints towards the goal so as about continuous refinement and progress review.</p><h4>Personal Coach</h4><p>AchieveMe is much more than an app that tracks your goals. It is a social network where you can find, challenge and encourage your friends.</p><p>Professional coaches are available in AchieveMe to help you with setting goals, guide you or to help with any personal challenges.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HMPOL5nHXzzEwxoNhqgoRg.png" /><figcaption>AchieveMe, social network, coaching</figcaption></figure><h4>Download</h4><p>AchieveMe is waiting for you in the AppStore <a href="https://apps.apple.com/cz/app/achieveme/id1373022918">here</a>. For more information please visit its <a href="https://achieveme.app/">website</a> or follow on <a href="https://www.linkedin.com/company/30618637">LinkedIn</a> or <a href="https://www.facebook.com/AchieveMe/?eid=ARCWVyKMJsuG7gj-j3lX9OF9xEtNKUBUEnVgup9EdpfTH5Yc0oMkGu1ZioV_JHfTo6g6YzGXp3P1qSVx">Facebook</a>. Any <a href="/service/mailto:info@cyrilcermak.com">feedback</a> for the App is highly appreciated.</p><h3>In conclusion</h3><p>I hope this article encouraged you to start working on your goals and hopefully, you learnt something new. If you like the article please give a clap or 50 and share it or AchieveMe with your friends. 🥇</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=319eea1ec7b4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Everest Base Camp Track in Winter]]></title>
            <link>https://medium.com/@cyrilcermak/everest-base-camp-track-in-winter-2b9858d56d8?source=rss-85e41d5ab945------2</link>
            <guid isPermaLink="false">https://medium.com/p/2b9858d56d8</guid>
            <category><![CDATA[nepal]]></category>
            <category><![CDATA[everest-base-camp-trek]]></category>
            <category><![CDATA[tracking]]></category>
            <category><![CDATA[adventure]]></category>
            <category><![CDATA[rescue]]></category>
            <dc:creator><![CDATA[Cyril Cermak]]></dc:creator>
            <pubDate>Sun, 02 Feb 2020 16:03:16 GMT</pubDate>
            <atom:updated>2020-02-02T16:03:16.189Z</atom:updated>
            <content:encoded><![CDATA[<p>Prepare yourself so you can help others when things go wrong…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yPGofPuykBD1CaCaQE93Kw.jpeg" /></figure><p>I finished the EBC track in January 2020. Unfortunately, not all the people I met on the track were able to finish it. When I decided to go for this 13 days long track in winter I searched a lot about how winter conditions are on the track. I found only a very few about it. Therefore, I decided to write about my journey here and what I have learned on my way.</p><h3>The Everest Base Camp Track</h3><h4>Preparation</h4><p>I decided to go on the 23rd of December and booked a ticket for the 31st. Thereafter, I had only a few days to get all my things for the track in order. I was lucky as in the specialized mountaineering shop in Prague, Czech Republic was a girl who did the track 3 years ago so she told me pretty much everything I needed to know. However, she did not know about the conditions in winter as she did it in spring. I did my homework so I knew the temperatures at around EBC at night can go as low as -45 degrees. That scared me a lot. I bought way too many things in the shop which in the end were actually helpful. Most importantly, I bought a really good sleeping bag.</p><h4>Day 0, Kathmandu</h4><p>I flew to Kathmandu, where I did not have anything booked. I took a taxi from the Airport to Thamel(the tourist part) and found quite a good hotel called Avataar. In the hotel, I asked the local guys about tomorrow’s Lukla flights and immediately booked my way there for the next day. I had a 6:15 AM flight. Before going to sleep I double-checked my backpack and left the rest of my stuff in the hotel reception.</p><p>I also bought a map. 😉</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*RbubsSumZwSZuobEZ5C6zQ.png" /><figcaption>Map — Source: <a href="https://www.researchgate.net/figure/Map-of-the-Everest-Base-Camp-trek_fig2_325667695">https://www.researchgate.net/figure/Map-of-the-Everest-Base-Camp-trek_fig2_325667695</a></figcaption></figure><h4>Day 1, KTM → Lukla and Lukla → Monjo</h4><p>At 5 AM I took a taxi from the hotel to the domestic airport. The Lukla flight was delayed for 2 hours which I later learned was a pretty good time. In roughly 30 minutes I landed in Lukla. Lukla is usually the starting point of this track. I had an idea of going by myself to Namche Bazaar and then hire a guide there. However, right after I step on the land of Lukla some random Nepali guy came to me and offered me his services as a guide to EBC.</p><p>We hit it off and I hired him after a 30 minutes chat over a tea in Lukla. His name was Dhana. After the chat, he invited me to his house and his sister cooked for us. Before we left Lukla we hit the local Lukla market to shop for some oranges for the trip. 🍊 We started walking at around 10 AM that day.</p><p>We talked all our way about our lives, I was particularly interested in how the mountain people live, what they do for a living, etc. We stopped after circa 4 hours for late lunch in Phakding and then continued our journey. Later that day we met a swiss couple, Liam and Emma(not their real names), we chat for a while and hit it off like a house on fire. We walked to Monjo with them and they then joined for the same lodge to sleep in. We all sat together in the living room and had a chat about our future adventure. We were quite nervous because no one knew what to expect from the cold and long track but on the other side, we were very excited about it. Well, we were going to see Everest from its Base Camp.</p><p>I was looking forward to test the sleep that night. I went to bed excited to see whether I will be cold or not. Outside was at around -7 I guess and inside could be at around 0 as I saw my breath there already. I was not cold. However, I was not able to fall asleep. Emma had the same problem. Even though I did not sleep I rested pretty well so I felt energic the next morning.</p><h4>Day 2, Monjo → Namche Bazaar</h4><p>Luckily, Liam and Emma asked to join me and Dhana on the track. Which was super good. The walk from Monjo to Namche was quite exhausting. First, we walked around the river down and then probably at around 5 hours up to the steep hill. That was the first time for me where I started to get a headache from the altitude.</p><p>Almost at the end of the hill, we met two Czech girls, Ann and Merry, who were hiking on their own. Unfortunately, Ann started to feel uncomfortable, she started vomiting and felt dizzy. I offered her help, later she accepted and we took her baggage and helped her to walk up to the Namche. Funny enough, in Namche Merry started being sick as well, the same symptoms of the altitude sickness. They both took Diamox, and I tried to take care of them. At one point, Ann had such a strong headache that she even could not open her eyes. They drunk heaps of tea stayed warm and later they went to sleep. Luckily, me, Liam and Emma were fine. I only had a bit of a headache.</p><p>The second night, outside at night was at around -12 and inside was at around -5. It was snowing the whole night. In the morning I was scraping the ice from inside of the window. However, the sleeping bag kept me warm but falling asleep was nearly impossible.</p><h4>Day 3, Namche Bazaar acclimatization</h4><p>The third day was an acclimatization day. Girls woke up and felt way better so they decided to join us that day. The whole Namche was covered by snow. We went to Everest’s view and then hiked to 4000m and came back to Namche. I started having a massive headache when I got back from the hike. That day I started taking Diamox as well. Obviously, it was too late but yet it helped a lot.</p><h4>Day 4, Tengboche</h4><p>We started the walk at around 8 AM. Ann and Merry decided to join us that day as well. I liked our crew very much. It’s good when the same minded people get together. We walked for a couple of hours mostly down and got into Phungi Thanga, where we stopped for lunch. That’s where Ann and Marry decided to continue on their own with words “we will meet later on the track”.</p><p>It was snowing that day and the visibility was not good. It was also cold. I was quite worried about them but they were grown-ups. We split and started our hike to Tengboche. That was the first time Liam started feeling stomach ache. The hike there was most probably one of the most difficult ones. It took at around 4 hours but the hill was very steep.</p><p>We got to Tengboche even though it was quite early at around 3:30 pm we decided not to continue to Pangboche which was our original aim. Liam’s stomach got worse, my headache was quite bad as well nevertheless Emma was totally fine but cold. Liam went straight to bed and got back for dinner. Ann and Merry continued to Pangboche that day.</p><p>The night was colder it was at around -15 outside so inside could be at around -7. I still could not fell asleep so as Emma. Liam had no problem sleeping however he started waking up at night because of his stomach problem. It was snowing the whole night.</p><h4>Day 5, Dingboche</h4><p>Liam’s stomach has not improved. I asked Dhana to carry his baggage, Liam argued a lot but then he agreed on it. It was a beautiful day and the views were spectacular, so we were happy that we did not miss such a view on the track the day before. We walked to Pangboche where we had lunch and then continued to Dingboche. The weather changed very quickly at that time. It started being very windy and started snowing. It was not far away but quite a steep hike. It took us at around 3 hours to get there from Pangboche as Liam could not walk fast because he started having cramps in his stomach. I started being worried about him, Emma started way earlier.</p><p>The night there was a bit colder as the hotel was made out of stones. I still could not fell asleep even though my body started being quite tired. Out of the window, I saw Ama Dablam, which was amazing.</p><h4>Day 6, Dingboche acclimatization</h4><p>That day we hiked to 5000m and got back to sleep to Dingboche. Liam stayed at the lodge and tried to heal his stomach and got some rest. I was still suffering from the headache but it was not that bad. I do remember that when we got back I had a 20 mins nap!!! Since I was not sleeping for 6 days already that nap healed my headache and that made my day.</p><h4>Day 7, Lobuche</h4><p>Liam felt a bit better in the morning as he was resting the whole day before, so we got a bit better in the mood.</p><p>We started the walk at around 8 am, stopped for a lemon tea and snickers at Dughla and continued our way to Lobuche. The day started nice but then it started snowing again.</p><p>We were a super trio, I was having massive headaches, Liam could not walk because of his stomach and Emma started crying because of the cold and the snow blizzard. It was at around -10, windy and snowing. We fixed Emma with my down jacket as I was still hiking only in my layer one, layer two t-shirts and a wind-proof jacket. Since she started smiling again, it got a bit better. When we got to Lobuche we met Ann and Merry. They stayed in the same lodge. We all started feeling a few problems with breathing. All of a sudden one deep breath was not enough. Lobuche is a place with rocks and mountains only. There are no plants that would produce oxygen.</p><p>Unfortunately, in the evening Liam started feeling much worse. He started vomiting and had massive cramps in his stomach. He had the mentality of a warrior where he was pushing over limits. I admire this in people. However there he suffered a lot and things got out of control.</p><p>We organized with Dhana an oxygen meter and a 100% oxygen bottle for him. At around 6 sherpas came there from the surrounding buildings. No one knew what to do. Dhana suggested to take Liam down on a horse overnight. As the lower altitude might make him better. I was quite against that as he did not have the classic altitude sickness symptoms so the lower altitude might not help him at all.</p><p>All we needed for sure was getting him to a hospital ASAP. Six sherpas had six different opinions. One was like give him oxygen it will make him better but his blood oxygen level was in norm so the oxygen was not necessary. Dhana thought that it might kill him if he was going to breathe the 100% oxygen for an hour and then skip back to the lower air oxygen level. Anyway, after a lot of discussions, we decided not to give him anything and wait till morning and then call the helicopter. He was insured, so like all of us, so <strong>no problem</strong>. At least we thought.</p><p>However, there was no signal in Lobuche and no satellite phone either. So calling a helicopter was not as easy as you might think.</p><h4>Day 8, Lobuche rescue day</h4><p>I got up slightly before 6 am and went to check up on Liam with Dhana. Liam was worse than at the night before, his body suddenly became really weak. I took all his insurance details. I and Dhana then started walking towards Gorak Shep as there they have two cell base stations. However, they are frozen but they unfreeze when the sun comes up.</p><p>It snowed at night and there was no path visible. Dhana was making a new path there as we walked. We walked for about two hours and then finally I had one line of a signal so I started calling the insurance company. The signal dropped after a few seconds so we walked a bit further up until we got on the top of the hill. There I had two lines of signals so I called the insurance again. It was Swiss, therefore it started in French then continued in German and finally English. I got to a call with an insurance guy, I explained that this is a state of emergency and I am calling on behalf of their client and I need to organize a helicopter for him. The guy was totally useless. He said it is not in their competence and that he does not have any number for a helicopter that is cooperating with the insurance company in Kathmandu. That was basically all that I needed, a helicopter company number that is covered by that insurance.</p><p>Dhana was still pushing to me that he has a “friend” who has a helicopter and he can organize it for 4000$ to Kathmandu. That was an option but I did not wanna give up on the normal rescue helicopter and not some shady Nepali helicopter business. I called, 911, 112, 155 all the emergency numbers I knew but all was void. I called my father, it was 3 am his time, to help me google. I stood on a rock surrounded by 8000 m high peaks and tried to get the helicopter number.</p><p>I received a few numbers from my father but none of them worked. Then I called my insurance company. Bad luck got in place there as they could not help me either, as their phone was numb! I could not believe. I prayed for my iPhone to stay alive until we get that sorted cause it was at around -25 at that time.</p><p>I waited there for about 20 more minutes praying a bit for help and luckily it came. There was a small group with a guide passing around us. Luckily the guide had the number for a legit helicopter company. I called it but they managed everything in Nepali so I did not understand what’s going on. Later I got to talk to the guy as well and he said that everything is fine and they will come to pick up Liam and Emma to Lobuche at around midday, I gave him all the insurance details, etc. It took me nearly an hour to get it organized.</p><p>Dhana ran ahead as he wanted to help with the heliport, I walked slowly back. I cried all the way back as I could not believe how can it be so hard to call someone for help in 2020, many more feelings and memories came together with that.</p><p>Anyway, the helicopter was called, the weather was cloudless so there should not be any problem I thought.</p><p>Wrong.</p><p>Lobuche started having a signal at around 11 am. Dhana received a call that the Helicopter is on its way. 30 minutes later, they called again that Lukla had bad weather therefore the helicopter could not come. It needs to take fuel there and then continue to Lobuche. The next flight window was scheduled for 5 pm.</p><p>It ended up as the previous attempt. While Liam was getting worse and worse we could not do anything but wait for the helicopter to come. Next attempt morning the next day.</p><p>I think that night was one of the worst ones Liam ever had. We did not go to sleep. We were going out with Liam every now and then as the fresh air was helping him. Yeah, we had a few nice romantic walks that night at around -25. He was vomiting a lot, his body was really weak, he basically did not really eat past 5 days plus he got to the Lobuche.</p><p>We knew it was a must for the helicopter to come the next morning. Luckily, it did come at around 10 am. Liam with Emma were transferred to Kathmandu where they stayed for three days and then they were transferred to a hospital in Swiss.</p><p>Pheeew</p><h4>Day 9, Gorak Shep + Everest Base Camp</h4><p>After the rescue mission, Dhana thought we will go down, but I wanted to finish the track. Not only that I could photoshop Liam and Emma to the pictures but it took too much effort till now to not to finish it.</p><p>We walked to Gorak Shep, dropped our baggage there and went to the base camp. That day we walked at around 9 hours. On our way to Gorak Shep we met Anna and Marry, we had a quick chat about what happened and continued. The track to EBC was nice. The higher you get the better the views are.</p><p>We got back from EBC when it was already dark as soon as the sun went off it started being really cold. It was at around -30 to -45 according to the local people.</p><p>Funny enough, even though this was the coldest night as inside the room could be at around -25 or -30, I finally had a bit of deep sleep. I was looking forward to sleep there. Dhana was offering me an electric blanket all the time but he did not understand that this was the part I was looking forward to. I took the blanket in case something would go wrong at night but I did not use it.</p><h4>Day 10, Kala Patthar</h4><p>In the morning I went to the bathroom where I saw the big barrel with such a big layer of ice that I could not break. They say that the bathroom is useable from 4 pm. Dhana told me that I am very tired and we should go down, but I wanted to do the KP as well. We hiked there, it took around 3 hours. It was very cold, that was the only time I had all 5 layers on me.</p><p>From Kala Patthar were probably the most spectacular views. Definitely for the Mt. Everest. When we got back to Gorak Shep for lunch I had a headache of my life and started feeling dizzy as well. I started regretting going there. Especially after what happened to my friends. Dhana was quite optimistic and claimed that as soon as we got lower it will be better. That was the first time he took my backpack. I could barely stand but we walked down to Lobuche. Lower we went the head was getting better and better. We got back to Lobuche quite late and I went to sleep almost immediately.</p><p>It was quite funny as Dhana was telling his friends about the rescue mission so I was getting snickers everywhere I went.</p><h4>Day 11, Khumjung</h4><p>We walked for 10 hours and got up to Khumjung. Walking down was much easier and my head was getting better and better.</p><h4>Day 12, Phakding</h4><p>Next day we also walked for about 8 hours and got to Phakding, we stopped in Namche for lunch and continued.</p><h4>Day 13, Lukla</h4><p>We woke up at 3 am to get a 7 am flight. We walked through the night and a lot of dogs accompanied us. I was quite scared as there were at around 15 dogs who were running around us. A few of them went up to Lukla.</p><p>I got to Lukla, said many thanks to Dhana and paid him a bit extra for his work. The only thing he sucked at was the helicopter number else he was amazing.</p><p>My flight got delayed for 3 hours so I flew at around 10 am back to Kathmandu.</p><p>That was pretty much it. I got back to KTM, took a taxi to Thamel and ate everything I could. I was going from a restaurant to a restaurant and ate the most caloric bombs they had.</p><h3>Equipment</h3><h4>Tracking clothes</h4><p>In total, I had 5 layers on the top and 3 layers on down.</p><ol><li>merino wool T-Shirt</li><li>long sleeve merino T-shirt with neck coverage</li><li>fleece hoodie</li><li>down jacket</li><li>windproof jacket</li></ol><p>For legs</p><ul><li>thin thermo trousers 2 pairs</li><li>tracking pants</li><li>3 season tracking shoes</li><li>2 pairs merino wool socks</li></ul><p>else</p><ul><li>winterproof hat with ears coverage</li><li>slim gloves</li><li>fat warm gloves</li><li>sunglasses</li></ul><p>Besides that, I also had one thermo t-shirt for sleeping, running shoes that I changed to in the lodge, one spare jacket and one spare fleece(did not use them).</p><h4>In the backpack (70l)</h4><p>I had a synthetic fibers sleeping bag with the lowest possible temperature of -25. Headlight lasting up to 10 hours per charge. Plastic 1l bottle. Heaps of medication for pretty much everything including Diamox. Loads of protein bars. Raincoat(poncho), water filter, pocket knife, toothpaste, toothbrush, wet baby wipes, vitamin tablets, towel, toilet paper, snowboarding glasses, thermo bottle, power bank, camera and most probably a few more things.</p><h3>In conclusion</h3><p>The EBC track is totally doable in winter, even though it’s quite cold during the night in higher altitude places but that’s the challenge of the track. I lost at around 10kg, I was at around 105kg +- 2kg and got onto 95kg when I got back. I gained back 5kg in 3 weeks as soon as I started eating correctly again. I missed the preparation of the emergency contacts as I was relying on the guide but I should have had done that before as well.</p><p>I met only a few tourists on the track which was amazing. In the lodges, we were pretty much alone all the time.</p><p>If you have reached this end, I hope you have enjoyed reading and wish you a pleasant trip to Nepal, maybe next winter or this one?</p><p>If you like what you read please give a clap or 50. :)</p><p>You can also download <a href="https://achieveme.app/">AchieveMe</a> and motivate people to do great stuff! :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2b9858d56d8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mobile Secrets]]></title>
            <link>https://medium.com/advanced-ios-engineering/mobile-secrets-8458ceaf4c16?source=rss-85e41d5ab945------2</link>
            <guid isPermaLink="false">https://medium.com/p/8458ceaf4c16</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Cyril Cermak]]></dc:creator>
            <pubDate>Sat, 05 Oct 2019 11:57:40 GMT</pubDate>
            <atom:updated>2023-04-05T13:53:51.849Z</atom:updated>
            <content:encoded><![CDATA[<h4>Handle secrets the secure way with ease</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ymygTvST_Ylez3m5ecRETg.jpeg" /></figure><p>In this article, I will show how to use <strong>Mobile Secrets</strong> gem alongside with GPG to handle app secrets the most secure way. <a href="https://github.com/CyrilCermak/mobile-secrets">Mobile Secrets</a> is an open-source project for handling secrets for mobile development. Contributions are highly welcomed. 🛠📱👷‍♀️👷‍♂️</p><p>The first part of the article is more for POs/PMs, feel free to skip to the more technical part if you are already familiar with the basics.</p><h3>What is a secret?</h3><p>A secret is every sensitive information within your app. This piece of information can do real harm to you, your app or business if it is leaked out. The secret is mostly string, but it can also be a certificate, some local file, etc.</p><h3>Why should secrets be handled differently?</h3><p>Let us say that you developed an app that is happily living in the AppStore or PlayStore. The app is built on top of Firebase. Therefore, you have to have your Firebase secret key inside the app to initialise the service. You are a good programmer so one of your jobs is making good and meaningful names for variables.</p><p>Here it comes, you named it firebaseSecret and assigned your secret key to it as a string. Nothing wrong with that, up until one day…</p><p>Your app hit the sky, everyone loves it, it brought too much of an attention. Unfortunately, not only the good one. Obsessed with money, having a black hat on and Kali Linux installed in VM, a hacker will download the app on his jailbroken iPhone. He extracted the IPA out of the phone and reversed engineered the app binary. Out of that, all the in-app strings can be listed. <br>(Assuming the <a href="https://infinum.co/the-capsized-eight/how-to-make-your-ios-apps-more-secure-with-ssl-pinning">SSL Pinning</a> was implemented otherwise, it would be even easier with MITM attack.)</p><p>Yes you guessed it, it will contain your firebaseSecret. The hacker won’t still have access to the Firebase console, however, it can download the whole database of users, their photos with puppies, etc. and… then wipe it out… and sell it back to you.</p><p>Let’s have a look at how it can look like.</p><h3>Reverse engineered binary</h3><p>I used <a href="https://www.hex-rays.com/products/ida/support/download.shtml">IDA</a> to disassemble the compiled binary and here is what I found.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sDSgJPOhU1yg70h5yEsQbA.png" /><figcaption>IDA disassembled binary</figcaption></figure><p>_$S3App7SecretsV14firebaseSecretSSvau+15 — 3 characters long App, contains 7 characters long Secrets with 14 characters long variable firebaseSecret who has assigned 15 characters long string in the subroutine. The Secrets is a struct within the App that contains static let with the name firebaseSecret who has assigned the secret string.</p><p>IDA is way too complex for just finding strings, there is nm — display name list a program that will list all strings within a compiled binary into a console by simply executing nm ./CompiledBinary.</p><h3>How to handle secrets</h3><p>First thing first, the secret must be obfuscated, without a doubt. You can read more about code obfuscation <a href="https://medium.com/swift2go/increase-the-security-of-your-ios-app-by-obfuscating-sensitive-strings-swift-c915896711e6">here</a> and <a href="https://en.wikipedia.org/wiki/XOR_cipher">here</a>.</p><p>Unfortunately, obfuscation might not be enough. What if there is a colleague who has access to the source repository or someone who might want to steal these secrets and hand it out? Simply downloading the repo and printing the de-obfuscated string into a console would do it.</p><p>In general, the secret should be visible only for the right developer in any circumstances. Especially, for mono-repository projects where many teams are contributing to simultaneously.</p><p>In the second part of the article, I will show how to use Mobile Secrets gem and GPG to obfuscate and protect your secrets.</p><h4>Protecting secrets with GPG</h4><p>GPG is the foundation of the Mobile Secrets, therefore some basic knowledge is necessary in order to work with it. If you are familiar with it already, please jump to the next section.</p><p><a href="https://gnupg.org/">GPG</a> or GnuPG is an open-source implementation of <a href="https://en.wikipedia.org/wiki/Pretty_Good_Privacy">PGP</a>(Pretty Good Privacy), GPG allows you to sign and encrypt your data. That being said, it is a perfect tool to handle secrets.</p><p><strong>Getting started</strong></p><p>First, install the GPG via brew, brew install gpg. Then add dotgpgand dotgpg-environment to your Gemfile or simply run gem install dotgpg dotgpg-environment.</p><p><strong>Initialisation</strong></p><p>When everything is installed, it is time to initialise the GPG in the project. Simply execute dotgpg init in the project directory to start.</p><p>GPG will generate a private and public key. The public key is saved in the .gpg folder under your email visible to everyone. This key is used with the keys of other developers to create the hash for encrypting. The private key is saved in ~/.gnupg and is protected by a password.</p><p><strong>Creating encrypted secrets</strong></p><p>To test the creation of a secret file you can just do: echo foo | dotgpg create secrets.gpg, you will be asked for a password and then the hashed secret file will be created. The real secrets will be added later in the article via Mobile Secrets.</p><p><strong>Adding more developers</strong></p><p>To add a developer into the authorised group, the developer needs to provide a public key from his machine, simply dotgpg key will print the key. This key must then be added by the already authorised person via dotgpg add .</p><h3>GEM: Mobile Secrets 📱</h3><p><a href="https://github.com/CyrilCermak/mobile-secrets">Mobile Secrets</a> gem is using <a href="https://en.wikipedia.org/wiki/XOR_cipher">XOR cipher</a> alongside with GPG to handle the whole process. Run gem install mobile-secrets to install it.</p><p>If you have not initialised the GPG yet you can do so with Mobile secrets as well by: mobile-secrets —-init-gpg . .</p><p>Let’s start with creating a template:mobile-secrets --create-template</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NNyRrmC8ZnuzOjnRapYwxQ.png" /><figcaption>MobileSecrets.yml</figcaption></figure><p>In the MobileSecrets.yml edit the configuration to the project needs. Unfortunately, at the time of writing this article only supported language is Swift. Hopefully, Kotlin will be added soon, PRs are highly welcomed. :)</p><p>Import finalized secrets mobile-secrets --import ./MobileSecrets.yml to secrets.gpg</p><p>Finally, we can run: mobile-secrets --export ./Output/Path/ to export the swift file with obfuscated secrets.</p><figure><img alt="Mobile Secrets exported Swift source code" src="https://cdn-images-1.medium.com/max/1024/1*FFqncC87vDvynjjZqWMQ0A.png" /><figcaption>Exported Swift secrets source file</figcaption></figure><p><strong>The ugly and brilliant part of the code</strong></p><p>What happened behind the hood? Out of the YAML configuration, the secrets were obfuscated with the specified hash key and converted into bytes. Therefore, we ended up with an array of UInt8 arrays.</p><p>The first item in the bytes array is the hash key. The second item is the key for a secret, the third item contains the obfuscated secret, fourth is again the key and fifth is the value, and so forth.</p><p>To get the de-obfuscated key just call the string(forKey key: String) function. It will iterate over the bytes array convert the bytes into a string and compare it with the given key. If the key was found the decrypt function will be called with a value on the next index.</p><p>Since we have [[UInt8]] mixed with the hash, keys and obfuscated secrets it would take an extreme amount of effort to reverse-engineer the binary and get the algorithm. Even to get the bytes array of arrays would take a significant effort.</p><h3>Fastlane + Automation</h3><p>Mobile Secrets can also be used as a <a href="https://github.com/CyrilCermak/fastlane-plugin-secrets">Fastlane plugin</a> that provides encrypt_secrets and decrypt_secrets actions. The difference between the Fastlane plugin and the Mobile Secrets gem is that the plugin runs in <strong>non-interactive</strong> mode.</p><p>Simply a password can be passed from the CI as an environmental variable and then used within the Fastlane action to decrypt the secrets so as the private key associated with the account in GPG.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZfJvPTNU0OQygWam3lWdew.png" /><figcaption>Mobile Secrets as a Fastlane plugin</figcaption></figure><p>To install mobile secrets as a Fastlane <a href="https://docs.fastlane.tools/plugins/using-plugins/">plugin</a> simply add gem &quot;fastlane-plugin-secrets&quot; to the Pluginfile. The encrypt_secrets action can be used to create the secrets.gpg file. After it was successfully executed the action should be deleted. The config keys can be later edited via dotgpg edit with the GPG authorised person.</p><p>Since the secrets are now automatically generated, they should be ignored in the .gitignore. Authorised developers will decrypt the secrets with their password and unauthorised can use empty: true inside the decrypt_secrets action to generate the secret source file without the secrets.</p><h4>Improvements</h4><p>GPG uses pinentry, a program that asks interactively in a secure way for your password and then sends it back to GPG. It is quite unfortunate to do it every-time the script is executed. Luckily, there is a pinentry-mac program who is saving the password into a keychain. That being said, the password needs to be set only once and then it is read from the keychain.</p><p>The pinentry-mac can be installed via brew install pinentry-mac.To change default pinentry program for GPG, add this line:pinentry-program /usr/local/bin/pinentry-mac for Intel-based Macs or pinentry-program /opt/homebrew/bin/pinentry-mac for M1-based Macs to: ~/.gnupg/gpg-agent.conf. Create the gpg-agent.conf if it is not in the directory. A restart of the GPG process is required after this change. Simply ps -x | grep gpg and then kill the GPG process. The pinentry-mac should appear for the next GPG action.</p><h3>In conclusion</h3><p>Handling secrets in the project is very important. In this article, I showed a way of dealing with secrets the most secure way I could think of. Mobile Secrets and GPG are awesome tools that can be easily integrated into your project.</p><p>Credits go to <a href="https://twitter.com/joenest">Joerg Nestele</a>, who worked with me on Mobile Secrets.</p><p>If you like what you read please share and give a clap or fifty. :)</p><p>If you liked this article and want to know more then please have a look at my book <a href="https://leanpub.com/modular-architecture-on-ios-and-macos">Modular Architecture on iOS and macOS — Building large scalable iOS and macOS apps and frameworks with Domain Driven Design</a> where I keep the latest development practices I learnt along the way. Or simply get in touch on <a href="https://www.linkedin.com/in/cyril-cermak-210a8b6b/">LinkedIn</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8458ceaf4c16" width="1" height="1" alt=""><hr><p><a href="https://medium.com/advanced-ios-engineering/mobile-secrets-8458ceaf4c16">Mobile Secrets</a> was originally published in <a href="https://medium.com/advanced-ios-engineering">Advanced iOS Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Behind the scene of ETag caching]]></title>
            <link>https://medium.com/advanced-ios-engineering/behind-the-scene-of-etag-caching-d48ba0946aa5?source=rss-85e41d5ab945------2</link>
            <guid isPermaLink="false">https://medium.com/p/d48ba0946aa5</guid>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[etag]]></category>
            <category><![CDATA[cache]]></category>
            <category><![CDATA[http-request]]></category>
            <dc:creator><![CDATA[Cyril Cermak]]></dc:creator>
            <pubDate>Sun, 21 Jul 2019 09:43:26 GMT</pubDate>
            <atom:updated>2019-07-21T09:59:10.941Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently I had a task to implement custom ETag caching mechanism into our core part of the iOS app. My rough estimation of the task was 2 days. Unfortunately, 2 days only took the investigation work, please let me tell you why.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H6sJjOISU4FFAHFmxM7XWw.jpeg" /><figcaption>Designed by Alekksall / Freepik</figcaption></figure><h3>What is Etag?</h3><p>First of all, what the <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ETag">ETag</a> is? ETag is a response header in HTTP that allows you to check whether a requested resource has changed or not. Thanks to ETag, caches can work more effectively. As instead of the requested resources returning the data it returns 304(NOT MODIFIED) and the data are taken out of local caches. That saves us a bandwidth in our applications. On the first request, the client saves the ETag and then attach it in If-None-Match<br>header for the next request.</p><h3>ETag caching behaviour in clients</h3><p>Along the way of implementing my custom ETag caching, I learnt the hard way how it works behind the scene on client sides (Browsers, iOS, Postman, curl, …).</p><p>By default, high-level clients like Postman, Chrome, iOS… will add to the request an HTTP header Accept-Encoding, which makes absolute sense as you don’t want to add that header to it by yourself all the time and you want to have the transfer to be as effective as possible. Thanks to my dear friend <a href="https://www.charlesproxy.com/">Charles</a> I tracked down that different client adds different accept-encoding header values.</p><p>Postman: Accept-Encoding: gzip, deflate <br>Chrome: Accept-Encoding: gzip, deflate, br<br>Firefox: Accept-Encoding: gzip, deflate, br<br>Safari: Accept-Encoding: br, gzip, deflate<br>iOS: Accept-Encoding: br, gzip, deflate <br>curl: no accept-encoding is presented<br>(order matters)</p><h3>ETag on AWS CDN</h3><p>Our CDN whose the custom ETag caching was meant to be implemented for is hosted on AWS. By default, if you request a CDN resource on AWS in any client besides curl it returns in headers Transfer-Encoding: chunked. That makes total sense. CDN expects that it will be sending large files to clients, therefore, it serves them in <a href="https://en.wikipedia.org/wiki/Chunked_transfer_encoding">chunks</a>.</p><p>Now we are getting to the bottom of the problem. Since clients always send the Accept-Encoding header as shown above this led to a mismatch of encodings and the ETag was never calculated and therefore, never returned in the response.</p><p>Interestingly, since curl has no Accept-Encoding header present the ETag is returned every-time as the server in my case CDN on AWS decides which encoding to choose and serves it to the client.</p><h3>Solving the problem</h3><p>So after roughly two days of depression, applying for a new job in McDonald’s, giving up on SW engineering, I had the solution and my sun shined again.</p><p>The solution is quite straightforward, to make it all work you just have to overwrite the default Accept-Encoding header so that the client does not attach the default one by itself. This worked for me on every platform.</p><h3>Conclusion</h3><p>Sometimes it takes more time to figure it out the nowadays convenience of clients than to implement a related specific feature in the app. I hope this article saves someone the time that I had to put into the investigation.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d48ba0946aa5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/advanced-ios-engineering/behind-the-scene-of-etag-caching-d48ba0946aa5">Behind the scene of ETag caching</a> was originally published in <a href="https://medium.com/advanced-ios-engineering">Advanced iOS Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Localising iOS App Modules]]></title>
            <link>https://medium.com/advanced-ios-engineering/localising-ios-app-modules-f4352030bf86?source=rss-85e41d5ab945------2</link>
            <guid isPermaLink="false">https://medium.com/p/f4352030bf86</guid>
            <category><![CDATA[modular-architecture]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[localisation]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Cyril Cermak]]></dc:creator>
            <pubDate>Mon, 25 Mar 2019 11:00:55 GMT</pubDate>
            <atom:updated>2019-03-25T11:00:55.081Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bvDg7mq5o3RJ21NlOQ04Fw.png" /></figure><h3>Introduction</h3><p>Localising your app can be challenging. Not only that you have to check the UI to make sure the strings are constrained appropriately. But there is also the challenge of dealing with the strings themselves. This article will show you a nice and simple way of localising your iOS/macOS app. :)</p><h3>Preparation</h3><p>First of all, we have to add another language to the app. This is done through the Localisation section in the Project Info Tab. A file called Localization.strings should be automatically created by Xcode. Apple calls this file a localisation table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*DhfBAx9-SOv6Yq0AOtcmSg.png" /><figcaption>Localisations section</figcaption></figure><h3>Localising modules</h3><p>I wrote two articles about modular architecture on iOS while there module is a framework in this article module is a logically separated part of the app in a folder. But don’t worry the process is the same. :) I will demonstrate the localisation on my latest project called <a href="https://achieveme.app/">AchieveMe</a>. So let’s say that AchieveMe has those modules — <em>Dashboard</em>, <em>Friends</em>, <em>Goals, Login </em>etc… Each module is a logical part of the app and has its own enum of localised strings. With that being said, you can imagine that by dividing localisation to modules will let you find strings in enum quite easily.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/346/1*4QiBdkiVDlX0APHnqHfRMA.png" /><figcaption>App Modules Structure</figcaption></figure><h4>Localised enum</h4><p>Since we have many modules with even more enums a protocol would be nice to define the enum interface. Let’s create a <em>LocalizedStringRepresentable</em> protocol that has a get accessor for a variable called text. The <em>text</em> variable will be the one we will use in the code to get our localised string.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e4b5ff44abe35d736176743e148051c4/href">https://medium.com/media/e4b5ff44abe35d736176743e148051c4/href</a></iframe><p><strong>Name-spacing</strong></p><p>When it comes to localisation, namespace is your best friend. Therefore, we will namespace each enum with a unique path. Why does this matter? It might not be necessary in the beginning but when your app grows bigger and bigger you would have a hard time to think of a proper name for the localised string that has not been used in the localised table yet.</p><p>In our case namespace is going to be a module path separated by dots. For instance, module login will have a prefix <em>module.login.</em> as a namespace.</p><p>I would not advice on using localised strings from other modules. When it comes to a localisation it always worked for me much better to have it all strictly separated even though some strings were duplicated across modules.</p><p>Now, let’s look at the LoginLocalization enum.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/113a6865a59721d059d2929be6074ac7/href">https://medium.com/media/113a6865a59721d059d2929be6074ac7/href</a></iframe><p><strong>Usage in the code</strong></p><p>To have a localised string in the app simply select a proper key from the enum and call the text variable. The part I really like about it is that we are not using any raw untranslated strings in the code which makes the code much more clearer.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/378f9b17382e50b1e8c33babe693274a/href">https://medium.com/media/378f9b17382e50b1e8c33babe693274a/href</a></iframe><p><strong>Localised table</strong></p><p>The <em>Localization.strings</em> file for module login would then looked like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/03dcc334e08e74ec692aee51a1b6f18f/href">https://medium.com/media/03dcc334e08e74ec692aee51a1b6f18f/href</a></iframe><p>…as you can see each word has it’s module prefix.</p><p><strong>Localised table lookup method</strong></p><p>Finally, we need to create a String extension that will contain the localized method we are going to use for translating our name-spaced keys from the Localized.strings table.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/64f6e71867ce4f779d04c9f59e9759c6/href">https://medium.com/media/64f6e71867ce4f779d04c9f59e9759c6/href</a></iframe><h3>Localising XIBs/Storyboards</h3><p>Ever since I have discovered <a href="http://snapkit.io/">SnapKit</a>(3 years ago) I tried to avoid using Interface Builder. However, you can simply drag the IBOutlet to the swift file and then use the enum to localised the strings in a proper way. :)</p><h3>Testing your localisation</h3><p>Once everything is set it is time to try the app in other languages. Luckily, Apple made that easy for us. You can specify the application language under Edit Scheme → Options. The app will then launch with the specified language.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*59k8gK-4zMjFAsf5Y27wqg.png" /></figure><h3>Conclusion</h3><p>In this article I described a nice way of localising modules of an app with enums. If you are interested in modular architecture on iOS you can read about it <a href="https://medium.com/freelancer-engineering/modular-architecture-on-ios-and-how-i-decreased-build-time-by-50-23c7666c6d2f">here</a> or <a href="https://medium.com/freelancer-engineering/state-of-the-art-architecture-for-large-scale-ios-apps-2f850248d32d">here</a>. :)</p><p>If you find these articles useful please comment or give me a clap (…or 50) :)</p><p>Thank you very much for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f4352030bf86" width="1" height="1" alt=""><hr><p><a href="https://medium.com/advanced-ios-engineering/localising-ios-app-modules-f4352030bf86">Localising iOS App Modules</a> was originally published in <a href="https://medium.com/advanced-ios-engineering">Advanced iOS Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[State Of The Art Architecture For Large Scale iOS Apps]]></title>
            <link>https://medium.com/freelancer-engineering/state-of-the-art-architecture-for-large-scale-ios-apps-2f850248d32d?source=rss-85e41d5ab945------2</link>
            <guid isPermaLink="false">https://medium.com/p/2f850248d32d</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[framework]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Cyril Cermak]]></dc:creator>
            <pubDate>Mon, 10 Sep 2018 05:39:10 GMT</pubDate>
            <atom:updated>2021-11-04T19:53:14.459Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>I wrote an <a href="https://medium.com/freelancer-engineering/modular-architecture-on-ios-and-how-i-decreased-build-time-by-50-23c7666c6d2f">article</a> about migrating our iOS a<a href="https://itunes.apple.com/au/app/freelancer-hire-find-jobs/id927810012">pp</a> into frameworks and how the app benefits from such work. This article continues and goes into more detail with the work that was done on the project after migration. I describe how you can elegantly link in-house developed frameworks together and what kind of patterns should be followed to achieve truly decoupled architecture for large scale iOS apps.</p><p>Note for my PMs…everything was done in my “product spare time” :)</p><h3>Motivation</h3><p>In the architecture I previously discussed, where everything belongs to a proper framework, where the main app target links all frameworks, where project structure is as decoupled as it can be, raises one important question… What is the best way of linking everything together? The state of the art would be to have the main app target (your app that is linking all frameworks together) to delegate responsibility to a framework and then be notified about framework desires e.g. framework that is currently being used wants to present a ViewController that belongs to another framework. The main app would then be notified about this change and the desired ViewController would be presented.</p><p>I hope you can imagine all the advantages of such an approach. First of all, I would like to mention reusability, imagine the scenario that happened to Facebook. Their app split into two (Facebook, Messenger), with this architecture it would take a lot less effort to achieve that so as to support both apps in the same time. Since everything is linked to the App at one place you can also quite easily take the whole framework/feature out and link it to multiple apps. No need to mention, that in a team, each developer can take responsibility over some specific framework, but more on that in the previous <a href="https://medium.com/freelancer-engineering/modular-architecture-on-ios-and-how-i-decreased-build-time-by-50-23c7666c6d2f">article</a>.</p><h3>The Three Tier Architecture</h3><p>In the previous article I discussed how you can modularise your app into frameworks. In this article I will build on the work we did in that article by dividing the project into 3 logical tiers that follow some strict rules.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NdrsSCt0eW4np6SDwRsDAg.png" /><figcaption>The Three Tier Architecture</figcaption></figure><h4>First tier (glue)</h4><p>The first tier consists of our main app target. It has the AppDelegate object, initialises some of our services, responds to notifications and so on. Besides that, it has our main app coordinator. The coordinator responsibility is to handle transitions in the app. It instantiates coordinators from framework features and passes responsibility to them as its child coordinator. Child coordinators notify their parents (in our codebase the main app coordinator) about actions that they are not responsible for. There is a number of reasons why we take responsibility away from the child coordinator, primarily because we don’t want one child coordinator to depend on another one as you can see on the image above.</p><h4>Second tier (features)</h4><p>The second tier has all our features, e.g <a href="https://www.freelancer.com/post-project">post a project</a>, management page, chat and so on. Each of these frameworks implement its own coordinator that is being instantiated in the first tier. Ideally, the coordinator should be the only publicly visible object outside of the framework. By having the frameworks coordinator as the only visible object we ensure that is the only way to interact with that feature. The second tier follows a strict rule to not to link any other framework from the second tier. The reason for this is to keep the feature decoupled from others, therefore it can be taken in or out of the project very easily. Nevertheless, the second tier can link any frameworks from the third tier and is being linked by the first tier. With that being said, frameworks in the second tier may need to have some shared dependencies, it is likely that, for example, the feature frameworks will need to access the network or persistence, this is what the third tier is for.</p><h4>Third tier (core)</h4><p>The third tier is the core of the application e.g models, networking, persistence, localisation and so on… Frameworks from this tier are linked by the second tier without any restrictions. However, unlike the second tier, frameworks from the third tier can link each other. It would be extremely difficult to avoid this linking on the third tier. For example, your networking framework so as the persistent will want to use models framework… You can think of numerous scenarios like that. A possible solution can be to create a fourth tier. Only shared frameworks for the third tier would be in the fourth tier. It would be probably a good solution, however we found it to be a bit over-engineered.</p><p>Here is an example of how the workspace could looks like.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/214/1*C9U0aQWMFFv3gG5wrUsNsw.png" /><figcaption>Workspace example</figcaption></figure><h3>Implementation</h3><p>Here is a naive example of how the implementation could look. In the code I am using the term <strong>flow</strong> instead of the coordinator as based on my opinion it is a more accurate term. Lets start with defining a protocol for our Flow. You can checkout the full demo <a href="https://github.com/freelancer/ios-modular-architecture">here</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8908e0b42ba8b5ff6f03e54743ed3486/href">https://medium.com/media/8908e0b42ba8b5ff6f03e54743ed3486/href</a></iframe><p>Now let’s look at the main AppFlow (AppCoordinator).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/91b4fd6d5bbdc86327b093e4c26b5e14/href">https://medium.com/media/91b4fd6d5bbdc86327b093e4c26b5e14/href</a></iframe><p>Finally, implementation of a child flow from one of the frameworks.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/640a667a9019a943b061a9696f600daa/href">https://medium.com/media/640a667a9019a943b061a9696f600daa/href</a></iframe><p>The coordinator pattern has been known for a while, there is plenty of documentation to get you inspired. I would like to point out here that I have seen some implementations where the coordinator takes over the model and is fetching the data or doing some other controller/view-model jobs. No need to mention, that the coordinator is designed for app flow, that is it’s job. The methods that the coordinator implements should only take already calculated/downloaded values from whatever is responsible for that in your architecture (view model, view controller…). In other words, stay <a href="https://en.wikipedia.org/wiki/SOLID">SOLID</a> ;)</p><h3>Conclusion</h3><p>This article describes how you can elegantly link in-house developed frameworks together and what kind of patterns should be followed to achieve truly decoupled architecture on iOS. I have written these two articles because it was uncertain where this setup was going to lead us in the beginning. Luckily, everything looks and works really well. I have already mentioned in the previous article that this architecture is a bit of an overkill for small apps, however might be considered before starting a new large scale project.</p><p>If you find these articles useful please comment or give me a clap (…or 50) :)</p><p>If you liked this article and want to know more then please have a look at my book <a href="https://leanpub.com/modular-architecture-on-ios-and-macos">Modular Architecture on iOS and macOS — Building large scalable iOS and macOS apps and frameworks with Domain Driven Design</a> where I keep the latest development practices I learnt along the way. Or simply get in touch on <a href="https://www.linkedin.com/in/cyril-cermak-210a8b6b/">LinkedIn</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2f850248d32d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/freelancer-engineering/state-of-the-art-architecture-for-large-scale-ios-apps-2f850248d32d">State Of The Art Architecture For Large Scale iOS Apps</a> was originally published in <a href="https://medium.com/freelancer-engineering">Freelancer Engineering &amp; Data Science</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Modular Architecture on iOS and how I decreased build time by 50%.]]></title>
            <link>https://medium.com/freelancer-engineering/modular-architecture-on-ios-and-how-i-decreased-build-time-by-50-23c7666c6d2f?source=rss-85e41d5ab945------2</link>
            <guid isPermaLink="false">https://medium.com/p/23c7666c6d2f</guid>
            <category><![CDATA[ios-app-architecture]]></category>
            <category><![CDATA[ios-framework]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[build-time]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Cyril Cermak]]></dc:creator>
            <pubDate>Tue, 03 Jul 2018 01:37:55 GMT</pubDate>
            <atom:updated>2021-11-04T19:53:57.364Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently, I was hired by Freelancer as an iOS engineer to work on their <a href="https://itunes.apple.com/au/app/freelancer-hire-find-jobs/id927810012">core iOS application</a>. As a quite young, fresh, progressive, over-motivated (thanks to YouTube motivation videos) bloke who loves to code I suggested roughly 6 improvements that we should do to the project to improve it. One of the bigger ones was regarding the compile time of the app; which when I started took around 15 minutes after a clean. In this post I’m going to describe how I tackled improving the compile time and the process I went through in transforming the project from one depending exclusively on CocoaPods to a project split into separate framework components, what we gained from it and how the whole process went.</p><h3>Prerequisites</h3><p>This article is partly about CocoaPods and Carthage. For those who do not know what they are, I will give a brief introduction here. Feel free to skip this section if you are already familiar with both.</p><p>- CocoaPods <a href="https://cocoapods.org/">https://cocoapods.org/</a><br>- Carthage <a href="https://github.com/Carthage/Carthage">https://github.com/Carthage/Carthage</a></p><p>Both CocoaPods and Carthage are third-party dependency tools. The main difference between them is the compilation and how libraries are attached to a project.</p><p>Pods in Cocoapods are libraries that are bound together with your application code and compiled alongside it. Every time you do a clean on a project, all the third party libraries must be compiled. Compiling libraries can take a significant amount of time if your project uses a lot of them.</p><p>Carthage does it differently: it fetches and builds libraries into frameworks. Built libraries must then be integrated manually. It also takes much longer to build libraries with Carthage as they are compiled for all the different processor architectures. However, they need not be rebuilt after a clean in a project; a library should only be built again when you want to update it to a new version. It should be noted that a library can be updated without touching all other libraries. Built libraries are linked to a project and attached to the app after it is compiled. To setup Carthage and link all libraries to the project might be quite time-consuming compared to CocoaPods setup.</p><p>Both tools have pros and cons. In general, CocoaPods libraries are easier to add, remove and maintain but they have to be compiled after clean again. Carthage is a bit more difficult to add, remove and maintain but it saves time as all the libraries are not compiled again after a project clean.</p><h3>About the App</h3><p>The project has been in development since 2012. I had to deal with a lot of legacy code, rewrite some Objective-C classes to Swift along the way and so on… But overall, the biggest problem were CocoaPods libraries. We had approximately 80 libraries bundled with the app which of course took a significant time to build. Unfortunately, getting rid of CocoaPods libraries was not as easy as replacing them with Carthage because of the dependencies that some of the libraries have, especially the in-house developed ones.</p><p>18 out of 80 CocoaPods libraries were developed in-house. For example, the Core library was dealing with API and persistence, the Components library had UI components and of course, the Feature1 library had a feature1 and so on. I was very unhappy with the CocoaPods dependency graph i.e., the Core library had Moya, RxSwift, RxMoya, SwiftyJSON and others as a dependency and the Core library was a dependency of the Feature1 library which had its own dependencies like RxCocoa, RxDataSources and so on… The image below describes simplified dependency graph of CocoaPods libraries we had.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/953/1*TsDVul7u9auIN3rZWki6SQ.png" /><figcaption>CocoaPods libraries in the project</figcaption></figure><p>Please imagine the concept from the image above on 18 in-house CocoaPods libraries and 62 third-parties… Well to only install CocoaPods libraries took some time. You could easily break the tree by adding some other dependency into an in-house podspec as each in-house library has it’s own podspec so it was quite hard to organize where the specific third-party library is coming from.</p><h3>Migrating to Frameworks</h3><h4>The idea</h4><p>Compiling third-party pods after clean took approximately 6 minutes which was just unacceptable. But I could not just easily replace e.g Alamofire with its framework version as Moya has Alamofire as a dependency so as RxCocoa has RxSwift and so forth. Therefore, if I was to replace Alamofire with its framework version, the Moya library would download the Alamofire anyway as it depends on it. I would end up with two Alamofire libraries linked to the project, one manually and the second one used with CocoaPods. This was just an example of the problem no need to mention that I was facing similar issues with the other 62 libraries.</p><p>I did not want to do it this way. We decided to get rid of in-house pods and create frameworks instead. We did not want to abandon CocoaPods as some of our CocoaPods libraries were not Carthage compatible and honestly it is much easier to test new libraries with CocoaPods than with Carthage. Our intent was to have both — include third-party libraries built by Carthage alongside with CocoaPods to our in-house frameworks and to the project.</p><p>Nice idea… and that is where the real work began. After some research of how to combine pods with frameworks, I created a proof of concept which worked but I was not very certain about it and did not know how it was going to work on a large scale project.</p><h4>About Frameworks</h4><p>What is a framework anyway? We can look at a framework as some bundle that is standalone and can be linked to a project. The main difference between a library and a framework is in the Inversion Of Control (IoC). When you are using something from a library, you are in control of it. On the other hand when you are using something from a framework you are passing responsibility for it to the Framework. I’ll delve more into IoC in the paragraph below. Libraries, at least on iOS, cannot contain anything other than code. A framework can contain everything you can think of e.g storyboards, xibs, images and so on…</p><p>As mentioned above, the way framework code execution works is slightly different than in a classic project or a library. For instance, calling a function from the framework is done through a framework interface. Let’s say a class from a framework is instantiated in the project and then a specific method is called on it. When the call is being done you are passing the responsibility for it to the framework and the framework itself then makes sure that the specific action is executed and the results then passed back to the caller. This programming paradigm is known as <a href="https://en.wikipedia.org/wiki/Inversion_of_control">Inversion Of Control</a>. Thanks to the umbrella file you know exactly what you can call and instantiate from the framework.</p><p>A framework does not support any Bridging-Header file; instead there is an umbrella.h file. An umbrella file should contain all Objective-C imports as you would normally have in the bridging-Header file. The umbrella file is basically one big interface for the framework and it is usually named after the framework name e.g myframework.h. If you do not want to manually add all the Objective-C headers, you can just mark .h files as public. Xcode generates headers for public files when compiling. It does the same thing for Swift files as it puts the ClassName-Swift.h into the umbrella file. You can check the final umbrella file under the derived data folder. Obviously, classes and other structures must be marked as public to be visible outside of a framework. Not surprisingly, you want to expose only files that are called outside of the framework.</p><p>There are two types of frameworks, dynamic frameworks and static frameworks. The major difference between them is how the framework is attached to your project. Static frameworks are attached to the project directly and loaded into the memory address which obviously takes time during app startup and leaves a memory footprint. Every change inside of a static library requires an app to compile again as the framework is part of the app. On the other hand, dynamic frameworks are saved in the app frameworks directory and are loaded only when necessary but they are linked to the project during startup. An app crashes when the framework is not found with an error similar to “dyld: library not loaded” when running the app. More on this topic <a href="https://developer.apple.com/library/content/documentation/DeveloperTools/Conceptual/DynamicLibraries/000-Introduction/Introduction.html#//apple_ref/doc/uid/TP40001908-SW1">here</a>.</p><h4>Creating Frameworks</h4><p>Creating frameworks is pretty straightforward: under the ‘File’ menu, select “New Project”, and then select “Cocoa Touch Framework”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/730/1*HJ_yi4f_qIt9SPxNgFCunw.png" /><figcaption>Creating new framework in Xcode.</figcaption></figure><p>You can copy any files such as assets, source code, xib files, or storyboards to the framework via drag and drop. One problem I came across while doing this was dealing with the Bridging-Header file: as mentioned previously, the Bridging-Header file is not supported in frameworks. You have to make sure that all the necessary Objective-C headers are imported into the umbrella file.</p><p>When I started migrating in-house pods to frameworks I wanted to build them first without Carthage third-party frameworks, meaning that all the third-party libraries were still linked as CocoaPods libraries. The idea was to have a single podfile that contains all of our CocoaPod dependencies. This podfile would be used by all of our frameworks as well as our main project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/753/1*2n3TUs4dcoxGG56fWVO0hQ.png" /><figcaption>Linking frameworks that are being developed</figcaption></figure><p>I was able to achieve that with a little bit of Ruby and CocoaPods documentation. Each CocoaPod library used in a framework should also be included in the main app, as including one in a framework does not also copy it to the main app target; otherwise, you would end up with “dyld: library not loaded” runtime exceptions when starting the app. It took me nearly 2 weeks to get it to a point where I compiled the app with freshly migrated in-house frameworks linked with Pods.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f9f304f1889bde909e7eab48c9ac2a9b/href">https://medium.com/media/f9f304f1889bde909e7eab48c9ac2a9b/href</a></iframe><p>Basically, I went through all the in-house pods one by one, migrating each of them to frameworks while resolving all of their dependencies, and tried to build them without deploying.</p><p>Another week past and I was fixing all the bugs related to the migration. I had tons of issues. One of the most typical was related to `dyld: Library not loaded`. Some issues were related to the access control, some were project related. I also had to deal with some linker errors which were pretty hard to fix.</p><p>One library in particular caused a number of problems — Google Maps. The Google Maps SDK library for iOS is made available as a static library, this is because Google continues to support iOS 7 while dynamic frameworks are only available from iOS 8 and above. It takes extra effort to get static libraries working correctly in this setup so I decided to dedicate a section in this article about how to deal with static libraries in particular.</p><h4>Adding third-party frameworks built by Carthage</h4><p>To link a third-party framework with an in-house framework, it is necessary to add the framework to “Linked Frameworks and Libraries” under the framework target’s General Settings. Afterwards, you want to tell the linker where to find this framework by specifying the framework path under “Build Settings”. This could be as simple as adding `$(inherited)` keyword, which is very handy if you want to have more then one target in the framework that is going to be using third-party dependencies.</p><p>You do not have to set up the Carthage copy phase script here (which copies the frameworks into an iOS application) because a framework cannot be deployed by itself. However, the Copy Phase script should be specified from the App target.</p><p>In my case, each in-house framework should have their own set of unit tests. These tests are deployed to a device, therefore, they must contain the copy phase script, otherwise the test target would crash with the previously- mentioned `Dyld: Library not loaded`.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/731/1*KqJ3mY71vNsBe82qwyJbTg.png" /><figcaption>Linking third party already build frameworks</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*n3UO99hYDzuQ-sAuyjek2A.png" /><figcaption>Setting up the path to third party frameworks</figcaption></figure><h3>Dealing with static libraries</h3><p>In this app, we are using the Google Maps library to show users locations on a map. Using our approach so far, this library was added by CocoaPods both to the main app and to an in-house framework.</p><p>Due to it being a static library, this led to console warnings such as `Class ClassName is implemented in both …` being printed during startup. It turned out the whole library was loaded into memory space *twice*. This had the effect of increasing the app startup time as well as using some additional memory space.</p><p>As previously mentioned, since static libraries are attached directly to the project (unlike dynamic libraries which are linked during run time), it is necessary to make sure that the library is attached only from one location. The solution for us was to extract the GoogleMaps from CocoaPods and link GoogleMaps static frameworks directly to one of our in-house developed frameworks. The library is used only within the framework. However, the framework is linked to other places that are using this library.</p><p>Out of curiosity (and good engineering practice), I looked to measure the app’s *pre-main cold start* times. “Cold start” here means that the app was not yet installed on the device, and the app was installed immediately right after the device was restarted, so that the kernel cache is clean. “Pre-main”, as the word implies, simply means the time it took until iOS calls the `main()` function in the app. (You can enable this by setting the `DYLD_PRINT_STATISTICS` environment variable in the app arguments to `1`.)</p><p>I ran five tests before GoogleMaps was extracted into a separate framework and five tests after. On average, the pre-main took 7.0s with the library loaded twice and 4.2 seconds without on the iPhone 6 Plus and 11.5s vs 7.3s on iPhone 5. I chose an older iPhone as I was expecting the time difference to grow more significantly with the before versus after; results confirmed this to be the case. With that being said, completing the GoogleMaps extraction saved us around 40% of the total time the app spent in the pre-main load cycle.</p><h3>Results</h3><p>Thanks to our migration to frameworks, we now have a modular system and we can look at the app from a different perspective. The image below describes the app after completing this process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/933/1*YQO157zp_FinQk8ZKWDk4A.png" /><figcaption>New architecture of the app</figcaption></figure><p>Also while implementing this architecture, we were able to remove more than half of all pre-existing CocoaPods dependencies and replace them with their Carthage framework versions.</p><h3>Wrap up</h3><p>After roughly 6 weeks, everything was set up and the project was compiling happily. Things that we have achieved on the project thanks to this architecture are really positive. I would like to highlight the pros and cons here.</p><p><strong>Pros:</strong></p><ul><li>Decreased clean project compile time thanks to not compiling CocoaPods libraries repeatedly. When I started this project our compile time was between 12–15 minutes — now compile takes 6–7 minutes. There are still more than 30 CocoaPods libraries left to migrate, so we are aiming to get it even lower than that.</li><li>Divided project into logical parts that are living their life nicely under the framework and are visible from the umbrella file.</li><li>Developers can run and develop only specific parts of the app (specific framework) without compiling everything.</li><li>More flexibility on the project. A framework can be quite easily taken out or linked back into the project.</li><li>We can now develop more efficiently using XCPlaygrounds as a project cannot be imported to the XCPlaygrounds but a framework can. A perfect use case is for developing UIComponents. With Playgrounds there is almost an instant build of the view.</li><li>Every framework contains its unit tests so it can be run in isolation from the rest of the app.</li></ul><p><strong>Cons:</strong></p><ul><li>Setting up and maintaining everything might be quite painful as there are so many things to do and maintain during the development.</li><li>Merge conflicts of pbxproj are something that is very unpleasant. The solution for it is to use XcodeGen. More on XcodeGen <a href="https://medium.com/@danielwilliamson17/xcodegen-a-better-way-to-manage-xcode-projects-3359d2a31d86">here</a>.</li></ul><p>I would probably not use this architecture on a project of a small scale as the overall complexity grows a lot with this setup. I recommend everybody who is interested in it on a deeper level to watch this <a href="https://developer.apple.com/videos/play/wwdc2016/406/">video</a>.</p><p>Feel free to download and test an example of this architecture <a href="https://github.com/freelancer/ios-modular-architecture">here</a>.</p><p>I would like to give a special credit here to my team lead Aldrich Co, who helped me a lot with proof reading of this article.</p><p>Thank you for reading.</p><p>If you liked this article and want to know more then please have a look at my book <a href="https://leanpub.com/modular-architecture-on-ios-and-macos">Modular Architecture on iOS and macOS — Building large scalable iOS and macOS apps and frameworks with Domain Driven Design</a> where I keep the latest development practices I learnt along the way. Or simply get in touch on <a href="https://www.linkedin.com/in/cyril-cermak-210a8b6b/">LinkedIn</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=23c7666c6d2f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/freelancer-engineering/modular-architecture-on-ios-and-how-i-decreased-build-time-by-50-23c7666c6d2f">Modular Architecture on iOS and how I decreased build time by 50%.</a> was originally published in <a href="https://medium.com/freelancer-engineering">Freelancer Engineering &amp; Data Science</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>