<?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 Aytuğ on Medium]]></title>
        <description><![CDATA[Stories by Aytuğ on Medium]]></description>
        <link>https://medium.com/@aytugsevgi?source=rss-dac28fb3667b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*56UVkgeFT_nXkDC0TMD7-w.jpeg</url>
            <title>Stories by Aytuğ on Medium</title>
            <link>https://medium.com/@aytugsevgi?source=rss-dac28fb3667b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 23:30:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aytugsevgi/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[Replicating the Dynamic Island Animation in SwiftUI]]></title>
            <link>https://medium.com/better-programming/dynamic-island-animation-5869fbce41e6?source=rss-dac28fb3667b------2</link>
            <guid isPermaLink="false">https://medium.com/p/5869fbce41e6</guid>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[apple]]></category>
            <dc:creator><![CDATA[Aytuğ]]></dc:creator>
            <pubDate>Sun, 11 Sep 2022 18:13:07 GMT</pubDate>
            <atom:updated>2022-09-15T16:50:00.952Z</atom:updated>
            <content:encoded><![CDATA[<h4>Here’s a cool demo for fun!</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IrCDNVPLh7xTGdMPqOUqRw.jpeg" /><figcaption>Source: Apple</figcaption></figure><p>Announced at the recently concluded Apple event, the dynamic island enters our lives with the iPhone 14 Pro. It offers the possibility to show a new notification.</p><p>I got a chance to experience this with Xcode 14 release candidate version and want to share it with you. You will see how easily we can replicate it in SwiftUI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*uqSKC8etgr0W_wCG6yGMgQ.gif" /></figure><p>When we press a button, we will start the dynamic island animation. We’re going to show it for a while and put it back on.</p><p>Let’s create our content view and put a button in it. The button action post a notification.</p><p>Before that, we will need to create a notification model.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2587de51ae0a27df9051f8b382e09313/href">https://medium.com/media/2587de51ae0a27df9051f8b382e09313/href</a></iframe><p>In order to show the view on(in?) dynamic island, we need to ignore the safe area.</p><p>Let’s call this view NotificationView and put it in GeometryReader as this view will have a flexible size. Then let’s ignore the safe area.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8e3d22e8909e6b45141227a4e7395113/href">https://medium.com/media/8e3d22e8909e6b45141227a4e7395113/href</a></iframe><p>The dynamic island has 11-pixel top padding. Its width is 126 and its height is 37.33.</p><p>So we’re going to put a view behind the notch. We will enlarge it with animation.</p><p>Since it is a demo, we will change the size of the view by keeping a state in this view. On receiving a notification we will animate the view and set the notification.</p><p>Also, we will set isExpanded equal to true.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/df03e3e0197a427fa1ef37bc78d62751/href">https://medium.com/media/df03e3e0197a427fa1ef37bc78d62751/href</a></iframe><p>When we press the button, we can see the animation we made for the dynamic island.</p><p>Now we can draw the view we want.</p><p>We can trigger and send notifications whenever we want.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*V1mT4d9R2qmqReSLN3sbbg.gif" /></figure><p>If we want to be sure whether the device has a dynamic island or not, we need to write ourselves an extension.</p><p>Apple has not yet released such an extension. I guess iOS 16.1 will do that.</p><p>For now, we can provide this control over the device name:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3efb3fe1810ca2d4049b1b7687ec324e/href">https://medium.com/media/3efb3fe1810ca2d4049b1b7687ec324e/href</a></iframe><p>Animating a dynamic island seems to be no different from a normal view animation. We’re all set.</p><p>We can develop the size and appearance we want. Plus what we did on the dynamic island looks aesthetic pleasing in apps for the end-user.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5869fbce41e6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/dynamic-island-animation-5869fbce41e6">Replicating the Dynamic Island Animation in SwiftUI</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Make UI Testing possible with TYGenerator]]></title>
            <link>https://medium.com/trendyol-tech/make-ui-testing-possible-with-tygenerator-c3654425d782?source=rss-dac28fb3667b------2</link>
            <guid isPermaLink="false">https://medium.com/p/c3654425d782</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[ui-testing]]></category>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[test]]></category>
            <dc:creator><![CDATA[Aytuğ]]></dc:creator>
            <pubDate>Tue, 09 Nov 2021 07:06:34 GMT</pubDate>
            <atom:updated>2021-11-09T07:06:34.693Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rzk5iNLunAAC-QYnu229CQ.jpeg" /></figure><p>UI testing has become an important part of our testing phase. It gives great advantages in terms of both automation and speed. However, to obtain these advantages adjusting unique accessibility identifiers for each element and preparing page object codes for them is one of the repetitive and hardest parts of this job. This really wastes a lot of time make UI testable for each element of each page.</p><p>In this article, I will talk about TYGenerator makes our views UI testable and automatically generate the necessary page codes for the Trendyol iOS team.. But first, I am sharing the article explaining how we write UI test. It would be great if you read this first.</p><p><a href="https://medium.com/trendyol-tech/how-to-make-ios-ui-testing-fast-and-reliable-6f572a0955f2">How to Make iOS UI Testing fast and reliable</a></p><p>We have been generating codes to make the UI testable. How? Let me introduce you the <a href="https://developer.apple.com/documentation/xcodekit/creating_a_source_editor_extension#overview">XCode Source Editor Extension</a>.</p><blockquote>You build extensions to the source editor in Xcode using XcodeKit. Source editor extensions can read and modify the contents of a source file, as well as read and modify the current text selection within the editor.</blockquote><p>Using the Xcode Source Editor Extension, we read the codes of our view controller, view, cell classes. By parsing these codes, we determine the class name, what kind of class it is(cell or view controller) and the UI elements used in class. Thanks to the data we obtained after the read codes, we make the elements UI testable and at the same time automatically generate the UI test class of class we are parsing.</p><h4>Making View Controller UI Testable</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*r3gPAkEi4WWRro1Y4NsCEw.gif" /><figcaption>For View Controller Class</figcaption></figure><h4>Making Cell UI Testable</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*CrlSx0u_llqhnSWiuMO0-A.gif" /><figcaption>For View Cell Class</figcaption></figure><p>Let’s take a look at the implementation of this extensions. As seen in the gifs, we have 4 extensions.</p><ul><li>Generate Accessibility Identifiers</li><li>Generate All ( this generate accessibility identifiers and UI testable page class)</li><li>Generate Mark</li><li>Sort Import</li></ul><p>Today we have 4 extension. But tomorrow it could be 10 or 20. We used chain of responsibility pattern to manage this. You can read about <a href="https://medium.com/trendyol-tech/handle-deep-linking-with-chain-of-responsibility-pattern-815902a9dc50">chain of responsibility pattern</a> by <a href="https://ahmetkeskin.medium.com/">Ahmet Keskin</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/98606b03151afa025385983c8a501c74/href">https://medium.com/media/98606b03151afa025385983c8a501c74/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/165a6c77d98f044901db07200f5d10ac/href">https://medium.com/media/165a6c77d98f044901db07200f5d10ac/href</a></iframe><p>Thanks to GenerateEngine, the selected extension is determined with isSatisfied and necessary action is taken with execute.</p><p>Let’s take a look at the UITestablePageGenerator, which is the generable item we’re really interested in. This is the class that does all our UI test preparations.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bf465e2decec1a3ebb89dc0fc0ccfb0c/href">https://medium.com/media/bf465e2decec1a3ebb89dc0fc0ccfb0c/href</a></iframe><p>Of course, I will not explain each method. Actual event happens “execute()” method. Here we do 3 main operations.</p><h4>conformAccessibilityIdentifiableToView</h4><p>This method import AccessibilityKit and conform AccessibilityIdentifiable to the view interface.</p><h4>conformUITestablePageToView</h4><p>This method makes UI elements testable by writing an extension conforming the UITestablePage.</p><h4>generateUIElementClass</h4><p>This method generates the actual class that checks each element on the page.</p><p>Each method is linked to each other. That’s why we make sure that the previous operation was successful by using an optional chain. If you want to take a look, you can find extension’s source codes <a href="https://github.com/aniltaskiran/LazyXcode/tree/master/AccessibilityGenerator">here</a>.</p><h3>Conclusion</h3><p>As you can see, we read and modified the codes by adapting them to own UI test structure. Considering our classes are bigger and we have 100s of view classes, this approach has saved us invaluable time. We always continue to look for new ways and keep our aproach updated. Thank you very much for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c3654425d782" width="1" height="1" alt=""><hr><p><a href="https://medium.com/trendyol-tech/make-ui-testing-possible-with-tygenerator-c3654425d782">Make UI Testing possible with TYGenerator</a> was originally published in <a href="https://medium.com/trendyol-tech">Trendyol Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Swift Unit Test Automation]]></title>
            <link>https://medium.com/kodluyoruz/swift-unit-test-automation-4b80bf537bf6?source=rss-dac28fb3667b------2</link>
            <guid isPermaLink="false">https://medium.com/p/4b80bf537bf6</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[test-automation]]></category>
            <category><![CDATA[unit-testing]]></category>
            <category><![CDATA[continuous-integration]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Aytuğ]]></dc:creator>
            <pubDate>Sun, 26 Sep 2021 07:56:00 GMT</pubDate>
            <atom:updated>2021-09-26T07:56:00.900Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tjH1PBr8bGg7FvezfGslCw.png" /></figure><p>Let’s say you have multiple packages with unit tests. We don’t like to test these packages one by one. So how can we test it collectively and see the results? <br>We encountered such a case in Kodluyoruz &amp; Trendyol iOS Bootcamp 🚀. We are solving algorithm questions in <a href="https://exercism.io/">exercism.io</a>. We tried to find a solution so that the assistants could check whether it passed the tests more easily.</p><blockquote>Exercism aims to provide opportunity for people of <strong>all backgrounds</strong> by helping them develop their programming skills through practice and mentorship. We provide thousands of exercises spread across over 50 language tracks, and offer both <strong>automated and human mentoring.</strong></blockquote><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FCmFMWpEa4IFtS%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FCmFMWpEa4IFtS%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FCmFMWpEa4IFtS%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="270" frameborder="0" scrolling="no"><a href="https://medium.com/media/c454fcb043bffa057050b5535e5172c1/href">https://medium.com/media/c454fcb043bffa057050b5535e5172c1/href</a></iframe><p>We think of <strong>github actions</strong>. Here we could run tests for each package by running terminal commands. But instead of the terminal outputs of the tests, it would be better if we could only see what percentage of the tests we passed and which package failed the test. So I had to write a script that can be run in github action.</p><p>I coded a <strong>python script</strong> that writes terminal level scripts and tests for each package. Script handle the terminal outputs, it shows;</p><ul><li>🚀 Total swift packages count,</li><li>🚀 Total unit test count,</li><li>🚀 Compiling errors,</li><li>🚀 Failed tests count,</li><li>🚀 Which packages encountered errors,</li><li>🚀 Average test success results.</li></ul><h4>So how do we run this script in our repository?</h4><p>We need to <strong>set up a workflow</strong> in actions section on your repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/556/1*Op6_HZ7yk-TSM2E8zh7B2Q.png" /></figure><p>Github provide a standard main.yml file. We <strong>change main.yml</strong> file like this.</p><pre>name: CI<br> on:<br>   push:<br>     branches: [ main ]<br>     <br> jobs:<br>   build:<br>     runs-on: ubuntu-latest<br>     steps:<br>       # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it<br>       - uses: actions/checkout@v2<br>       # You can run script like this<br>       - name: Run Script<br>         run: python3 .script/main.py</pre><p>Great. Where is our main.py? <a href="https://github.com/aytugsevgi/Exercism-Solutions/blob/main/.script/main.py">Here, you can use from this repository.</a> <br>Also, if your package folders are not directly under your repo, you need to give which folder it is under as a parameter. If your package folders under <strong>“myFolder”</strong>. You need to do like this.</p><pre>- name: Run Script<br>         run: python3 .script/main.py <strong>myFolder1</strong></pre><p>When you push packages, output results will be like these.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/266/1*nqsk33F1PWaZds-CnSlWSA.png" /></figure><p>If your tests has any fail or compiling error.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/603/1*Y988UD_rGCMlOjA8KDFI2g.png" /></figure><p>The convenience of automating things is really great. This has been a very good experience for me.</p><p>Thank you for sharing this experience. See you 🚀🚀🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4b80bf537bf6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/kodluyoruz/swift-unit-test-automation-4b80bf537bf6">Swift Unit Test Automation</a> was originally published in <a href="https://medium.com/kodluyoruz">Kodluyoruz</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Swift Generic Types]]></title>
            <link>https://aytugsevgi.medium.com/swift-generic-types-2ce9ae5a4eca?source=rss-dac28fb3667b------2</link>
            <guid isPermaLink="false">https://medium.com/p/2ce9ae5a4eca</guid>
            <category><![CDATA[generics]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[clean-code]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Aytuğ]]></dc:creator>
            <pubDate>Sun, 09 May 2021 13:46:18 GMT</pubDate>
            <atom:updated>2021-05-09T13:46:18.499Z</atom:updated>
            <content:encoded><![CDATA[<p>Selamlar, Kodluyoruz &amp; Trendyol iOS Bootcamp eğitimim devam ederken daha önceden bilsek bile gerçek hayatta hiç uygulamadığım bir kavramdan söz etmek istiyorum. Bu eğitim ile artık “Yahu burası generic yapsam ne tatlı olur ama” diyorum. Bakalım kimmiş bu generic type.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-_up9854t5EZr16aUtoJTQ.jpeg" /></figure><h4>Generic Type Nedir?</h4><p>Generic type, yazdığınız kodun farklı tipler ile tekrar kullanılabilir haline getirmenizi sağlayan kavramdır. Temelde aynı işi yapan fakat bunu farklı tipler üzerinde gerçekleştiren kodlarınızı tek bir çatı altında toplamanıza olanak sağlar. Böylelikle kod tekrarını azaltır ve daha temiz çalışmış oluruz.</p><pre><strong>func</strong> sum(firstValue: Int, secondValue: Int) -&gt; Int {</pre><pre>    firstValue + secondValue</pre><pre>}</pre><pre><strong>func</strong> sum(firstValue: Double, secondValue: Double) -&gt; Double {</pre><pre>    firstValue + secondValue</pre><pre>}</pre><p>Basit bir örnek ile ele almak gerekirse, 2 adet sayıyı toplamak istiyoruz. Fakat bu sayıların tipi Int veya Double olabilir. Bu yüzden 2 farklı fonksiyon yazdık. Aynı işi yaptıklarına hemfikiriz. Yalnızca 2 fonksiyonun aldığı ve döndürdüğü değer tipi farklı. Bunu kodu daha güzel yazmak adına kendimiz bir tip uyduralım. Temsili ve anlamlı olması açından “Type” ın T’si bizim tipimiz olsun.</p><pre><strong>func</strong> sum&lt;T&gt;(firstValue: T, secondValue: T) -&gt; T {</pre><pre>    firstValue + secondValue</pre><pre>}</pre><p>Burada fonksiyon adımızdan hemen sonra kendi oluşturduğumuz tipi &lt;&gt; işaretleri arasına yazıyoruz. Artık kendi tipimizi bu fonksiyon için kullanabiliriz. Int, Double demek yerine genel bir isim verip T dedik. Artık dışarıdan gelen 2 tane aynı tipteki bir değeri toplayabilir ve tekrar o tipteki değeri döndürebiliriz.</p><p>Bir şeyi unuttuk değil mi? Her tipteki 2 değer toplanamaz. Benim ihtiyacım olan sayıları toplamaktı. Peki ben bu kısıtı nasıl verebilirim?</p><h4>Generic Type Constraints</h4><p>Generic type kullanırken tipimiz o kadar da genel olmasını istemiyorsak, belli özelliklere sahip tipler ile iş yapacaksak kısıtlama verme ihtiyacı duyarız. Aslında çok isteğe bağlı bir durum yok ortada. Kısıtlamak zorundayız çünkü o tipin o özelliğe sahip olup olmadığı bilmeden işlem yapamayız. Compiler ekranımıza hatayı fırlatır.</p><p>Örneğimiz için istediğimiz olay sayıları toplamaktı. O zaman generic tipimize kısıtımızı vermenin vakti geldi.</p><pre><strong>func</strong> sum&lt;T: Numeric&gt;(firstValue: T, secondValue: T) -&gt; T {</pre><pre>    firstValue + secondValue</pre><pre>}</pre><p>T tipimizin Numeric olacağını söylediğimizde aslında bunun toplanabilir bir değer olduğunu söyledik. Böylelikle numeric tipler üzerinde toplama işlemi yapan generic bir fonksiyon yazmış olduk.</p><p>Yahu ben bu generic tipleri sadece fonksiyonlarda mı tanımlayabilirim? Gelin bir class/struct yaratıp, class/struct’ta nasıl kullanacağımızı da görelim.</p><h4>Generic Type Class/Struct</h4><p>Generic class/struct’lar için Apple’ın kendi dokümanında vermiş olduğu örnek üzerinden ilerleyelim ve stack yapısını oluşturalım.</p><pre><strong>struct</strong> Stack&lt;T&gt; {</pre><pre><strong>    var</strong> items = [T]()</pre><pre><strong>    mutating</strong> <strong>func</strong> push(<strong>_</strong> item: T) {</pre><pre>        items.append(item)</pre><pre>    }</pre><pre><strong>    mutating</strong> <strong>func</strong> pop() -&gt; T {</pre><pre><strong>        return</strong> items.removeLast()</pre><pre>    }</pre><pre>}</pre><p>Yine fonksiyonların adının sonuna tanımladığımız gibi burada da struct adından hemen sonra &lt;&gt; içine T tipinde olacağını veriyoruz. Bu T tipinde bir array’in olduğu ve yine T tipindeki değeri array’ın sonuna eklediğimizi, sonundan değerini sildiğimiz fonksiyonları tanımlıyoruz. Farkettiniz mi, fonksiyonlara tekrardan T tipinde olacağını tanımlamamıza gerek yok. Zaten scope’larında T tipi mevcut olduğu için buna gerek yok.</p><p>Stack içinde String, Int veya herhangi bir tipte değeri saklayabiliriz.</p><pre><strong>var</strong> names = Stack&lt;String&gt;()</pre><pre>names.push(&quot;Bob&quot;)</pre><pre>names.pop()</pre><p>Anlaması kolay olması adına örnekleri basit tuttum. Peki gerçek hayatımızda bir iOS uygulama geliştirirken nerelerde kullanabileceğimiz hakkında birkaç örnek yapalım.</p><p>Verilen bir API’dan veri çekecek olalım. İçerisinde user verilerini barındırıyor. Bunun için bir yapı ve veriyi çekip yapımıza dönüştürecek bir fonksiyon yazalım.</p><pre><strong>struct</strong> User: Decodable {<br>    <strong>var</strong> userId: Int?<br>    <strong>let</strong> name: String?<br>    <strong>let</strong> lastname: String?<br>    <strong>let</strong> type: String?<br>}</pre><pre><strong>func</strong> fetchUsers(completion: <strong>@escaping</strong>(Result&lt;[User],ServiceError&gt;) -&gt; Void) {</pre><pre><strong>     let</strong> url = URL(string: Constant.baseUrl + “users/”)!<br>     <strong>var</strong> request = URLRequest(url: url)<br>     request.httpMethod = HttpMethod.get.rawValue<br>     <strong>let</strong> task = URLSession.shared.dataTask(with: url) { (data, <strong>_</strong>, <strong>_</strong>) <strong>in<br>         guard</strong> <strong>let</strong> data = data <strong>else</strong> {<br>             completion(.failure(.noDataAvailable))<br>             <strong>return<br>         </strong>}<br>         <strong>do</strong> {<br>             <strong>let</strong> decoder = JSONDecoder()<br>             <strong>let</strong> products = <strong>try</strong> decoder.decode([User].<strong>self</strong>, from: data)<br>             completion(.success(products))<br>        } <strong>catch</strong> {<br>            completion(.failure(.canNotProcessData))<br>        }<br>    }<br>    task.resume()<br>}</pre><p>Burada dikkat etmemiz gerek kısım User tipi.</p><pre><strong>let</strong> products = <strong>try</strong> decoder.decode([User].<strong>self</strong>, from: data)</pre><p>şeklinde gelen data’yı [User]’a decode ediyoruz. Her farklı modelimiz için yeni fetch fonksiyonları oluşturmak pek hoş olmayacaktır. 10 farklı modeliniz olsa bile tekrar eden bu kod blokları oldukça büyüyecek. Bunun yerine hayatımızı kurtaracak generic type’ları kullanalım.</p><pre><strong>func</strong> fetchData&lt;T: Decodable&gt;(type: T.Type, endPoint: String, completion: <strong>@escaping</strong>(Result&lt;[T],ServiceError&gt;) -&gt; Void) {</pre><pre><strong>    let</strong> url = URL(string: Constant.baseUrl + endPoint)!<br>    <strong>var</strong> request = URLRequest(url: url)<br>    request.httpMethod = HttpMethod.get.rawValue<br>    <strong>let</strong> task = URLSession.shared.dataTask(with: url) { (data, <strong>_</strong>, <strong>_</strong>) <strong>in<br>        guard</strong> <strong>let</strong> data = data <strong>else</strong> {<br>            completion(.failure(.noDataAvailable))<br>            <strong>return<br>        </strong>}<br>        <strong>do</strong> {<br>            <strong>let</strong> decoder = JSONDecoder()<br>            <strong>let</strong> result = <strong>try</strong> decoder.decode([T].<strong>self</strong>, from: data)<br>            completion(.success(result))<br>        } <strong>catch</strong> {<br>            completion(.failure(.canNotProcessData))<br>        }<br>    }<br>    task.resume()<br>}</pre><p>Artık dışarıdan T tipinde bir değer alacağız ve bu T tipi için datayı decode edeceğiz. Her bir model için aynı fonksiyonu kullanabilirim. Burada dikkat edilmesi gereken T nin Decodable olmasıdır.</p><p>Umarım anlaşılır olmuştur. Yeni öğrenen biri için hemen aklına gelen çözüm generic type olmayabilir. Projemde nereyi generic yapabilirim diye endişelenmeyin. Karşılaştığımız kod tekrarı, kodu temiz yazma kaygısı bizi ister istemez zaten generic işler yapmaya itecek. 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2ce9ae5a4eca" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Swift’de Hashable ve Equatable]]></title>
            <link>https://aytugsevgi.medium.com/swiftde-hashable-ve-equatable-cd102d6630f5?source=rss-dac28fb3667b------2</link>
            <guid isPermaLink="false">https://medium.com/p/cd102d6630f5</guid>
            <category><![CDATA[hashing]]></category>
            <category><![CDATA[equatable]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[object-oriented]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Aytuğ]]></dc:creator>
            <pubDate>Mon, 29 Mar 2021 14:02:36 GMT</pubDate>
            <atom:updated>2021-03-29T14:02:36.905Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/930/1*RyHP2LzI1owZkq-i3yuIgQ.jpeg" /></figure><p>Selamlar, bu yazımda sizlerle Swift dilinde <strong>Hashable</strong> ve <strong>Equatable</strong> protokollerine ne zaman ihtiyaç duyabileceğimizi, nasıl kodumuza uygulayabileceğimizi paylaşacağım. Yazılan örnek kodlar Stanford University School of Engineering, 2017 yılı güz döneminin CS193P kodlu Developing Apps for iOS dersinden alınmıştır.</p><p>Bir <strong>dictionary</strong> oluşturduğumuzda <strong>key </strong>tarafını <strong>Int</strong>, <strong>String</strong> gibi tanımlayabiliyoruz ki genellikle bu şekilde tanımlıyoruz. Peki kendi oluşturduğumuz bir sınıfı <strong>key</strong> olarak tanımlamak istersek,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/487/1*6CzENwE7slATGUdm5b38ww.png" /><figcaption>Dictionary&lt;Key: Hashable, Value&gt;</figcaption></figure><p>gibi bir hata almamız kaçınılmaz. Bu hata bizim oluşturduğumuz <strong>Card</strong> yapımızın <strong>Hashable</strong> olmadan <strong>key</strong> olarak tanımlayamayacağımızı söylüyor. Demek ki daha önceden <strong>key</strong> olarak tanımlamaya alıştığımız <strong>Int</strong>, <strong>String</strong> gibi yapılar <strong>Hashable</strong> imiş. Peki biz kendi yapımızı veya sınıfımızı <strong>Hashable</strong> yapabilir miyiz?</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2Fd4zHnLjdy48Cc%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fd4zHnLjdy48Cc%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2Fd4zHnLjdy48Cc%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="317" frameborder="0" scrolling="no"><a href="https://medium.com/media/a3fef25851aa8b4e1c41dab0d1d0e51a/href">https://medium.com/media/a3fef25851aa8b4e1c41dab0d1d0e51a/href</a></iframe><p>Önce mevcut <strong>Card</strong> yapımızı bir tanıyalım.</p><pre><strong>struct</strong> Card {</pre><pre><strong>    var</strong> isFaceUp = <strong>false</strong></pre><pre><strong>    var</strong> isMatched = <strong>false</strong></pre><pre><strong>    var</strong> identifier: Int</pre><pre><strong>    private</strong> <strong>static</strong> <strong>var</strong> identifierFactory = 0</pre><pre><strong>    private</strong> <strong>static</strong> <strong>func</strong> getUniqueIdentifier() -&gt; Int {</pre><pre>       identifierFactory += 1</pre><pre><strong>       return</strong> identifierFactory</pre><pre>    }</pre><pre><strong>    init</strong>() {</pre><pre><strong>       self</strong>.identifier = Card.getUniqueIdentifier()</pre><pre>    }</pre><pre>}</pre><p>Bu yapıya <strong>Hashable</strong> protokolünü verelim ve protokolün bize sağladığı fonksiyon ile yapımızı <strong>Hashable’a</strong> uygun hale getirelim.</p><pre><strong>struct</strong> Card: Hashable</pre><pre><strong>func</strong> hash(into hasher: <strong>inout</strong> Hasher) {</pre><pre>    hasher.combine(identifier)</pre><pre>}</pre><p>Bu kadar kısa bir işlem ile <strong>Dictionary’lerde</strong> kendi yapılarımızı <strong>key</strong> olarak verebileceğiz. Her seferinde <strong>key</strong> olarak yapılarımızın özelliklerini verip sonrasında aynı nesneyi çağırmak için listelerde arama yapmamıza gerek kalmadı.</p><p>Aynı şekilde işlerimizi <strong>struct</strong> ve <strong>class’lar</strong> ile halledebilmek için <strong>Hashable’ın</strong> da kalıtım aldığı <strong>Equatable</strong> protokolünü uygulayarak karşılaştırma işlemlerimizi çok daha kısa bir şekilde halledebileceğiz. Her iki yapıyı veya sınıfı karşılaştırırken tek tek <strong>property’lerini</strong> karşılaştırmak zorunda kalmayacağız. Bir kere tanımlayıp kurallarımızı verdikten sonra daha temiz bir şekilde kodumuzu yazmaya devam edebiliriz.</p><p>Zaten <strong>Hashable</strong>, <strong>Equatable’dan</strong> kalıtım aldığı için direkt olarak <strong>Card</strong> sınıfına <strong>Equatable</strong> protokolünün sağladığı fonksiyonu implement edebiliriz.</p><pre><strong>static</strong> <strong>func</strong> ==(lhs: Card, rhs: Card) -&gt; Bool {</pre><pre><strong>    return</strong> lhs.identifier == rhs.identifier</pre><pre>}</pre><p>Bizden doğal olarak <strong>Bool</strong> bir değer döndürmemiz bekleniyor. Yapımızdaki hangi <strong>property’lere</strong> göre eşitliğin sağlanacağını tanımlayarak eşitlik sorgularını nesnelerimiz üzerinden yapabiliriz. Örneğin;</p><pre>if firstCard.identifier == secondCard.identifier {<br>    //some codes<br>}</pre><p>yerine,</p><pre>if firstCard == secondCard {<br>   //some codes<br>}</pre><p>şeklinde kullanabiliriz. Özellikle 2 nesne eşitliği için birçok <strong>property</strong> kontrol edilecek durumlarda bu protokol hayatımızı daha kolay bir hale getiriyor.</p><p>Bu protokollerin getirdiği kolaylıkları sizlerle paylaşmaya çalıştım. İyi, kötü feedback’lerinizi esirgemeyin. Özellikle kötü feedback’leri 👻</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cd102d6630f5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flutter Web ve Azure Deployment]]></title>
            <link>https://aytugsevgi.medium.com/flutter-web-ve-azure-deployment-e319139fb65e?source=rss-dac28fb3667b------2</link>
            <guid isPermaLink="false">https://medium.com/p/e319139fb65e</guid>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[Aytuğ]]></dc:creator>
            <pubDate>Thu, 28 Jan 2021 13:48:03 GMT</pubDate>
            <atom:updated>2021-01-28T16:29:55.144Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*sTyA5Tzemy_DQ-2jvLk5RA.png" /></figure><p>Ah flutter, benim üzümlü kekim. Her şey Bulut Bilişim dersimizin final projesi ile başladı. “Online Examination System” konulu web sitesi yapmamız ve azure ortamında deploy etmemiz istemişti. Elinizin altında Flutter gibi güçlü bir geliştirme ortamı varken gidip bu ödev için .Net, React, Django veya Flask vs. geliştirmek istemezsiniz. Ben de bu motto ile yola çıktım.</p><p>Flutter ile geliştirdiğim kodu Azure ortamında nasıl deploy edebileceğimi gösteren herhangi bir doküman veya video bulamadım. O yüzden bu yazıyı yazmaya karar verdim.</p><p>Öncelikle kullandığınız paketlerin web için kurulumları varsa yapmaya dikkat edin. Örneğin flutter sevenlerin en çok kullandığı firebase için index dosyasına eklemeniz gereken bazı script tagleri bulunmaktadır.</p><p>Kodu yazdık, testimizi yaptık. Sıra geldi deploy etmeye. Web için build alarak başlayalım. Terminali açıp projemizin kök dizinine gidelim. Sonrasında,</p><pre>flutter web build</pre><p>Eğer bir sıkıntı ile karşılaşırsak önce mevcut kanalımızı kontrol etmekte fayda var. Şu an için flutter web stable değil. O yüzden beta kanalına geçiş yapmamız gerekiyor. Kanalımızı kontrol edelim.</p><pre>flutter channel</pre><p>Eğer beta’da değilsek geçiş yapalım.</p><pre>flutter channel beta<br>flutter upgrade<br>flutter config --enable-web<br>flutter web build</pre><p>Build işlemini tamamladıktan sonra github’a projemizi pushlayalım. Fakat öncesinde projemizdeki build klasörünün adını değiştirelim. Çünkü github’a bu halde pushlayınca build klasörünü pushlayamıyoruz. Adını “build2” olarak değiştirmemiz bile yeterli olacaktır.</p><p>Github ortamına build alınmış haldeki projemizi aktardıktan sonra Azure tarafına geçebiliriz. Portaldaki terminali açalım.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/261/1*eAbT1fqQc8oZni7BVsCywg.png" /><figcaption><a href="https://portal.azure.com/#home">https://portal.azure.com/#home</a></figcaption></figure><p>Github’a attığımız projemizi Azure ortamına klonlayalım.</p><pre>git clone &lt;your repository&gt;</pre><p>Şimdi projemizin build/web dizine gidelim ve deploy işlemimizi yapalım.</p><pre>az webapp up -g &lt;Your Group Name&gt; --sku F1 --name &quot;&lt;Project Name&gt;&quot; --location westeurope --html</pre><p>Örneğin;</p><pre>az webapp up -g WebAppResourceGroup --sku F1 --name &quot;awesomeapp&quot; --location westeurope --html</pre><p>Başka kaynaklarda sondaki “--html” kısmını göremeyebilirsiniz fakat bizim mutlaka bunu yazmamız gerekiyor. Yoksa deploy ederken hata almamız kaçınılmaz.</p><p>Artık Flutter ile yazdığınız proje web ortamında deploy edildi. Deploy edildikten sonra terminalde yazan link ile geliştirdiğiniz web sitesine ulaşabilirsiniz. Bol kodlu günler dileğiyle ❤</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e319139fb65e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>