<?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 Besar on Medium]]></title>
        <description><![CDATA[Stories by Besar on Medium]]></description>
        <link>https://medium.com/@besari?source=rss-507fd8998d50------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*2gbqBuw0UIqCHObDH8qZYA.png</url>
            <title>Stories by Besar on Medium</title>
            <link>https://medium.com/@besari?source=rss-507fd8998d50------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 21:07:13 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@besari/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[Mobile Apps Continue To Thrive, with Record Spending Expected in 2023: Here is 10 Stats]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://besari.medium.com/mobile-apps-continue-to-thrive-with-record-spending-expected-in-2023-here-is-10-stats-c1ff5bd93946?source=rss-507fd8998d50------2"><img src="https://cdn-images-1.medium.com/max/2600/0*DzObJ9k0LXrg9cuo" width="5184"></a></p><p class="medium-feed-snippet">Looks like mobile app development isn&#x2019;t going anywhere anytime soon. In fact, people are still all about mobile apps and that trend is&#x2026;</p><p class="medium-feed-link"><a href="https://besari.medium.com/mobile-apps-continue-to-thrive-with-record-spending-expected-in-2023-here-is-10-stats-c1ff5bd93946?source=rss-507fd8998d50------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://besari.medium.com/mobile-apps-continue-to-thrive-with-record-spending-expected-in-2023-here-is-10-stats-c1ff5bd93946?source=rss-507fd8998d50------2</link>
            <guid isPermaLink="false">https://medium.com/p/c1ff5bd93946</guid>
            <category><![CDATA[app-development]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Besar]]></dc:creator>
            <pubDate>Tue, 10 Jan 2023 09:19:35 GMT</pubDate>
            <atom:updated>2023-01-10T09:19:35.744Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Location Awareness with iBeacons in Swift: A Guide for Developers]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://besari.medium.com/location-awareness-with-ibeacons-in-swift-a-guide-for-developers-d71f03f59c79?source=rss-507fd8998d50------2"><img src="https://cdn-images-1.medium.com/max/2600/0*u_gPn334Vy5uC7vF" width="5184"></a></p><p class="medium-feed-link"><a href="https://besari.medium.com/location-awareness-with-ibeacons-in-swift-a-guide-for-developers-d71f03f59c79?source=rss-507fd8998d50------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://besari.medium.com/location-awareness-with-ibeacons-in-swift-a-guide-for-developers-d71f03f59c79?source=rss-507fd8998d50------2</link>
            <guid isPermaLink="false">https://medium.com/p/d71f03f59c79</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ibeacon]]></category>
            <category><![CDATA[swift-4]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Besar]]></dc:creator>
            <pubDate>Fri, 16 Dec 2022 13:44:36 GMT</pubDate>
            <atom:updated>2024-03-01T10:53:06.908Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[iOS App Security — keeping apples worm-free]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://besari.medium.com/ios-app-security-keeping-apples-worm-free-568ffdd0fa4b?source=rss-507fd8998d50------2"><img src="https://cdn-images-1.medium.com/max/1920/1*1U-XvMCUvOMv218fNNMl7w.png" width="1920"></a></p><p class="medium-feed-snippet">Tech companies and businesses in general, are taking the subject of data security and privacy more and more seriously, considering it as&#x2026;</p><p class="medium-feed-link"><a href="https://besari.medium.com/ios-app-security-keeping-apples-worm-free-568ffdd0fa4b?source=rss-507fd8998d50------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://besari.medium.com/ios-app-security-keeping-apples-worm-free-568ffdd0fa4b?source=rss-507fd8998d50------2</link>
            <guid isPermaLink="false">https://medium.com/p/568ffdd0fa4b</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[best-practices]]></category>
            <dc:creator><![CDATA[Besar]]></dc:creator>
            <pubDate>Fri, 04 Feb 2022 11:45:10 GMT</pubDate>
            <atom:updated>2022-02-04T11:45:10.104Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Deep Programming]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/better-programming/deep-programming-da7dc58a7104?source=rss-507fd8998d50------2"><img src="https://cdn-images-1.medium.com/max/2600/0*n7BG3NlCMhzCPBpE" width="5472"></a></p><p class="medium-feed-snippet">Cal Newport&#x2019;s book&#x201C;Deep Work&#x201D; applied to programming</p><p class="medium-feed-link"><a href="https://medium.com/better-programming/deep-programming-da7dc58a7104?source=rss-507fd8998d50------2">Continue reading on Better Programming »</a></p></div>]]></description>
            <link>https://medium.com/better-programming/deep-programming-da7dc58a7104?source=rss-507fd8998d50------2</link>
            <guid isPermaLink="false">https://medium.com/p/da7dc58a7104</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[deep-work]]></category>
            <category><![CDATA[productivity]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[focus]]></category>
            <dc:creator><![CDATA[Besar]]></dc:creator>
            <pubDate>Wed, 30 Sep 2020 00:49:05 GMT</pubDate>
            <atom:updated>2020-09-30T00:49:05.617Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Puma — Pure Swift tool to automate iOS application development and deployment]]></title>
            <link>https://besari.medium.com/puma-pure-swift-tool-to-automate-ios-application-development-and-deployment-ff920ac0da26?source=rss-507fd8998d50------2</link>
            <guid isPermaLink="false">https://medium.com/p/ff920ac0da26</guid>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[mobile]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Besar]]></dc:creator>
            <pubDate>Fri, 27 Mar 2020 11:30:33 GMT</pubDate>
            <atom:updated>2020-03-27T21:54:17.917Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to automate iOS app development and deployment using a pure Swift tool — Puma</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7GY5bPwHO_KS5Lz1m-TZDw.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ye9Odd2DPLvDO8hY0adaSA.png" /><figcaption>Puma logo</figcaption></figure><p>You’re developing an app, something great, something that you believe is going to be the next big thing, but along the way you need to switch your focus in order to deal with some chore tasks, things like creating development and distribution build, generating screenshots for the app store deployment, fighting provisional profiles and certificates, and what’s worse, you need to perform them all the time.</p><p>That’s when Puma comes into play.</p><p>But wait! Why Puma???!! We have all those existing tools, tools that have already proven themselves, why should we go with something new?</p><p>Well, Puma is unlike any other tool, Puma is intended to be used as a Swift library and not as a command-line tool. With Puma, you do not need to understand/memorize lots of command-line arguments. The library is 100% written in Swift thus type-safe. So what you need to do is just import it and build your own build tool. You can easily call it a unicorn.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EJvWlnaLtXWhxJU_epWsZQ.jpeg" /><figcaption>image source: <a href="https://mktoolboxsuite.com/what-is-a-unicorn-startup/">https://mktoolboxsuite.com/what-is-a-unicorn-startup/</a></figcaption></figure><p>In order to dive deeper, we have written this article to cover some of the key aspects of the library.</p><h4><strong>Table of content:</strong></h4><ul><li>Introduction</li><li>Getting Started</li><li>Example</li><li>Bonus: tricks and tips</li><li>FAQ</li><li>Conclusion</li></ul><h3>Introduction</h3><p>Puma is a set of build utilities to automate mobile application development and deployment, Puma’s characteristics are the following:</p><ul><li>Puma and its dependencies are written in pure Swift, making it easy to read and contribute.</li><li>Use latest Swift 5.1 features like function builder to enable declarative syntax</li><li>Type-safe. All required and optional arguments are clear.</li><li>No configuration file. Your Swift script is your definition.</li><li>Simple wrapper around existing tools like xcodebuild, instruments and agvtool</li><li>Reuse awesome Swift scripting dependencies from Swift community</li></ul><h3>Getting Started</h3><p>Since we mentioned that Puma is meant to be used as a Swift library, which means it is just Swift code and you have total control over the program thus the recommended way to integrate Puma is via <a href="https://swift.org/package-manager/">SPM</a>, although you are free to go through any package manager of your choice.</p><h4>1. Run Puma as standalone executable</h4><p>With Swift Package Manager, started by creating an executable and add Puma as a dependency Run the following commands in the root dir of your project:</p><pre>mkdir MyBuildTool           <br>cd MyBuildTool<br>swift package init --type executable</pre><p>After executing the commands above, you should see this printed out on your terminal:</p><pre>Creating executable package: MyBuildTool<br>Creating Package.swift<br>Creating README.md<br>Creating .gitignore<br>Creating Sources/<br>Creating Sources/MyBuildTool/main.swift<br>Creating Tests/<br>Creating Tests/LinuxMain.swift<br>Creating Tests/MyBuildToolTests/<br>Creating Tests/MyBuildToolTests/MyBuildToolTests.swift<br>Creating Tests/MyBuildToolTests/XCTestManifests.swift</pre><p>Now open your Package.swift, add Puma as dependencies</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/00231f35a92dc138ffe8be165e584de3/href">https://medium.com/media/00231f35a92dc138ffe8be165e584de3/href</a></iframe><p>Go to <strong>MyBuildTool/Sources/MyBuildTool/main.swift</strong> and start using tasks from Puma. Here is an example how to do that:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/56a52521970fc423ed5ad020a30ce305/href">https://medium.com/media/56a52521970fc423ed5ad020a30ce305/href</a></iframe><p>Now build and run, Swift Package Manager will fetch all dependencies and build your executable</p><pre>swift build<br>swift run</pre><h4>2. Run Puma as macOS command-line application</h4><p>Another way to consume Puma is via Xcode:</p><ol><li>Create a macOS command-line application</li><li>Add Puma via Swift Package Manager in Xcode.</li></ol><h3>Example</h3><p>In <a href="https://github.com/pumaswift/Puma/tree/develop/Example">Example Folder</a> you will find a workspace named TestPuma, it has the following:</p><ul><li>TestPuma project: this is a macOS command-line project to create executable</li><li>Puma project</li><li>TestApp: the test iOS app</li></ul><h4>Generate Puma project</h4><p>Since Swift Package Manager contains only sources, in order to work with Xcode, run the following command to generate Puma project</p><pre>swift package generate-xcodeproj</pre><h4>Run TestPuma</h4><p>Open Example/TestPuma.xcworkspace, the Puma project has already been included. Select TestPuma scheme, in order to run</p><ul><li>You need to sign TestPuma target, the easiest way is to check Automatic Signing and select a team</li><li>You need to sign all frameworks in Puma project or the workaround is to disable Library validation:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vss3UPJ2dGBR_S4C.png" /><figcaption><a href="https://onmyway133.github.io/blog/How-to-fix-library-not-found-with-SPM-and-CocoaPods-in-Xcode/">https://onmyway133.github.io/blog/How-to-fix-library-not-found-with-SPM-and-CocoaPods-in-Xcode/</a></figcaption></figure><h4>Play around</h4><p>You need to tweak the teamId and options according to your project.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5dde7ab3962cca614097504b92be42b7/href">https://medium.com/media/5dde7ab3962cca614097504b92be42b7/href</a></iframe><p>So on this file, you can specify a couple of things, including:</p><ul><li>Which tasks are enabled, meaning which ones you would like to perform, you can do that by setting the value of the isEnabed flag</li><li>The version number for all targets</li><li>The build number for all targets</li><li>UITests destination like the platform, osand the name, you can also specify if you want to test without building.</li><li>saveDirectory for screenshots</li><li>You can specify scenarios which accepts language, localeand an array of destinations, where you can specify things the platform, osand the name</li><li>In the end, you set the workingDirectory</li></ul><p>So once you execute Puma, you’ll get the list of the available tasks just below our beautiful logo, from where you can see which ones are enabled (meaning which ones will be performed)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tRU_pj57D5si8TxZaemwEg.gif" /><figcaption>Puma loading tasks</figcaption></figure><h4>Environment variables and secrets</h4><p>In the TestPuma workspace, there’s a TestPuma scheme which is configured on the TestPuma macOS command-line target. It is shared which means it gets tracked inside git history. If you run Puma inside Xcode, consider duplicating that TestPuma scheme to another unshared scheme, so you can configure launch arguments and environment variables there.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zWVk1gmRFtqatlBA.png" /></figure><p>Pass your environment variables here:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sHYTanyoKTcbzXxQ.png" /></figure><p>Once you&#39;re ready to go and execute Puma, you’ll see this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GElkHe89DjpDZYeZBeb2fA.gif" /><figcaption>Puma output from Console</figcaption></figure><p>Or if you execute it inside Xcode:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*HOCa4rgqb7oqUD98XtTU5Q.gif" /></figure><p>And WALA! There you have it, at the end you will be able to see the summary of the tasks that you have performed and you will be able to check which tasks have succeeded and which ones have failed.</p><p>Puma will generate a file called puma.log in your Downloads folder, the directory can be changed on the main.swift file:</p><pre>workflow.logger = FileLogger(saveFilePath: Directory.downloads.appendingPathComponent(&quot;puma.log&quot;).path)</pre><p>If you have enabled the Screenshot task, you’ll be able to find them on the directory that you have specified (saveDirectory) , in a structure like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*MsivfA-2YCyBICqmY_MB2Q.gif" /><figcaption>Puma — Screenshots</figcaption></figure><h3>Tips and tricks</h3><p>Here are some tips and tricks to work with Puma more efficiently</p><h4>Environment variables</h4><p>When Puma is run as a macOS command-line library, you can access environment variables via ProcessInfo</p><pre>UploadApp {<br>    $0.authenticate(<br>        username: ProcessInfo().environment[&quot;username&quot;]!,<br>        password: ProcessInfo().environment[&quot;password&quot;]!<br>    )</pre><pre>    $0.upload(<br>        ipaPath: Directory.downloads.appendingPathComponent(&quot;TestApp.ipa&quot;).path<br>    )<br>}</pre><p>If you set environment variables in a scheme in Xcode, you can choose to have 2 schemes, one shared main scheme and 1 unshared but with environment variables.</p><h4>Directory</h4><p>Puma encourages explicitly, so you have to provide explicit paths. Instead of typing path like /Users/khoa/Downloads, you can use the Directory class which provides nifty properties for popular locations, they are file URL so you can append path components further.</p><pre>Directory.home<br>Directory.downloads<br>Directory.applications</pre><h4>Configure tasks directly</h4><p>Some tasks like Build, Test, UploadApp uses command-line tools like xcodebuild or altool, and they provide convenient configuration methods:</p><pre>Build {<br>    $0.configure(workspace: &quot;TestApp&quot;, scheme: &quot;TestApp&quot;)<br>}</pre><p>In case you want to customize, you can configure on the command line tool directly:</p><pre>Build {<br>    $0.xcodebuild.arguments.append(contentsOf: [&quot;--scheme&quot;, &quot;TestApp&quot;])<br>}</pre><h3>FAQ</h3><h4>How can I contribute</h4><p>Puma is open source in Github, We are always happy to get new PRs and suggestions.</p><p><a href="https://github.com/pumaswift/Puma/">pumaswift/Puma</a></p><h4>How to get in touch with Puma developers</h4><p>We have set up a slack workspace were we collaborate, make suggestions and open discussions, you’re free to join us in <a href="https://pumaswift.slack.com/">Puma Slack</a></p><h4>Compare with others</h4><p>The idea of making scripts to automate things is not new. Some other tools are battled tested and deal with edge cases, and of course more awesome than Puma.</p><p>Starting from our internal need to automate some small tasks, we hope to extend Puma to deal with more common mobile application development and deployment use cases. There are existing Xcode commands like xcodebuild, instruments, avgtool and other awesome scriptings from Swift community, our job is to connect things up and make them a little bit nicer.</p><h4>Why Swift</h4><p>Swift is a type-safe language. The compiler guides you through completing all the required parameters, which makes it clear what information is needed for a specific task. There is no automatic detector, assumptions and asking us at runtime. No user interaction should be required when running.</p><p>The project is not just for a declarative Swift syntax shell. The code is in pure Swift, which helps contributors to easily reason about the code.</p><p>With Swift Package Manager, you can just import Puma to declare the tasks, and extend the framework the way you want. There is no additional configuration file, your Swift file is the source of truth.</p><p>With Swift Package Manager and GitHub Package Registry support for Swift packages, we believe Swift scripting will become the norm.</p><h3>Conclusion</h3><p>So in this article, we have introduced Puma, we explained what makes it different speaking of other existing tools, made our hands dirty with the library by taking an example then we covered some tips and tricks in order to work with the library more efficiently and finally we went through our current FAQ.</p><p>We have added so much effort to make this tool useful and anti-pain for your daily life as an iOS developer. We believe that with your help, we can sophisticate it, even more, so do not hesitate to send us <a href="https://github.com/pumaswift/Puma/pulls">PRs</a> and/or feedback.</p><p><strong><em>Through Puma our goal is to save tons of developer hours and make it easer for you as a developer to focus on what matters.</em></strong></p><p>_________________________________________________________________</p><p><em>Found this article useful? Follow me on </em><a href="http://medium.com/@besari"><em>Medium</em></a><em> and </em><a href="https://github.com/besarism/"><em>Github</em></a><em> for more:</em></p><p><a href="https://github.com/besarism/">besarism - Overview</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ff920ac0da26" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Xcode Hacks to Make Your Life Easier]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/better-programming/xcode-hacks-cf32434cbc2?source=rss-507fd8998d50------2"><img src="https://cdn-images-1.medium.com/max/2600/0*CoDI3AnXvsvLUOL8" width="5184"></a></p><p class="medium-feed-snippet">Some of the lesser-known features and tricks of Xcode</p><p class="medium-feed-link"><a href="https://medium.com/better-programming/xcode-hacks-cf32434cbc2?source=rss-507fd8998d50------2">Continue reading on Better Programming »</a></p></div>]]></description>
            <link>https://medium.com/better-programming/xcode-hacks-cf32434cbc2?source=rss-507fd8998d50------2</link>
            <guid isPermaLink="false">https://medium.com/p/cf32434cbc2</guid>
            <category><![CDATA[hacks]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Besar]]></dc:creator>
            <pubDate>Wed, 31 Jul 2019 12:08:27 GMT</pubDate>
            <atom:updated>2019-08-31T19:54:41.796Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[“Massive” View Controllers or bad coding style?]]></title>
            <link>https://besari.medium.com/massive-view-controllers-or-bad-coding-style-bf2b0d57c268?source=rss-507fd8998d50------2</link>
            <guid isPermaLink="false">https://medium.com/p/bf2b0d57c268</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[mobile]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <dc:creator><![CDATA[Besar]]></dc:creator>
            <pubDate>Wed, 24 Jul 2019 11:08:39 GMT</pubDate>
            <atom:updated>2019-11-21T08:32:54.576Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IyE0T29KRQq5nJ7qKO-y1g.png" /></figure><p>When you decide to jump into iOS development, you are exposed to a new language, new APIs, frameworks, new conventions. And no less you are exposed to a new architecture design pattern, Apple’s Model View Controller or MVC (recommended by Apple itself).</p><p>Before jumping to Apple’s MVC, let’s stop and talk a little bit about Classic MVC. MVC has been traditionally used by popular programming languages like Java, Python, Ruby etcetera, mainly for GUI programs.</p><h3>MVC (Model View Controller)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e4cwzqZEGcqZ3RGX5qWMpQ.png" /><figcaption>Classic MVC</figcaption></figure><p>As you can see from the diagram, the model is responsible for managing the data of the application. It’s the application’s dynamic data structure and the central component of the pattern, while view presents the model in some kind of format e.g chart, list, diagram, etc.</p><p>The controller after validating the received user input performs interactions by converting that input to commands for the model or view.</p><p>You can ask if it is possible to develop an app using this pattern? YES, but you wouldn’t go for it for many reasons. The problem is that with this pattern we are not guaranteed of having a decoupled code. All three entities are exposed to each other, thus IT WILL NOT HELP us solve the code reuse or no-flexibility problem either.</p><h3>What about Apple’s MVC?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*la8KCs0AKSzVGShoLQo2oQ.png" /><figcaption>MVC by Apple</figcaption></figure><p>Apple’s MVC is all about communication between 3 entities (the same ones mentioned above) and they have to obey certain rules during communication. The controller is the center of all the communication. Its job is to format the model’s information for the view and to interpret the user’s interaction for the Model. Since the Model is UI independent, one of the most important rules of MVC communication is that Model and View should not talk to each other.</p><p>View is the Controllers minions since we mentioned that Controller the center of communication and View cannot talk to Model the other way round. The question is whether View can talk to Controller?</p><p>Yes, it can. Although, since the View doesn’t own the data they display, the communication must be blind. For example, collectionView or some other generic view is showing you a huge collection of books. Let’s say there are 100K books, its foolishness to have that generic view to bring all the books. So the alternative is to use a protocol mechanism to call a set of predefined methods like numberOfItemsInSection, cellForItem, etc. This way View requires the Controller to provide the Model’s data and display it, as we mentioned above.</p><p>But what about the Model, can it talk to the Controller? Well, we mentioned above that the Model is UI Independent. Since the Controller is essentially UI dependent, the communication can’t be direct. In case some Model’s data changes and it wants any UIs that are interested to update, we can use Notification and KVO (Key-Value Observing) for that scenario.</p><p>To give you a better overview, here is a diagram from a Stanford professor, Paul Hegarty.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OC8UuDr2noA0PyZ3ISu1KA.png" /><figcaption>MVC by Paul Hegarty</figcaption></figure><p>It looks very plain right? But things can get a little bit more knotty.</p><p>Things are quiet in control when we have a really simple ViewController which only handles events and manages/layouts views. What about when on top of those mentioned above, you also need to do the following:</p><ol><li>Navigation</li><li>Networking</li><li>Caching</li><li>Error handling</li><li>Model encode/decode</li></ol><p>Well, in that situation you can put every task mentioned above, on the ViewController. After a short-while start complaining about how MVC stands for “Massive View Controllers”. OR just stop complaining and examine which tasks are not necessary ViewController’s responsibility!</p><h3>Which one of those jobs can be moved out of the ViewController?</h3><p>Actually, almost all of them can be moved out of the ViewController, let&#39;s take some examples.</p><h4><strong>Navigation</strong></h4><p>Pushing new ViewControllers isn’t necessarily done by a ViewController, instead, you can use Coordinator Pattern:</p><blockquote>Using the coordinator pattern in iOS apps lets us remove the job of app navigation from our view controllers, helping make them more manageable and more reusable, while also letting us adjust our app’s flow whenever we need. <a href="https://www.hackingwithswift.com/articles/71/how-to-use-the-coordinator-pattern-in-ios-apps">(read more…)</a></blockquote><h4><strong>Layout</strong></h4><p>Another task that can be removed from our view controller is <em>Layout. W</em>ell, what you can do in this case is that you can just create a custom view and on loadView() method, assign that custom view to self.view:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2e2cb96e4c08e339c1c2d8a8dd1f6c14/href">https://medium.com/media/2e2cb96e4c08e339c1c2d8a8dd1f6c14/href</a></iframe><h4><strong>Networking + error handling, encoding/decoding &amp; caching</strong></h4><p>Creating a separate class which covers the networking tasks is a much better way than doing it inside ViewController, as you can see in the example below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ee3d1574534a79108c606374dab0c363/href">https://medium.com/media/ee3d1574534a79108c606374dab0c363/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4fbf1a9ee95b24dfaaac5451cdbd9221/href">https://medium.com/media/4fbf1a9ee95b24dfaaac5451cdbd9221/href</a></iframe><p>ViewController calls the fetchData method with completion callback from <em>ApiService class.</em> The cool thing is that you can also do error handling, encoding/decoding and caching on this class (<em>ApiService</em>). This way we avoid our ViewControllers from being “Massive”.</p><h4>Conclusion</h4><p>In any way, I am not putting one architecture design pattern above the other. This article aims to clarify some misconception concerning MVC, where some developers intent to put all the logic on ViewControllers, something you can’t find on Apple’s Documentation as a suggestion.</p><p>Architectures are not here to solve our problems, they help us to do so. Each design pattern architecture has its pros and cons. And each one of them is destined to tackle a certain situation, so use them wisely.</p><p>Found this article useful? Follow me (<a href="https://medium.com/@besari">Besar</a>) on Medium!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bf2b0d57c268" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>