<?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 Daniil Vorobyev on Medium]]></title>
        <description><![CDATA[Stories by Daniil Vorobyev on Medium]]></description>
        <link>https://medium.com/@daniilspirit?source=rss-f550ee8e21d3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*kOFqwXVsRMFWYiwxaCqgsg.jpeg</url>
            <title>Stories by Daniil Vorobyev on Medium</title>
            <link>https://medium.com/@daniilspirit?source=rss-f550ee8e21d3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 12:48:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@daniilspirit/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[Blur Effect you want!]]></title>
            <link>https://daniilspirit.medium.com/blur-effect-you-want-9f355afdd4fc?source=rss-f550ee8e21d3------2</link>
            <guid isPermaLink="false">https://medium.com/p/9f355afdd4fc</guid>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[swift-programming]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[xcode]]></category>
            <dc:creator><![CDATA[Daniil Vorobyev]]></dc:creator>
            <pubDate>Sat, 18 Apr 2020 15:47:56 GMT</pubDate>
            <atom:updated>2021-03-08T20:39:04.973Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*4bUKqe2pwCNd_9lTWczlKw.png" /><figcaption>Final Blur Effect that we can easily achieve</figcaption></figure><p>If you have been developing iOS apps for more than half of year and you are crazy about UI, then you probably had to create <strong>Blur Effect</strong>. Sometimes it’s necessary to blur the current UIWindow background and show anything in the foreground like fill-out UI components, UIView with some information, UIAlertViewcontroller’s etc. Apple provides various implementation options, but once again faced with such a task, the most popular of them didn’t help me to achieve the desired result. I would like the <em>Blur Effect</em> to have two important properties: <strong>Extensibility</strong> (customization) and <strong>high speed</strong>.</p><p>In my projects requiring <em>UIImage</em> processing (which also includes Blur Effects) often had to think about performance. To maintain high performance <strong>Accelerate</strong> framework will help us. Accelerate is used to make large-scale mathematical and image calculations much easier for developers and optimized for high performance tasks. It is worth mentioning that this framework requires a separate article but now we will make perfect Blur Effect with it.</p><p>The algorithm of this approach is pretty simple: <em>PresentedViewController</em> makes a snapshot of the content under it and then apply blur filter on created snapshot. Below is the code of our presented controller:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0ccb3de055957a9aad1b3c43949a13b4/href">https://medium.com/media/0ccb3de055957a9aad1b3c43949a13b4/href</a></iframe><p>All that remains is to write the <strong>applyGaussianBlur</strong> method for our image. Below I showed the code using the Accelerate framework:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f50ae2503b3ba431815f85c2b1a61f18/href">https://medium.com/media/f50ae2503b3ba431815f85c2b1a61f18/href</a></iframe><p>Explanations for the code is a separate article, which I will definitely write soon :) It should be noted that the <em>GAUSIAN_TO_TENT_RADIUS_RADIO</em> property can be adjusted depending on what radius is needed. This method gives a good performance and instantly processes the image. As the result we can see:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RFX6j9glU1_NndjWS-Hq6g.jpeg" /><figcaption><strong>With blur radius 4, 10 and 23</strong></figcaption></figure><h3>Another approaches to create Blur Effect:</h3><p>1. The most popular way is to use <strong>UIVisualEffectView </strong>which is use UIBlurEffect by its own. It’s quite easy to create, and the final result can satisfy in rare cases:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/826/1*sHHo9qMvc16pcZq4RXh9-g.png" /></figure><p>UIBlurEffect has 5 styles, but the problem is that they are not extensible. <strong>We can’t control the radius of the blur</strong> of a UIVisualEffectView. <a href="https://stackoverflow.com/a/47475656"><em>We can use hacks and give the impression that the blur radius changes</em></a>, but this is not a good approach and I would advise to avoid such kludge. In addition, there are other possibilities:</p><p>2. Another way to implement is <strong>Gaussian blur effect. CIFilter </strong>has an effect that blurs the input image, moreover, <a href="https://stackoverflow.com/a/38935951"><em>the filter allows us to set the blur radius value</em></a><em>. </em>The concept of such a blur will be slightly different:<em> In this case to get such an effect we need to make a snapshot of the background, and then apply a filter to it. </em>The big disadvantage of this approach is its<strong> slow execution</strong>. Image transformation, applying of the CIFilter and cgImage creation requires resources and substantial time, but we want to show the controller without any delay.</p><p>3. <a href="https://stackoverflow.com/a/60542018">We can obtain private class “</a><a href="https://stackoverflow.com/a/60542018">_UICustomBlurEffect” and use it as UIBlurEffect effect.</a> But this is an extremely unsafe and undocumented way. Never do this. <br><strong>UPD: </strong>Someone in a comments on SO noticed that it does not work with 14 iOS</p><p>In this article, I showed several ways to create a Blur Effect and I hope gave an incentive to learn new frameworks. I will be glad to hear reasonable criticism, feel free to comment. Thank you :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9f355afdd4fc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Indirect Enums on practice]]></title>
            <link>https://daniilspirit.medium.com/indirect-enums-on-practice-58610c9db2ac?source=rss-f550ee8e21d3------2</link>
            <guid isPermaLink="false">https://medium.com/p/58610c9db2ac</guid>
            <category><![CDATA[mobile]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Daniil Vorobyev]]></dc:creator>
            <pubDate>Mon, 20 Jan 2020 20:25:41 GMT</pubDate>
            <atom:updated>2020-03-17T06:12:11.152Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lCpzNBzu8YNlJ_Ut8TmBUw.png" /></figure><p>As we know, <em>Enumeration</em> (<strong>Enum</strong>) defines a common type for a group of related values and enables you to work with those values in a type-safe way within your code. Sometimes we also need to have <strong>associated values — </strong>I<strong> </strong>suppose most of iOS Developers have ever written something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/1*7vNv3h-iZkcRDlrTYC6chA.png" /><figcaption>Associated value</figcaption></figure><p><strong>But what happens if we try to specify in the associated value our enum itself?</strong></p><p>Let’s try to write:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V5sL-XM9jtWSi2XgN2M3QQ.png" /><figcaption>Ooops… recursive enum error</figcaption></figure><p><strong>FAIL. </strong>Compiler shows error: <em>“Recursive enum ‘%EnumName’ is not marked ‘indirect’” . </em>Now we going to figure out what the error is it and how to fix it while preserving our functionality</p><p>As I said earlier, enums are <strong>value type</strong>, which due to the specifics of Apple memory management must be determined at compile time. In other words, we must know exactly how many memory cells we need to allocate for each instance stored on stack. So, <strong>when we determine inside one value type object the same value type object, we create a kind of recursion where it is impossible to understand how much memory is needed for such an object</strong>. In fact, another problem is deduced from this: We can’t determine property of type <em>A</em> inside struct <em>A.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HiqV2btEFGP1TsOu_49zcw.png" /><figcaption>Error described above</figcaption></figure><p>But back to our problem and try to figure out how swift works with <em>associated values enums:</em></p><ul><li><strong>For a Swift enum, enum object will only have one case assigned to itself (since it can’t assigned two values at the same time)</strong></li><li><strong>Then</strong> <strong>compiler checks which case of the enum will occupy the maximum memory.</strong></li><li><strong>Now the instance of enum will have the required memory plus some static memory for current state tracking.</strong></li></ul><p>So how to store <strong><em>recursive</em></strong><em> </em>associated values?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/1*jJxp-OC7QP8DNtfL6rhC7g.png" /><figcaption>Solve the problem!</figcaption></figure><h4>Special word — <strong>indirect — solves the error.</strong></h4><p><strong>Indirect</strong> modify the way Swift stores enum so they can grow to any size. We also can apply indirect only to some cases but not to the whole enum:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/666/1*CyeMEwdDXdQXtljVc6wAGQ.png" /><figcaption>It’s also possible</figcaption></figure><p>Do this when not all of enum’s cases referring recursively itself.</p><p><em>Let’s figuring out what happens when we indicate this declaration modifier.</em> The explanation is easy enough: <strong>Indirect</strong> <strong>instructs the compiler to store the enum’s data behind a pointer. </strong>Another word,<strong> </strong>a static memory size is allocated for storing the <em>refference</em> on the stack, but the content (as I guess) stored on the heap. Thus after these optimizations, no need to make the instance of Enum big enough to hold the whole data.</p><p>I hope this article has been helpful to you!</p><p><a href="https://www.tothenew.com/blog/recursive-enumerations-in-swift/">https://www.tothenew.com/blog/recursive-enumerations-in-swift/</a> — Excellent article which i used in my own</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=58610c9db2ac" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Let’s practice multithreading]]></title>
            <link>https://daniilspirit.medium.com/lets-practice-multithreading-97a5e0f2c386?source=rss-f550ee8e21d3------2</link>
            <guid isPermaLink="false">https://medium.com/p/97a5e0f2c386</guid>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[swift-4]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[swift-programming]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Daniil Vorobyev]]></dc:creator>
            <pubDate>Sun, 12 May 2019 08:22:50 GMT</pubDate>
            <atom:updated>2019-05-12T08:22:50.010Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi all Medium community. In this article I would like to show <strong>by examples</strong> how multithreading works in Swift. I know that there are many articles on the topic of multithreading in iOS, but I would like to systematize all the basic points here. So, let’s start.</p><p>Firstly, should clarify what thread and queue are:</p><ul><li><strong>Thread</strong> is a<strong> </strong>point of execution in program, that executes a process in the system.</li><li><strong>Queue </strong>is a different from the thread. They are merely queues of closures that will eventually be forwarded to a relevant thread by the system.</li></ul><p><em>Note, that processor can perform only one of your tasks at any given time, and in the case of a single-core CPU multithreading is achieved by fast switching between threads (</em><strong><em>context switch</em></strong><em>). In the case of multiply-core CPU multithreading is achieved by the fact that each thread associated with a task is provided with its own core for running tasks.</em></p><p>A queue can be synchronous and asynchronous:</p><ul><li><strong>Sync </strong>function locks the current queue, and returns control to the current queue only after completing its task</li><li><strong>Async </strong>function<strong> </strong>returns control to the current queue immediately after starting the job for execution in another queue, without waiting for it to complete</li></ul><p>Enough of boring theory, now let’s create two test functions with emoji printing and two queues.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/aecdc9d9f852d1b6fc10758358386f81/href">https://medium.com/media/aecdc9d9f852d1b6fc10758358386f81/href</a></iframe><p>And let’s see what the next piece of code displays:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d81dc142adbccc2ea1c82b785407fce3/href">https://medium.com/media/d81dc142adbccc2ea1c82b785407fce3/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ost-MgxjGeg2xyum0Vu1QQ.png" /><figcaption><strong>Output</strong></figcaption></figure><p>Here <strong>sync </strong>function of <strong><em>queue1</em></strong><em> </em>stops the execution of our current main queue and returns to it only after completing <em>emoji1(). </em>And only then<em> </em>system takes the <strong><em>queue2</em></strong> closure into processing and performs <em>emoji2().</em></p><p>Now consider another example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/37060b9d709c7d15a3a4351e20dfafb9/href">https://medium.com/media/37060b9d709c7d15a3a4351e20dfafb9/href</a></iframe><p>Here we see a resource-intensive addition operation that is performed in a cycle, as well as an asynchronous<strong> </strong><em>print(“1”)</em> call in the same queue first. Let’s see the program output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7Rm6c3cT_JZjMD1MNGw3yA.png" /><figcaption><strong>Output</strong></figcaption></figure><p>As we can see, <strong>queue1.async { print(“1”) } </strong>didn’t execute before resource-intensive operation. The reason is simple: <em>Queue1 </em>is a <strong>serial queue</strong>.</p><ul><li><strong>Serial queue </strong>is a queue which sequentially executes its closures</li><li><strong>Concurrent queue </strong>is a queue which executes its closures in parallel, without waiting for the execution of the current task.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EK6a2QU_wjXJYNI8X8aXog.png" /><figcaption><strong>Concurrent and serial queues</strong></figcaption></figure><p><strong><em>Note: DispatchQueue.main is a serial queue</em></strong></p><p>So in the example above, <strong>print(“1”) </strong>will be executed only after the external process is completed.</p><p>Finally, let’s look at the last example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/91c9e28e8ee489036a9b30dc28e732b8/href">https://medium.com/media/91c9e28e8ee489036a9b30dc28e732b8/href</a></iframe><p>and its output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n4jkKF9ZiY0jGdsYXkbjjQ.png" /><figcaption><strong>output</strong></figcaption></figure><ul><li>Obviously ( I hope so :) ), the first will be called<strong> print(“1”)</strong></li><li>Next will be called <strong>print(“4”)</strong>. Why so? Even despite the presence of <em>sleep(2), </em><strong>queue1</strong> is a serial queue, which means the system can’t start executing other <strong>queue1</strong> blocks, and also can’t continue to perform <strong>queue2, </strong>because<strong> queue1.sync { sleep(1) … } </strong>blocked further execution of <strong>queue2</strong></li><li>Next will be called <strong>print(“5”) </strong>because closure with <strong>print(“5”) </strong>was added in the queue earlier than <strong>print(“2”)</strong></li><li>Then <strong>print(“6”) </strong>will be called<strong>. </strong>Obviously that a synchronous call of <strong>queue1.sync { print(“5”)} </strong>blocked <strong>print(“6”)</strong> execution.</li><li>Only after <strong>queue1 </strong>has<strong> </strong>completed the previous blocks — <strong>print(“2”) </strong>called</li><li>The last print that we see — <strong>print(“3”)</strong></li></ul><p>But if we make our <strong>queue1</strong> concurrent</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8fc374cc00c62b7c8cad09199bc7e8f1/href">https://medium.com/media/8fc374cc00c62b7c8cad09199bc7e8f1/href</a></iframe><p>we will see a completely different result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AvZ-Pm5yXMtqIUtP5MCr0Q.png" /><figcaption><strong>Result with concurrent queue1</strong></figcaption></figure><p>Now those functions <strong>sleep() </strong>directly affect the order of execution of the code since the concurrent <strong>queue1</strong> begins to execute closures without waiting for the completion of the previous.</p><p>Multithreading is a very important and interesting mechanism that includes a lot of hard and easy things. I didn’t have time to tell in this article about such things as <strong>Quality of Service, Semaphores, DispatchWorkItem, OperationQueue and many others </strong>the iOS developer should be aware of. If this article is useful I will definitely continue a series of topics about multithreading. I will be glad to hear about any comments on the content of the article. Thanks for reading and good luck :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=97a5e0f2c386" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>