<?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 Serhat Sezer on Medium]]></title>
        <description><![CDATA[Stories by Serhat Sezer on Medium]]></description>
        <link>https://medium.com/@serhatsezer?source=rss-f8810fe2f9c2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*tvswsvx7UzBgXKqV.jpeg</url>
            <title>Stories by Serhat Sezer on Medium</title>
            <link>https://medium.com/@serhatsezer?source=rss-f8810fe2f9c2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 19:37:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@serhatsezer/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[So you’re reviewing PR on mobile?]]></title>
            <link>https://medium.com/@serhatsezer/so-youre-reviewing-pr-on-mobile-63390cdb9026?source=rss-f8810fe2f9c2------2</link>
            <guid isPermaLink="false">https://medium.com/p/63390cdb9026</guid>
            <category><![CDATA[code-review]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Serhat Sezer]]></dc:creator>
            <pubDate>Thu, 06 Feb 2020 20:08:10 GMT</pubDate>
            <atom:updated>2020-02-06T20:08:10.481Z</atom:updated>
            <content:encoded><![CDATA[<p>Reviewing one’s code is good habit in order for to prevent missing bugs and keeping coding style convention as standard as possible along with Linters. But here I’m not planning to mention things like ‘how to review your team-mate code’ or ‘stay away these bad patterns’. It’s going to be more like me sharing my experience and learnings throughout my career. So things that I’m going to mention might be wrong and I would be happy to know your comments and feedbacks!</p><p><strong>Keep your PR as small as possible<br></strong>Again probably you may heard this almost everywhere. But beileve it or not this is very crucial. Just one moment put yourself in PR reviewers position. Which one would easy for your to review? Three hundreds line of code review for two files or one thousand lines of code for five files each?</p><p><strong>Find a branch name convention which best works for you and the team<br></strong>Giving a good understandable branch name is make reviewers jobs a bit more easier so because of that they don’t have to spend unnecessary time to figure out what the PR does? Good convention I’m using since I start the review code is: If it’s a feature and it has ticket number associated with Issue Tracking Product I use feature/iOS-App-3400_add_user_list you can even create branch feature on Jira so it creates ticket to the remote.</p><p><strong>Testing <br></strong>Okay I think no need to mention writing test. But that one only make sure business logic is not broken or works as expected. How are you going to test actual UI? Writing UI automation test? or testing manually? First one may require more maintenance time of yours if you don’t have dedicated QA teammate. Second one seems a bit quick and easy just check out PR branch and run the app device or simulator. But this approach has some flaws. Based on what reviewer going to test your PR request? It has to be clear <strong>DoD</strong>(Definition of Done) and<strong> A/C</strong>(Acceptance Criteria). Who’s going to write those? People who knows app’s business logic more. You and your teammates!</p><p>But one thing is good to keep in mind that you’re going to review the code and most of the review process time should be reviewing the not testing whole application. One of my previous experience, we were introduced new policy that we’re going to ‘review the code’ and ‘test the application’ in device. Why? Because no writing test, no UI automation etc. After a while review a code turned into testing the implementation manually and we forgot the review the code. Even though it’s important to test your own implementation manually, always try to keep these repetitive tasks to be automated. So you can have more to be productive as a developer.</p><p><strong>Linters<br></strong>Linters are good. Linters are good-but-dominant-teacher for you. It pushes you to write more clean(well based on style guideline) and robust code. It also gives visibily of your code health, prevent you to see ‘you added unnecesarray comma here’ and things like that. It can detect potential bugs, memory leaks, unused variables or functions so list goes on… Like I said the beginning of the sentence, It can tell your mistake. Imagine a stiuation where you wrote some code and your inner voice says that the code which you wrote can cause memory leak. But you decided to ignore it because you think you know better. But later boom! Linter gives you a memory leak warning. So you got your lesson at that point. (I been there!)</p><p><strong>Hooks<br></strong>Git Hooks are basically shell scripts that trigger some specific events occured. Those are every commit, merge, push. For instance you can add a hook that check some certain configuration are setted before branch got merge.</p><p><strong>Pairing<br></strong>This title can be unrelated but it’s important to be pair up one of your colleague who knows businnes logic better than yours. In that way you can reduce code review workload a bit. If you’re conforming one of those XP(Extreme framework) priciples. You have got to pair up with one of your colleauge and by doing that you’re just reduced one reviewer or if you have small development team you can directly merge your feature branch to develop or somewhere else.</p><p><strong>Finding Reviewers<br></strong>I keep the important one to the last. Finding people who are willing to review your code is hard time to time. It’s not good mindset to think like <em>I just add some people for to review and I’m done here</em>. You and your teammates producing something together. You’re running same goal and it has to treated equally. Try to let your teammates know about your delayed PR review on daily stand ups, dedicated slack channels etc.</p><p>So after all we’re doing things we love. Try to enjoy, learn, improve and not take every feedback personally. Look every mistake as an opportunity to improve yourself as a developer.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=63390cdb9026" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Managing View Controller States with Power of Enums]]></title>
            <link>https://medium.com/@serhatsezer/managing-view-controller-states-with-power-of-enums-906d6a108ac6?source=rss-f8810fe2f9c2------2</link>
            <guid isPermaLink="false">https://medium.com/p/906d6a108ac6</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[dry]]></category>
            <dc:creator><![CDATA[Serhat Sezer]]></dc:creator>
            <pubDate>Thu, 03 Oct 2019 20:56:58 GMT</pubDate>
            <atom:updated>2019-10-03T20:56:58.947Z</atom:updated>
            <content:encoded><![CDATA[<p>There are lots of resources, approaches and solutions in order for to reduce view controller overloads such as abstracting view logic out of view controller to view models and getting rid of the navigation transitions with coordinators and all those solutions are good on their own.</p><p>Take a look at the code below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/aa42db294256787abfe4949c2b9372fc/href">https://medium.com/media/aa42db294256787abfe4949c2b9372fc/href</a></iframe><p>In this implementation first we show loading indicator and then notify our view model, dismiss indicator and call <em>reloadData() </em>method in order for to update tableview itself. When our controller started to grow we have to do those stuff over and over again.</p><p>Instead of doing repetitive task every change of controller, we can introduce enums that control view controller state changes and act based on the state.</p><p>Like so;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f1d7d947a2a46431f71ad27c2d3b052e/href">https://medium.com/media/f1d7d947a2a46431f71ad27c2d3b052e/href</a></iframe><p>As you can see instead of adding those view updating works every request/opertion we just introduce new enum value called <strong>State </strong>everytime any state change in our view controller notified with enum values and based on that view controller update itself accordingly.</p><p>So in this time I’d like share something I use often and hope you found useful.<br><strong>Peace ✌🏼</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=906d6a108ac6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Make your Moya cacheable]]></title>
            <link>https://medium.com/@serhatsezer/make-your-moya-cacheable-85d5d0e9bc33?source=rss-f8810fe2f9c2------2</link>
            <guid isPermaLink="false">https://medium.com/p/85d5d0e9bc33</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[moya]]></category>
            <category><![CDATA[cache]]></category>
            <dc:creator><![CDATA[Serhat Sezer]]></dc:creator>
            <pubDate>Mon, 26 Nov 2018 12:56:14 GMT</pubDate>
            <atom:updated>2018-11-26T12:56:14.844Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi there! For this week article we’ll have a look at how can we cache our response sending through Moya framework. But first off I think it would be better to know how cache works in iOS system.</p><h4>URLCache</h4><p>URLCache provides both in-memory and on-disk caching mechanism for URL request. You can be able to adjust your storage by using URLCache.shared instance. If you ask yourself why I needed to use caching anyway? It may be not benifical to use for rather small project. But as a developer we should take scaling into account. For this matter caching request-response will help not to server overload. When a request has finished loading its response from the server a cached response willl be saved to local disk. Next time the “same request” is made the local cache data will be returned.</p><p><strong>Configuring URLCache:</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/58a7ecdb17f7185df94e0a9a4d4eb37f/href">https://medium.com/media/58a7ecdb17f7185df94e0a9a4d4eb37f/href</a></iframe><p><strong>Cache Policy</strong></p><p>If you’re dealing with caching in general you have to declare caching policy in order to show your intent. In <em>NSURLRequest.CachePolicy</em> there are some types for you to specify your intent. Those are;</p><ul><li><strong>useProtocolCachePolicy</strong><br>Use the caching logic defined in the protocol implementation, if any, for a particular URL load request. (Default)</li><li><strong>reloadIgnoringLocalCacheData<br></strong>The URL load should be loaded only from the originating source.</li><li><strong>reloadIgnoringLocalAndRemoteCacheData<br></strong>Ignore local cache data, and instruct proxies and other intermediates to disregard their caches so far as the protocol allows.</li><li><strong>reloadIgnoringLocalCacheData<br></strong>The URL load should be loaded only from the originating source.</li><li><strong>returnCacheDataElseLoad<br></strong>Use existing cache data, regardless or age or expiration date, loading from originating source only if there is no cached data.</li><li><strong>returnCacheDataDontLoad<br></strong>Use existing cache data, regardless or age or expiration date, and fail if no cached data is available.</li><li><strong>reloadRevalidatingCacheData<br></strong>Use cache data if it can be validated by the origin source; otherwise, load from the origin.</li></ul><p><strong>Making request with cache policy</strong></p><p>It’s time to write some to show how URLCache is works with URLRequest! Below code we created URLRequest and gave cachePolicy initializer property to “.returnCacheDataElseLoad” as I described it above it will try to return local cache if it has, if not it will request to remote server.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/beab452425485a3cf33e00b3ad5d4d72/href">https://medium.com/media/beab452425485a3cf33e00b3ad5d4d72/href</a></iframe><h3>MoyaCacheable</h3><p>In Moya framework there is no built-in caching mechanism. You have to do it yourself. But fortunately Moya provides really great approach for developers to add plugin existing framework. Conforming <em>PluginType </em>with your concrete object you can modify request before sending request to the network. Below you can find some of them.</p><blockquote>public protocol PluginType {<br><strong> /// Called to modify a request before sending.<br></strong> func prepare(_ request: URLRequest, target: TargetType) -&gt; URLRequest</blockquote><blockquote><strong>/// Called immediately before a request is sent over the network (or stubbed).<br></strong> func willSend(_ request: RequestType, target: TargetType)</blockquote><blockquote><strong>/// Called after a response has been received, but before the MoyaProvider has invoked its completion handler.<br></strong> func didReceive(_ result: Result&lt;Moya.Response, MoyaError&gt;, target: TargetType)</blockquote><blockquote><strong>/// Called to modify a result before completion.<br></strong> func process(_ result: Result&lt;Moya.Response, MoyaError&gt;, target: TargetType) -&gt; Result&lt;Moya.Response, MoyaError&gt;<br>}</blockquote><p>Here it’s below how I solve this issue conforming PluginType protocol.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4d414254e07f2bdc7661c5dfc7ab9aef/href">https://medium.com/media/4d414254e07f2bdc7661c5dfc7ab9aef/href</a></iframe><p>First off I created protocol called <em>MoyaCache </em>when any API enum that conforms to MoyaCacheable I can be able to catch it from prepare(request:, target:) method on <em>PluginType</em>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4ea972ffd6c5b0e448ad40be6b3abc08/href">https://medium.com/media/4ea972ffd6c5b0e448ad40be6b3abc08/href</a></iframe><p>Here it’s bellow I created extension over Github enum and conform <em>MoyaCacheable</em> protocol. By doing so I can also take advantage of using enum to specify which endpoint use which caching protocol. Pretty neat.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2a9886e2f548aa534b3a43ccde2f9cbd/href">https://medium.com/media/2a9886e2f548aa534b3a43ccde2f9cbd/href</a></iframe><p>Now it is time to call a request to see response if it’s cache the result or not.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c954bba0b3593cb55cd97b7e0fa50213/href">https://medium.com/media/c954bba0b3593cb55cd97b7e0fa50213/href</a></iframe><p>That’s all for this tutorial. I tried to explain clearly as best as I can. I research on the internet to learn how I can bring caching feature to Moya this what I came up with. If you want to learn more further about URLCache I added some links below that can help you!</p><p><a href="https://developer.apple.com/documentation/foundation/urlcache">https://developer.apple.com/documentation/foundation/urlcache</a></p><p><a href="https://nshipster.com/nsurlcache/">https://nshipster.com/nsurlcache/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=85d5d0e9bc33" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Weekly one bite iOS — One-time password(OTP) feature]]></title>
            <link>https://medium.com/@serhatsezer/weekly-one-bite-ios-one-time-password-otp-feature-912665a4fb0b?source=rss-f8810fe2f9c2------2</link>
            <guid isPermaLink="false">https://medium.com/p/912665a4fb0b</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[ios12]]></category>
            <dc:creator><![CDATA[Serhat Sezer]]></dc:creator>
            <pubDate>Mon, 12 Nov 2018 11:39:39 GMT</pubDate>
            <atom:updated>2019-07-23T08:51:03.330Z</atom:updated>
            <content:encoded><![CDATA[<h3>iOS — One-time password(OTP) feature</h3><p>One-time password(OTP)! As we all know this feature is generally used for verification one of your critical operation like money transfer or account verification etc.</p><p>Before iOS 12 we had to write down those numbers or alphanumerical characters by ourself. But thanks to iOS 12 we can get this feature by one line of code.</p><blockquote>let confirmationCodeTF = UITextField()<br>confirmationCodeTF.textContentType = .oneTimeCode</blockquote><blockquote>let textView = UITextView()<br>textView.textContentType = .oneTimeCode</blockquote><p>When you receive the SMS, iOS will automatically show the one time password code in the QuickType bar(above the keyboard) for a few minutes letting you tap on it to automatically fill it into the textField/textView for you.</p><p>I hope you find this feature useful and you can be able to benefit from it! Cheers✌🏼</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=912665a4fb0b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Your Old Friend Associated Object in Swift]]></title>
            <link>https://medium.com/@serhatsezer/your-old-friend-associated-object-in-swift-bb8e105ee633?source=rss-f8810fe2f9c2------2</link>
            <guid isPermaLink="false">https://medium.com/p/bb8e105ee633</guid>
            <category><![CDATA[runtime]]></category>
            <category><![CDATA[swift-runtime]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Serhat Sezer]]></dc:creator>
            <pubDate>Wed, 15 Aug 2018 22:19:32 GMT</pubDate>
            <atom:updated>2018-08-15T22:27:48.925Z</atom:updated>
            <content:encoded><![CDATA[<p>There were times we needed to use property inside Objective-C categories for our extended built-in objects and our custom classes. Often times it reduce overhead otherwise we would need to subclass that class and add neccessary property into that.</p><h3>Associated Objects Come To Rescue</h3><p>Associated Objects is part of Objective-C runtime. It allow you to associate objects at runtime. Simply, you can attach any object to any other object without subclassing.</p><p>Below you can find built-in Associated Object methods in Foundation SDK I’ll explain each property.</p><pre>void objc_setAssociatedObject(id object, void *key, id value, objc_AssociationPolicy policy)</pre><pre>id objc_getAssociatedObject(id object, void *key)</pre><ul><li><strong>object</strong> is the source object for the association, actually it is the object that point to the other object.</li><li><strong>*key</strong> is the the key for the association, this can be any void pointer</li><li><strong>value</strong> is the object you want to store or associate with the source object.</li><li><strong>policy</strong> is enum type defining the type of reference, just like the types you use when declaring properties. Values are: (OBJC_ASSOCIATION_ASSIGN, OBJC_ASSOCIATION_RETAIN_NONATOMIC, OBJC_ASSOCIATION_COPY_NONATOMIC, OBJC_ASSOCIATION_RETAIN, OBJC_ASSOCIATION_COPY)</li></ul><blockquote>When you trying to add computed property inside your extension class compiler gives this error: ‘<strong>Extensions may not contain stored properties</strong>’</blockquote><p>I think we can grasp the idea by adapting the idea to the real world situation. Here it is below there is a category for to create caption for UIImage we want to add additional property through Category in Objective-C.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/893947fb1c520e8e51ed7add4434e4d4/href">https://medium.com/media/893947fb1c520e8e51ed7add4434e4d4/href</a></iframe><h3>In Type Safe World</h3><p>As you may know Swift is type-safe language and It’s forbidden to use stored instance inside the extension because adding an instance property would change the size of instances of that type.</p><p>There is a some solution for this one of them is using Struct and holding values inside struct thus you can change any properties through structs inside extension properties. I think it’s not ideal solution to do so. We can still use Objective-C runtime like we did before in Swift.</p><pre>func objc_getAssociatedObject(_ object: Any, _ key: UnsafeRawPointer) -&gt; Any?</pre><pre>func objc_setAssociatedObject(_ object: Any, <br>                            _ key: UnsafeRawPointer, <br>                            _ value: Any?, <br>                            _ policy: objc_AssociationPolicy)</pre><pre>func objc_removeAssociatedObjects(_ object: Any)</pre><p>You can find simple implementation of associated object in Swift. There is model named ProductDetail and I needed to add additional property to show total sum of basket.</p><blockquote>When you trying to add computed property inside your extension class compiler gives this error: ‘<strong>Extensions may not contain stored properties</strong>’</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/89b13e278c8bc68a17f1f63fa03963d0/href">https://medium.com/media/89b13e278c8bc68a17f1f63fa03963d0/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a745174e797522c2cded5f823844d13b/href">https://medium.com/media/a745174e797522c2cded5f823844d13b/href</a></iframe><h3>Use Wisely</h3><p>Associate object, opening up a world of dynamic dispatch and associated runtime manipulation. Which means you’re chaning something happens in runtime. I’ve never experienced any problem while I use that feature but it’s better to know what you’re doing.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bb8e105ee633" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Make your UITableView & UICollectionView lighter with MVVM]]></title>
            <link>https://medium.com/@serhatsezer/make-your-uitableview-uicollectionview-lighter-with-mvvm-ac4efc833ef7?source=rss-f8810fe2f9c2------2</link>
            <guid isPermaLink="false">https://medium.com/p/ac4efc833ef7</guid>
            <category><![CDATA[coding-style]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[swift-3]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Serhat Sezer]]></dc:creator>
            <pubDate>Thu, 19 Oct 2017 13:24:51 GMT</pubDate>
            <atom:updated>2017-10-20T09:16:13.518Z</atom:updated>
            <content:encoded><![CDATA[<p>Sometimes, working with both UITableView and UICollectionView ending up with bloated views or even controllers. Things more complicated when we need to change our datatype dynamically. Lets say we have two section like below;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*ERkpjVDEO7Rk4hEVHVhFoQ.png" /><figcaption>Let say we have two section one shows current orders and second one shows completed orders.</figcaption></figure><p>Below screen there are two separated section that means we need two seperate model and this two models configured accordinly. If I select “Orders” I have to prepare my cell in table view with Order model. In contrast when I select “Completed Orders” I have to prepare my cell in tableview with related model as well.</p><p>I have created two different model for this situation first one is for active order and second one is for completed orders like so; For this kind of situtations it would more benifical to seperate data sources. We should not re-use our data source files into same application. Instead we should create our data source per table&amp;collection views. By doing so, we can test our view models, models and even our data sources!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0dacf67aabd4eb03e3a1ff2a90b55d76/href">https://medium.com/media/0dacf67aabd4eb03e3a1ff2a90b55d76/href</a></iframe><p>And my ViewModels has very simple job right now.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f0ea7af307ddf06840650ffd3288eb23/href">https://medium.com/media/f0ea7af307ddf06840650ffd3288eb23/href</a></iframe><p>Our data sources only implementing UITableViewDataSource or UICollectionViewDataSource</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0030b06e8d8a436480b91c0fc1360027/href">https://medium.com/media/0030b06e8d8a436480b91c0fc1360027/href</a></iframe><p>And finally, our view controller does only one thing; mediating between views and view models! Generally we should keep our view controller light. This way if we can make unit test our view models that increase our test coverage and our app robutness and doing a little SRP(Single Responsibility Principle) rule.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f40e6b8b83d31f7e08c5eeff23af1d88/href">https://medium.com/media/f40e6b8b83d31f7e08c5eeff23af1d88/href</a></iframe><h3>Testing</h3><p>When make thins red-green-refactor criteria in this approach we can test almost every business logic. We can test our model, view model and even data source like I said before;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8dcc5a3c34531c370c672b31b708a677/href">https://medium.com/media/8dcc5a3c34531c370c672b31b708a677/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ac4efc833ef7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tiny Alamofire Wrapper — ServiceProvider]]></title>
            <link>https://medium.com/@serhatsezer/tiny-alamofire-wrapper-serviceprovider-daf08dd8952?source=rss-f8810fe2f9c2------2</link>
            <guid isPermaLink="false">https://medium.com/p/daf08dd8952</guid>
            <category><![CDATA[generics]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[network]]></category>
            <category><![CDATA[alamofire]]></category>
            <dc:creator><![CDATA[Serhat Sezer]]></dc:creator>
            <pubDate>Thu, 12 Oct 2017 12:41:27 GMT</pubDate>
            <atom:updated>2017-10-18T14:28:25.865Z</atom:updated>
            <content:encoded><![CDATA[<p>Today, I found useful framework called <a href="https://github.com/Moya/Moya">Moya</a> moya is really great for comprehensive network request. But if you’re not working with a big project and your expectations are low you may want to chose or use much lighter framework. Because of that reason I wanted to create a framework to fulfill this issue and I called ServiceProvider.</p><p>I works just like Moya framework. You have to create enum values with or without associate values this enum is used to make sure that you provide implementation details for each target (endpoint) and Xcode check this enum at comple time which is very safer and you never miss the implementation any of these enum values! After that you have to conform <em>RequestRepresentable </em>protocol to to translate each enum values as a request. It’s not final implementation and not a framework yet. I’ll add more features and update this post later on! I just wanted to show my basic approach.</p><p>Here it is the implementation to better illustrate:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/21645939f09214f383693accf4c1df9b/href">https://medium.com/media/21645939f09214f383693accf4c1df9b/href</a></iframe><h3>Creating Request EndPoints</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/346f7306fb858753b6aa980888348f82/href">https://medium.com/media/346f7306fb858753b6aa980888348f82/href</a></iframe><p>After that we simply use our ServiceProvider class to make a request</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/35b95ef598e75678af1d0370e906dd42/href">https://medium.com/media/35b95ef598e75678af1d0370e906dd42/href</a></iframe><p>Here is the Xcode project:<br><a href="https://github.com/serhatsezer/SSServiceProvider">https://github.com/serhatsezer/SSServiceProvider</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=daf08dd8952" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Swift Protocol Composition]]></title>
            <link>https://medium.com/@serhatsezer/swift-protocol-composition-e64692072425?source=rss-f8810fe2f9c2------2</link>
            <guid isPermaLink="false">https://medium.com/p/e64692072425</guid>
            <category><![CDATA[swift-3]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[composition]]></category>
            <category><![CDATA[protocol-oriented]]></category>
            <dc:creator><![CDATA[Serhat Sezer]]></dc:creator>
            <pubDate>Fri, 11 Aug 2017 14:05:49 GMT</pubDate>
            <atom:updated>2017-10-15T13:35:05.188Z</atom:updated>
            <content:encoded><![CDATA[<p>Swift continue evolving since it first announced and as I developer I often try to follow new language-based features and improvements to improve my coding ability. It sometimes hard to keep up to date yourself and yesterday I was noticed that there is still room to improve myself! <a href="https://en.wikipedia.org/wiki/Composition_over_inheritance">Protocol Composition</a> was one of them :)</p><p>Yesterday I wanted to create a plain UIViewController and it contains simple UITableview and this tableview’s cell needed to show some UIImageViews and some UILabels depending on related model. But also I wanted to use that view controller as reusable. Second view controller’s tableview cell also needed to show different UI elements like UISwitch, UIScrollView etc. I didn’t want to create seperate UITableviewCell for this matter. So I came up with an idea to create Protocols for all different representables. For example TextRepresentable, SwitchRepresentable, TextPresentable etc.</p><p>Here it is what i did:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/02b86272fb9b4e996a9ea64e4842e896/href">https://medium.com/media/02b86272fb9b4e996a9ea64e4842e896/href</a></iframe><p>At the top of the file I created typealias and this typealias simply contains all of the presentable protocols.<br>In any view controller which call configure(presenter:) method they can take advantage of our representable!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0c56c49c2140b3e819e546543ae032b9/href">https://medium.com/media/0c56c49c2140b3e819e546543ae032b9/href</a></iframe><h4><em>Update!</em></h4><blockquote><em>Now with Swift 4 there is a connivence way to make composition instead of use protocol&lt;&gt; we can simple do this by ampersand (&amp;) character. Like example below.</em></blockquote><p>Replace from above code to the below one.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/30f5dbf8febd25fdcdca3bf5730d6678/href">https://medium.com/media/30f5dbf8febd25fdcdca3bf5730d6678/href</a></iframe><p>But when I am doing this I noticed something that I am violating one of the SOLID princeple. Called ISP(Interface Segregation Principle) Don’t judge right now🙄 I’ll talk more about SOLID principle in future posts!🤓</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e64692072425" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What’s the “higher order function” in Swift]]></title>
            <link>https://medium.com/@serhatsezer/whats-the-higher-order-function-in-swift-addd1948fb79?source=rss-f8810fe2f9c2------2</link>
            <guid isPermaLink="false">https://medium.com/p/addd1948fb79</guid>
            <category><![CDATA[functional]]></category>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[swift-programming]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[swift-3]]></category>
            <dc:creator><![CDATA[Serhat Sezer]]></dc:creator>
            <pubDate>Mon, 07 Aug 2017 12:16:58 GMT</pubDate>
            <atom:updated>2017-08-11T11:35:24.808Z</atom:updated>
            <content:encoded><![CDATA[<p>Higher order functions <em>“a function can take either accept functions or closure as a argumant”</em> you’ve already familiar with last one right? You can also write your own higher order function or there are a bunch all ready to take advantage of!</p><p>If you want to play little bit more RX functions I highly recommend you to visit <a href="http://rxmarbles.com/">RxMarbles</a> website.</p><p>Most commonly mentioned higher order functions are; (<strong>maps</strong>, <strong>filter</strong>, <strong>reduce</strong>, <strong>sort</strong>)</p><p>But I want to look at <strong>Array</strong> high order functions! ( <strong>contains</strong>, <strong>drop</strong>, <strong>first</strong>, <strong>flatMap</strong>, <strong>forEach</strong>, <strong>partition</strong> and <strong>split</strong>)</p><p>I just want to you to just realize you can’t remember how to use it and resort reinventing the wheel. Let’s take a look at some of these more obscure higher order functions, and compare how some would need to be coded in for-in or while loop.</p><p><em>Imagine we have an array of fruits</em></p><pre>var fruits = [“Banana”,”Pineapple”,”Coconut”,”papaya”,”Kiwi”,”Rambutan”]</pre><h3><strong>Map</strong></h3><p>Perform an operation on every element in an array to build another array.<br>eg. Let’s create another array consisting of all of the fruits in lowercase.<br>Instead of:</p><pre>var fruitLowercase:[String] = []<br>for fruit in fruits {<br> fruitLowercase.append(fruit.lowercased())<br>}<br>//[“Banana”, “Pineapple”, “Coconut”, “papaya”, “Kiwi”, “Rambutan”]</pre><p>We can simply use map:</p><pre>let fruitLowercase = fruits.map { $0.lowercased() }<br>//[&quot;Banana&quot;, &quot;Pineapple&quot;, &quot;Coconut&quot;, &quot;papaya&quot;, &quot;Kiwi&quot;, &quot;Rambutan&quot;]</pre><h3><strong>Filter</strong></h3><p>Returns every element in an array that satisfies a condition<br>eg. Lets say we want all of the fruits that begin with C-P</p><pre>var fruitAK:[String] = []<br>for fruit in fruits {<br> if (“C”…”P”).contains(fruit.characters.first!) {<br> fruitAK.append(fruit)<br> }<br>}<br>//[“Coconut”, “papaya”]</pre><p>We can simply use filter:</p><pre>let fruitAK = fruits.filter { (&quot;C&quot;...&quot;P&quot;).contains($0.characters.first!) }</pre><pre>//[&quot;Coconut&quot;, &quot;papaya&quot;]</pre><h3><strong>Reduce</strong></h3><p>Generate a single value by performing an operation on every element in that array.<br>eg. Lets say we need to know the letter count all of the fruits.</p><pre>var totalLetters = 0<br>for fruit in fruits {<br> totalLetters+=fruit.characters.count<br>}<br>//40</pre><p>We can simply use reduce:</p><pre>let totalLetters = fruits.reduce(0) {$0 + $1.characters.count}<br>//40</pre><h3><strong>Sorted</strong></h3><p>Create a sorted version of an array. You don’t need to see an example of manually sorting an array to understand how this works!<br>Sort an array simply by describing how you want the sort to work. You can do this simply by indicating the direction of the sort with a less than mark or greater than mark.</p><pre>var fruitSorted = fruits.sorted(by: &lt;)<br>//[“Banana”, “Coconut”, “Kiwi”, “Pineapple”, “Rambutan”, “papaya”]</pre><p>Notice that “papaya” comes last, as lower case letters come after upper case letters. You may want to ignore capitalization (or localization) differences:</p><pre>var fruitSorted = fruits.sorted(by: {$0.localizedLowercase &lt; $1.localizedLowercase })<br>//[“Banana”, “Coconut”, “Kiwi”, “papaya”, “Pineapple”, “Rambutan”]</pre><h3><strong>Contains</strong></h3><p>Generate a true/false by checking if any element in your array satisfies a condition. Related to filter, but returns a Bool, rather than an array.</p><p>eg. Let’s say we need to know if our fruits array contains a four letter fruit.<br>Instead of:</p><pre>var fruitContains4Char = <strong>false</strong></pre><pre><strong>for</strong> fruit in fruits {</pre><pre><strong>if</strong> fruit.characters.count == 4 {</pre><pre>fruitContains4Char = <strong>true<br>break<br></strong>}<br>}</pre><pre>//true</pre><p>We can simply use contains:</p><pre>let fruitContains4Char = fruits.contains {$0.characters.count == 4}<br>//true</pre><h3>Drop</h3><p>Drops elements from your array while a condition is true, stops checking when it encounters an element that shouldn’t be dropped.</p><p>eg. Let’s say we want to drop all elements at the beginning of the array that contain the letter ‘a’.<br>Instead of:</p><pre>var fruitDropA:[String] = fruits<br>while fruitDropA.count&gt;0 &amp;&amp; fruitDropA.first!.contains(“a”) {<br> fruitDropA.remove(at: 0)<br>}<br>//[“Coconut”, “papaya”, “Kiwi”, “Rambutan”]</pre><p>We can simply use drops:</p><pre>let fruitDropA = fruits.drop { $0.contains(“a”) }<br>//[“Coconut”, “papaya”, “Kiwi”, “Rambutan”]</pre><h3>First</h3><p>You’re probably familiar with the first property that retrieves the first element of an array, but did you know you can pass in a condition to get only the first element that meets that condition?</p><p>eg. Let’s say we want the first element of the array that contains the letter ‘i’.<br>Instead of:</p><pre>var firstFruitI:String?<br>for fruit in fruits {<br> if fruit.contains(“i”) {<br> firstFruitI = fruit<br> break<br> }<br>}<br>//Optional(“Pineapple”)</pre><p>We can simply use contains:</p><pre>var firstFruitI = fruits.first { $0.contains(“i”) }<br>//Optional(“Pineapple”)</pre><h3><strong>FlatMap</strong></h3><p>Closely related to map, flatMap automatically removes any nil values from a map call, ensuring that the array returned does not contain optionals.</p><p>eg. Let’s say we have an array of String values:</p><pre>let numbers = [“1”,”3&quot;,”pineapple”,”2&quot;]</pre><p>And we want to convert these to an Array of Int. The map function would return an Array of Optional Int, and a nil value for “pineapple” that isn’t a number:</p><pre>let numbersMapped = numbers.map { Int($0) }<br>//[Optional(1), Optional(3), nil, Optional(2)]</pre><p>That’s not what we’re after, we want an array of Int!<br>We could of course do this in a for loop:</p><pre>var numbersMapped:[Int] = []</pre><pre><strong>for</strong> number in numbers {</pre><pre><strong>if</strong> let int = Int(number) {</pre><pre>numbersMapped.append(int)</pre><pre>}<br>}</pre><pre>//[1, 3, 2]</pre><p>But much easier using flatMap:</p><pre>let numbersMapped = numbers.flatMap { Int($0) }<br>//[1, 3, 2]</pre><h3><strong>ForEach</strong></h3><p>The forEach higher order function is a cool tool for your programming arsenal — basically short-hand for the for-in loop.</p><p>eg. Let’s say we want print the lowercase version of every fruit in our fruits array.<br>Instead of:</p><pre><strong>for</strong> fruit in fruits {<br>print(fruit.lowercased(), terminator: &quot; &quot;)<br>}</pre><pre>//banana pineapple coconut papaya kiwi rambutan</pre><p>simply use forEach:</p><pre>fruits.forEach { print($0.lowercased()) }</pre><pre>//banana pineapple coconut papaya kiwi rambutan</pre><h3><strong>Partition</strong></h3><p>The partition method partitions the elements of your array based on a condition. Elements that meet the condition are placed last in the array.</p><p>eg. Let’s say we want all of the fruit in our fruits array that contains the letter “i” to come last. We could do this with a for-in loop:</p><pre>var partitionedFruit:[String] = []<br>var partition = 0<br>for fruit in fruits {<br> if fruit.contains(“i”) {<br> partitionedFruit.append(fruit)<br> } else {<br> partitionedFruit.insert(fruit, at: partition)<br> partition+=1<br> }<br>}<br>fruits = partitionedFruit<br>//[“Banana”, “Coconut”, “papaya”, “Rambutan”, “Pineapple”, “Kiwi”]</pre><p>Notice that “Kiwi” and “Pineapple”, the only elements with an “i” are placed at the end of the array. Alternatively, we can do this with just one line of code with the partition method:</p><pre>fruits.partition(by: { $0.contains(“i”) })<br>//[“Banana”, “Rambutan”, “Coconut”, “papaya”, “Kiwi”, “Pineapple”]</pre><p>Notice that this method, rather than returning a new array, actually changes the array itself. Notice also that the order of the elements within each partition changes in a somewhat random fashion.</p><h3><strong>Split</strong></h3><p>You may be familiar with the components method on String, used to split a String based on a separator.</p><p>eg. Let’s say we have a paragraph that we want to split into sentences. We could use the components method, checking for full-stops (aka periods):</p><pre>let paragraph = “I can’t believe it! These higher order functions are like magic. Don’t you think? Well, maybe not magic, but pretty useful all the same.”<br> <br>let sentences = paragraph.components(separatedBy: “.”)<br>//[“I can\’t believe it! These higher order functions are like magic”,<br>//” Don\’t you think? Well, maybe not magic, but pretty useful all the same”,<br>//””]</pre><p>What’s with that final element though? An alternative to the components method is the split method, which accepts a separator too, but by default will omit blank elements.</p><p>To use the split method on a String, you would use it on the String.characters property, which is a String.CharacterType, which adopts the Collection protocol, giving characters access to many of the same cool higher order functions that Array has access to. Once you’ve separated String characters with split, you’ll have an array of something called a SubSequence, that you can pass in when initializing a String — you can do this on each element of your new array using the map higher order function to end up with an array of Strings.</p><p>what does that look like?</p><pre>let sentencesSubsequences = paragraph.characters.split(separator: “.”)<br>let sentences = sentencesSubsequences.map{ String($0) }<br>//[“I can\’t believe it! These higher order functions are like magic”,<br>//” Don\’t you think? Well, maybe not magic, but pretty useful all the same”,<br>//””]</pre><p>But wait, that ignored exclamation marks and question marks — they also define the end of a sentence. How to separate our paragraph using all three?</p><p>The split method has a fancy higher order function option as well. You can use it to divide our paragraph by full stops, exclamation marks or question marks:</p><pre>let sentencesSubsequences = paragraph.characters.split { $0 == “.” || $0 == “!” || $0 == “?” }<br>let sentences = sentencesSubsequences.map{ String($0) }<br>//[“I can\’t believe it”,<br>//” These higher order functions are like magic”,<br>//” Don\’t you think”,<br>//” Well, maybe not magic, but pretty useful all the same”]</pre><p>Well that’s it! I hope next time you need to perform some magic on an array, you too might remember and take advantage of one of these higher order functions, keep your code nice, pretty and succinct and remember that you don’t need to reinvent the wheel!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=addd1948fb79" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>