<?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 Ceren on Medium]]></title>
        <description><![CDATA[Stories by Ceren on Medium]]></description>
        <link>https://medium.com/@cerengunnes?source=rss-4b6246117857------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*U9MxJmxLuvFOdYSE-1eYKQ.jpeg</url>
            <title>Stories by Ceren on Medium</title>
            <link>https://medium.com/@cerengunnes?source=rss-4b6246117857------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 15:27:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@cerengunnes/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[Higher Order Functions in Swift]]></title>
            <link>https://medium.com/@cerengunnes/higher-order-functions-in-swift-4d374e31a077?source=rss-4b6246117857------2</link>
            <guid isPermaLink="false">https://medium.com/p/4d374e31a077</guid>
            <category><![CDATA[higher-order-function]]></category>
            <category><![CDATA[function]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Ceren]]></dc:creator>
            <pubDate>Sun, 20 Oct 2024 17:38:40 GMT</pubDate>
            <atom:updated>2024-10-20T17:38:40.402Z</atom:updated>
            <content:encoded><![CDATA[<p>Hey there! 👋 In this article, I’ll walk you through some of the most popular higher-order functions in Swift. Let’s get started! 👩🏻‍💻</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3dMekC30a-PagaRJ" /><figcaption>Photo by <a href="https://unsplash.com/@sapegin?utm_source=medium&amp;utm_medium=referral">Artem Sapegin</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Higher-order functions in Swift are functions that take other functions as arguments or return them as results. They enable more flexible and reusable code by allowing functions to be passed around like variables. Common examples in Swift include <strong><em>map</em></strong>, <strong><em>filter</em></strong>, and <strong><em>reduce</em></strong>, which manipulate collections in a concise and functional way. Now, let’s take a closer look at five popular higher-order functions in Swift and see how they work!</p><h3><strong>1-) .map()</strong></h3><p>The map function in Swift is a higher-order function that transforms each element of a collection using a given closure. It returns a new array with the transformed values without modifying the original collection.</p><pre>let numbers = [1, 2, 3, 4, 5]<br>let doubledNumbers = numbers.map { $0 * 2 }<br>print(doubledNumbers) // Output: [2, 4, 6, 8, 10]</pre><h3>2-) .filter()</h3><p>The .filter() function in Swift is a higher-order function that helps you select elements from a collection based on a condition you provide. It returns a new array containing only the elements that satisfy the condition without modifying the original collection.</p><pre>let numbers = [1, 2, 3, 4, 5]<br>let evenNumbers = numbers.filter { $0 % 2 == 0 }<br>print(evenNumbers) // Output: [2, 4]</pre><h3>3-) .reduce()</h3><p>The .reduce() function in Swift is a higher-order function that combines all the elements of a collection into a single value by applying a closure that you provide. It takes an initial value and a closure that specifies how to combine the elements.</p><pre>let numbers = [1, 2, 3, 4, 5]<br>let sum = numbers.reduce(0) { $0 + $1 }<br>print(sum) // Output: 15</pre><h3>4-) .sorted()</h3><p>The .sorted() function in Swift is a higher-order function that returns a new array containing the elements of a collection in ascending order. It does not modify the original collection. You can also provide a custom sorting closure if you want to sort the elements in a specific way.</p><pre>let numbers = [5, 2, 3, 1, 4]<br>let sortedNumbers = numbers.sorted()<br>print(sortedNumbers) // Output: [1, 2, 3, 4, 5]</pre><h3>5-) .forEach()</h3><p>Iterates over each element of a collection and performs a specified action for each element. Unlike the other functions, it does not return a new collection. This function is frequently used in <strong>SwiftUI</strong> to loop over data structures and create views dynamically, such as in List or ForEach blocks, allowing developers to build UI components for each element in a collection.</p><pre>import SwiftUI<br><br>struct ContentView: View {<br>    let names = [&quot;Niall&quot;, &quot;Louis&quot;, &quot;Liam&quot;, &quot;Harry&quot;, &quot;Zack&quot;]<br>    <br>    var body: some View {<br>        VStack {<br>            ForEach(names, id: \.self) { name in<br>                Text(name)<br>            }<br>        }<br>    }<br>}</pre><p>Thanks for reading! I hope you found these examples helpful — keep practicing and soon these functions will become second nature. Happy coding! 😊</p><p>Resources:</p><p><a href="https://www.geeksforgeeks.org/higher-order-functions-in-swift/">https://www.geeksforgeeks.org/higher-order-functions-in-swift/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4d374e31a077" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[UserDefaults and SwiftUI’s @AppStorage]]></title>
            <link>https://medium.com/@cerengunnes/userdefaults-and-swiftuis-appstorage-19e0c76821f1?source=rss-4b6246117857------2</link>
            <guid isPermaLink="false">https://medium.com/p/19e0c76821f1</guid>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[userdefaults]]></category>
            <category><![CDATA[data-storage]]></category>
            <category><![CDATA[ios-development]]></category>
            <dc:creator><![CDATA[Ceren]]></dc:creator>
            <pubDate>Sun, 13 Oct 2024 13:49:14 GMT</pubDate>
            <atom:updated>2024-10-13T13:49:14.691Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello everyone, hope you’re having a good day. In this article I’ll explain UserDefaults and @AppStorage property wrapper in SwiftUI, highlight the differences between them and provide detailed information. Let’s dive straight in! 🧚‍♀️</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*fOpe6rmHxNSHN4ux" /><figcaption>Photo by <a href="https://unsplash.com/@wasdrew?utm_source=medium&amp;utm_medium=referral">Andras Vas</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3><strong>User Defaults</strong></h3><p>It allows you to store small pieces of data, such as user’s choice of theme, notification preferences, language settings, whether they’ve seen the onboarding pages, or whether the user is logged in, etc.<br>Keep in mind that you should not use <strong>UserDefaults</strong> to store any sensitive data. If you need to store sensitive information, consider using a proper database instead, as data stored in <strong>UserDefaults</strong> can be easily accessed and is not encrypted.</p><p>Data is stored as key-value pairs in UserDefaults, and under the hood, it’s saved in a plist (Property List) file, which is an XML-based format. However, when using UserDefaults, you interact with it like a dictionary.</p><p>Let’s see an example of the usage of user defaults:</p><pre>import SwiftUI<br><br>struct ContentView: View {<br>    @State private var backgroundColor: Color = .green<br>    let defaults = UserDefaults.standard<br>    <br>    var body: some View {<br>        Button(&quot;Change Background Color&quot;) {<br>            changeBackgroundColor()<br>        }<br>        .padding()<br>        .background(backgroundColor)<br>        .clipShape(Capsule())<br>        .onAppear {<br>            loadBackgroundColor()<br>        }<br>    }<br>    <br>    func changeBackgroundColor() {<br>        backgroundColor = backgroundColor == .green ? .orange : .green<br>        saveBackgroundColor()<br>    }<br>    <br>    func saveBackgroundColor() {<br>        let colorString = backgroundColor == .green ? &quot;green&quot; : &quot;orange&quot;<br>        defaults.set(colorString, forKey: &quot;backgroundColor&quot;)<br>    }<br>    <br>    func loadBackgroundColor() {<br>        if let colorString = defaults.string(forKey: &quot;backgroundColor&quot;) {<br>            backgroundColor = colorString == &quot;green&quot; ? .green : .orange<br>        }<br>    }<br>}</pre><p>In this example, we first created a state variable to store our button’s background color and a singleton called defaults, which helps us interact with <strong>UserDefaults</strong>. When user taps on the button, it changes the background color of the button and saves the changed color to the user defaults.</p><blockquote>A <strong>singleton</strong> allows us to create a single instance of the related class, and by using that singleton, we avoid the need to create the same instance repeatedly. It is instantiated once and used throughout the project. In the end, this helps reduce code repetition and optimize memory usage.</blockquote><h3>@AppStorage Property Wrapper in SwiftUI</h3><p>As you may know, SwiftUI works with property wrappers, one of them is the @AppStorage property wrapper. It allows us to store user data just like in User Defaults but it can be only used in SwiftUI since UIKit does not work with property wrappers.</p><p>You can store data types such as <strong>Int</strong>, <strong>Double</strong>, <strong>Float</strong>, <strong>String</strong>, <strong>Data</strong>, and <strong>URL</strong>. It is suitable for small pieces of data, similar to <strong>UserDefaults</strong>. In fact, the @AppStorage property wrapper saves data to <strong>UserDefaults</strong>, but it utilizes a property wrapper because that’s how SwiftUI operates.</p><p>Let’s do the same example but now use the @AppStorage property wrapper:</p><pre>import SwiftUI<br><br>struct ContentView: View {<br>    @AppStorage(&quot;backgroundColor&quot;) private var backgroundColor: String = &quot;green&quot;<br><br>    var body: some View {<br>        Button(&quot;Change Background Color&quot;) {<br>            changeBackgroundColor()<br>        }<br>        .padding()<br>        .background(getColor(from: backgroundColor))<br>        .clipShape(Capsule())<br>    }<br>    <br>    func changeBackgroundColor() {<br>        backgroundColor = (backgroundColor == &quot;green&quot;) ? &quot;orange&quot; : &quot;green&quot;<br>    }<br>    <br>    private func getColor(from colorString: String) -&gt; Color {<br>          switch colorString {<br>          case &quot;green&quot;:<br>              return .green<br>          case &quot;orange&quot;:<br>              return .orange<br>          default:<br>              return .green<br>          }<br>      }<br>}</pre><p>In this example, we didn’t have to load or save the user’s preferred color choice because the @AppStorage property does the job for us. It automatically updates the property from <strong>UserDefaults</strong> whenever there is a change, ensuring that the user&#39;s preference is consistently reflected in the app&#39;s interface. This functionality not only simplifies our code but also enhances the user experience by making it seamless and efficient. As a result, we can focus on other aspects of our app without the overhead of manually managing the storage and retrieval of simple user settings.</p><p>That was it for the article, thank you for reading. I hope you found the information helpful! ✨</p><p><strong>Resources:</strong></p><p><a href="https://developer.apple.com/documentation/swiftui/appstorage">https://developer.apple.com/documentation/swiftui/appstorage</a></p><p><a href="https://www.hackingwithswift.com/quick-start/swiftui/what-is-the-appstorage-property-wrapper">https://www.hackingwithswift.com/quick-start/swiftui/what-is-the-appstorage-property-wrapper</a></p><p><a href="https://www.hackingwithswift.com/example-code/system/how-to-save-user-settings-using-userdefaults">https://www.hackingwithswift.com/example-code/system/how-to-save-user-settings-using-userdefaults</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=19e0c76821f1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Swift’s Closures]]></title>
            <link>https://medium.com/@cerengunnes/swifts-closures-2c7b088a458d?source=rss-4b6246117857------2</link>
            <guid isPermaLink="false">https://medium.com/p/2c7b088a458d</guid>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios-development]]></category>
            <category><![CDATA[closures-functions]]></category>
            <dc:creator><![CDATA[Ceren]]></dc:creator>
            <pubDate>Sun, 06 Oct 2024 13:50:15 GMT</pubDate>
            <atom:updated>2024-10-06T13:50:15.735Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, I’ll explain closures in detail, give code examples and hopefully help someone to understand usage of closures in Swift. Let’s go! 🏃🏻‍♀️💨</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*y2cc45TutTvQL3lT" /><figcaption>Photo by <a href="https://unsplash.com/@cgower?utm_source=medium&amp;utm_medium=referral">Christopher Gower</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote><strong>What is a closure?</strong></blockquote><p>Closures are self-contained blocks of functionality that can be passed around and used in your code. They are sometimes described as ‘anonymous functions’, meaning they don’t have names yet still perform operations just like regular functions. Closures can also capture the variables or constants in their surrounding context, but I’ll explain that in another article, as it deserves a detailed explanation on its own. Let’s dive into the examples to see what they actually do. ✨</p><p>Let’s begin with writing a simple function, and afterwards, we’ll change that function into a closure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b-9fem5AZU_oUiUmNGRiNg.png" /></figure><p>We have a function called <strong>addTwoNumbers</strong> that takes 2 parameters called <strong><em>firstNumber</em></strong> and <strong><em>secondNumber</em></strong>, both of type Int, and returns their sum.</p><blockquote>We called the function without using the internal parameter names because of the underscore, which allows us to omit the parameter labels. For more information check out -&gt; <a href="https://docs.swift.org/swift-book/documentation/the-swift-programming-language/functions/">https://docs.swift.org/swift-book/documentation/the-swift-programming-language/functions/</a></blockquote><blockquote>We also omitted the return keyword because if your function contains only one line of code that produces the output, you can skip the return, for more information -&gt; <a href="https://www.hackingwithswift.com/swift/5.1/implicit-returns">https://www.hackingwithswift.com/swift/5.1/implicit-returns</a></blockquote><p>Now let’s see this function’s ✨closure✨ version:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sy9Ks4MRrkVGz2GhzHqvPQ.png" /></figure><p>Since closures can be assigned to constants or variables, I first created a constant called <strong><em>sum</em></strong>. I then specified the type of the constant, which is a closure that takes two <strong>integer</strong> parameters and returns an <strong>Int</strong>. The curly braces indicate the beginning of the closure, followed by the parameters <strong><em>firstNumber</em></strong><em> </em>and <strong><em>secondNumber</em></strong>. After that comes the in keyword, which marks the start of the closure’s body.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/126/1*u8K91tPLOLptCPom6q2Gyw.png" /><figcaption>The result of them both</figcaption></figure><p>The syntax may look a little intimidating at first, but I assure you it will get easier as you get used to it, and it’s also really handy! Let’s go through another example, this time I’ll show you a usage of closure on a really common code block.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FxlThnaFL6BzP2X8Kt0uDA.png" /></figure><p>This code block is common if you’re fetching some sort of data from the server, basically what it does is a URL is created, and a URLSession data task is initiated to fetch data from the server. The <strong><em>task </em></strong>constant assigned to a closure that takes data, response and error parameters. Below their types are shown:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*Yy1fY2iMfqUyNQFe2VVmXw.png" /></figure><p>A <strong><em>completionHandler</em></strong> is a closure passed into a function to be executed after the function completes its task, typically asynchronously. It allows you to define what should happen with the results (such as data or errors) once the task, like a network request, is finished. By using a <strong><em>completionHandler</em></strong>, you can handle the outcome of the task (success or failure) outside of the function itself.</p><p>I’ll give you another example to demonstrate the usage of closures. In SwiftUI, closures are very common, especially in the form of trailing closure syntax. Let me show you an example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*A1Wp0CQ5TG5KrsTYMEzuyQ.png" /></figure><p>This is the button component syntax in SwiftUI, <strong><em>Save</em> </strong>text is the title of the button, action parameter takes a closure that takes no parameters and returns nothing. If you go into the <strong><em>() -&gt; Void</em></strong> part and click enter it’ll look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/598/1*4HLVilOh9aROGpbfFbrZKA.png" /><figcaption>I added the print statement inside of the action.</figcaption></figure><p>In this example, the { } marks the body of the action closure where you define the action that will be executed when the button is pressed. Specifically, when the &quot;Save&quot; button is clicked, it prints the message to the console. This is an example of trailing closure syntax, commonly used in SwiftUI to define actions for UI elements like buttons.</p><p>This concludes the article; I hope you found it beneficial. While closures can perform all the functions of a regular function, they often lead to clearer code in certain situations. However, you can certainly use functions exclusively or vice versa, as they can be used interchangeably as needed. I hope you enjoyed reading, and I look forward to seeing you in my future articles. Have a great day! 👋 🚀</p><p><strong>Resources:</strong></p><p><a href="https://docs.swift.org/swift-book/documentation/the-swift-programming-language/closures">https://docs.swift.org/swift-book/documentation/the-swift-programming-language/closures</a></p><p><a href="https://www.hackingwithswift.com/read/0/21/closures">https://www.hackingwithswift.com/read/0/21/closures</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2c7b088a458d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Localization in SwiftUI]]></title>
            <link>https://medium.com/@cerengunnes/localization-in-swiftui-2f50887f7a12?source=rss-4b6246117857------2</link>
            <guid isPermaLink="false">https://medium.com/p/2f50887f7a12</guid>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[localization]]></category>
            <category><![CDATA[language]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swiftui]]></category>
            <dc:creator><![CDATA[Ceren]]></dc:creator>
            <pubDate>Sun, 29 Sep 2024 14:27:12 GMT</pubDate>
            <atom:updated>2024-09-29T14:33:07.704Z</atom:updated>
            <content:encoded><![CDATA[<p>Hey everyone! I’ll explain localization with a small project using Apple’s SwiftUI framework. Hope you’ll benefit from it. Enjoy! 🤗</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zfsuSoijkZLboMyh" /><figcaption>Photo by <a href="https://unsplash.com/@altumcode?utm_source=medium&amp;utm_medium=referral">AltumCode</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>First I create an example UI, I choose a menu to localize from English to German. (Mind you, you could get hungry afterwards 😋 🍽️)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1010/1*nyKF8VYYMC_auwz4xnBatw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1010/1*rICssQOgYeaYccuxC76tVg.png" /><figcaption>Menu example in English</figcaption></figure><p><strong>Step 1</strong>: command + n -&gt; iOS -&gt; String Catalog -&gt; next -&gt; create</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dc2ei6XMP4gKc_fvC0wkCw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Rnk1yJq7KJGM58BwbTJJNA.png" /></figure><p><strong>Step 2: </strong>Add values that you want to localize. In my case it’ll look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xbWvPxObw2cb1CzwpWX_EQ.png" /></figure><p><strong>Step 3: </strong>Now let’s click on the + button at the bottom left and add German.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/492/1*2uhSOUyhccq_plNe5YjGmQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DxvhPMs8cRQVg1mfqYxU4A.png" /></figure><p><strong>Step 4: </strong>Fill out the German(de) section to adapt to German. You could also change the String Catalog look to Source Code file look and add the translated strings in the same way.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XWDpJJN5DHhilBUMCAPctQ.png" /></figure><p><strong>Step 5: </strong>Then I added 2 functions to format prices correctly and provide multi-language support.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o_U7nZsaSyurZzHGu9_Jcg.png" /></figure><p><strong>Step 6: </strong>For the final step I’ll run the app in German. To do that: LocalizationExample -&gt; Edit Scheme -&gt; Options -&gt; App Language -&gt; German</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*T9T_-Qq6Fs1lZCiZVchh8g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*he7U1Y3vCLlnmlAuVwMq1Q.png" /></figure><p>Let’s see the finished look! 🚀✨</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1010/1*NgLcM_4wf3MIvo7Tt8Nrcg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1010/1*Hjbq75_VD34avMMhPJyfnw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2f50887f7a12" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[View Controller Yaşam Döngüsü]]></title>
            <link>https://medium.com/@cerengunnes/view-controller-ya%C5%9Fam-d%C3%B6ng%C3%BCs%C3%BC-d87ec01386fa?source=rss-4b6246117857------2</link>
            <guid isPermaLink="false">https://medium.com/p/d87ec01386fa</guid>
            <category><![CDATA[bootcamp]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios-development]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[uikit]]></category>
            <dc:creator><![CDATA[Ceren]]></dc:creator>
            <pubDate>Sun, 13 Aug 2023 10:15:12 GMT</pubDate>
            <atom:updated>2023-10-24T14:51:13.810Z</atom:updated>
            <content:encoded><![CDATA[<p>Merhaba! 👋 Bu yazımda View Controller’ın yaşam döngü metodlarından bahsedeceğim. O zaman başlayalım, keyifli okumalar! 🤓📚</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gqf8ruJoMJACTIeK" /><figcaption>Photo by <a href="https://unsplash.com/@christinhumephoto?utm_source=medium&amp;utm_medium=referral">Christin Hume</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Uygulamalarda çalışan her bir ekranın bir yaşam döngüsü vardır. Bu yaşam döngüsünde çalışan birtakım metodlar bulunmaktadır. Şimdi teker teker bu metodlara bakalım. ⬇️</p><h4>1- init()</h4><p>init(initializer) metodu bir sınıf, struct ya da enum’dan bir nesne oluşturulduğu zaman ilk çağrılan metoddur. Bu metod o nesnenin belleğe çıkmasını sağlar. Bu işlem o yapıdaki property’leri kullanarak bir başlangıç değeri atamayı ve kullanılmadan önce gerekli işlemlerin yapılmasını sağlar.</p><h4>2- loadView()</h4><p>Eğer View Controller’ın nib dosyası varsa, bu metod view’u nib dosyasından yükler. Fakat eğer nib dosyası yoksa yeni bir UIView instance’ı yaratılır. View’ları yaratmak için ve View Controller’ın initialization işlemi için Interface Builder kullanılmışsa, bu metod override edilmemelidir.</p><h4><strong>3- viewDidLoad</strong>()</h4><p>Bu metod View Controller view’u ilk yüklendiğinde tetiklenir ve uygulama yüklendiğinde yalnızca bir defa çalışır. Bir defa çağrıldıktan sonra artık belleğe alındığı için, yeni bir View Controller instance’ı oluşturulana kadar tekrar çağrılmaz.</p><p><strong>viewDidLoad()</strong> metodu View Controller’ın view’u yüklemesi için nib dosyası kullanmasına ya da programatik UI kullanılmasına bakılmaksızın tetiklenir. Uygulama açılır açılmaz olmasını istediğimiz işlemleri burada gerçekleştirebiliriz.</p><h4>4- viewWillAppear()</h4><p>Bu metod View Controller’ın view’u ekranda görünmeden hemen önce çalışır ve ekran her açılmadan önce tetiklenir. View ekranda görünmeden hemen önce herhangi bir özelleştirme yapılacaksa bu metod override edilebilir.</p><h4>5- viewDidAppear()</h4><p>Bu metod View Controller ekranda göründükten hemen sonra tetiklenir ve ekran her göründüğünde tetiklenir. View ekranda göründükten sonra herhangi bir özelleştirme yapılacaksa bu metod override edilebilir.</p><h4>6- viewWillDisappear()</h4><p>Bu metod View Controller ekrandan kaybolmadan hemen önce çalışır. Örneğin bir View Controller’dan diğer view controller’a geçtiğimiz zaman bu metod tetiklenir.</p><h4>7- viewDidDisappear()</h4><p>Bu metod View Controller ekrandan kaybolduktan hemen sonra çalışır. Örneğin View Controller’a ait widget’ların ekranda kalıp kalmayacağına karar verileceği zaman bu metod kullanılabilir.</p><h4>8- deinit()</h4><p>Swift artık ihtiyaç olmaması halinde instance’ları hafızadan siler. deinit() metodu oluşturulan nesne bellekten silinmeden önce çağrılır. Swift hafıza yönetimini <em>Automatic Reference Counting</em> (ARC)adlı bir sistemle kontrol eder. Kısaca açıklayacak olursak, bu sistem aynı sınıftan üretilen referans sayısını tutar, bu sayı 0&#39;a indiğinde ise o sınıftan oluşturulan instance’ı yok eder. deinit() metodu parametre almaz ve her class’ın yalnızca 1 tane deinit() metodu vardır.</p><p>Şimdi bu metodların çalışma sırasının minik bir demosunu görelim:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/296/1*9U_PevajUa4wiSteSC_qiQ.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1016/1*BGIxnUzEV7QyoIxDAwzdyQ.png" /></figure><p>Bu yazımda View Controller’in yaşam döngüsünden bahsettim. Bir dahaki yazımda görüşmek üzere! Hoşçakalın. 👋</p><h4>Kaynakça:</h4><p><a href="https://developer.apple.com/documentation/uikit/uiviewcontroller/">https://developer.apple.com/documentation/uikit/uiviewcontroller/</a></p><ul><li><a href="https://www.mobilhanem.com/ios-view-controller-kullanimi-ve-view-controller-yasam-dongusu/">iOS View Controller Kullanımı ve View Controller Yaşam Döngüsü</a></li><li><a href="https://gelecegiyazanlar.turkcell.com.tr/konu/egitim/swift-ile-ios-programlama-101/viewcontroller-yasam-dongusu">ViewController Yaşam Döngüsü</a></li><li><a href="https://docs.swift.org/swift-book/documentation/the-swift-programming-language/deinitialization/">Documentation</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d87ec01386fa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Apple Music UICollectionView Example]]></title>
            <link>https://medium.com/@cerengunnes/apple-music-uicollectionview-example-c570d888be6d?source=rss-4b6246117857------2</link>
            <guid isPermaLink="false">https://medium.com/p/c570d888be6d</guid>
            <category><![CDATA[uikit]]></category>
            <category><![CDATA[apple-music]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[apple]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <dc:creator><![CDATA[Ceren]]></dc:creator>
            <pubDate>Mon, 30 Jan 2023 15:27:35 GMT</pubDate>
            <atom:updated>2023-01-30T15:58:48.969Z</atom:updated>
            <content:encoded><![CDATA[<p>Hey everyone! 👋 In today’s article, I’m going to make a clone of Apple Music’s search page. So, let’s get started!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vJq4qaLty2NXjgtc" /><figcaption>Photo by <a href="https://unsplash.com/@clemhlrdt?utm_source=medium&amp;utm_medium=referral">Clément Hélardot</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>First I created a project, named it AppleMusicSearchClone and set the interface to storyboard.</p><p>1- Embed the ViewController to a navigation bar.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g8SNoPiyEnC73cEqWLQ7UQ.png" /></figure><p>2- Select navigation bar, and go to attributes inspector, tick off ‘Prefers Large Titles’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bC7_SsXPKMiVIv-WRg0BdA.png" /></figure><p>3- Select the View Controller and give it the title of ‘Search’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F2AlFa11Ml7qyZoiBIUJZw.png" /></figure><p>4- Drag a SearchBar from the Objects Library to the ViewController, and pin it 0 from left, right and top.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sUAyoDirMKhemDi6jiO4FA.png" /></figure><p>5- Drag a label from Object Library, give the font size 30 and font style bold, and pin 10 from the left and 10 from the top.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m3pDgFjO6A5TDBEQ6r4isA.png" /></figure><p>6- Drag a Collection View from the Objects Library to the ViewController, and pin all sides to 0.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mWeuYiWaCloVQkPms_RIUQ.png" /></figure><p>7- Give collection view cell an identifier called ‘collectionCell’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8sHeAgOEkhEvQVTUkNCLRQ.png" /></figure><p>8- Drag an image view into the collection cell and pin 0 from left, right, top and bottom and give the width of 128 and height of 128.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I3An--13IRDlZnVt3Ijn-g.png" /></figure><p>9- Drag a label into the UIImageView and give the constraints of 10 from the left and 10 from the bottom, and set its font style to semibold.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AewsIxy0a_assyG6QwYRMg.png" /></figure><p>10- Add some images that I find from Google.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RDyDkt50WLgU3Zirkqg5kw.png" /></figure><p>11- Create a class Called Music that has 2 properties.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YvCxeh7SZzTTJ0V2WFy9vw.png" /></figure><p>12- Create a UICollectionViewCell that’s called MusicCollectionViewCell and connect the image and label with the created class.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JPYG8W4kAg8niB4jJMXqNg.png" /></figure><p>13- To see how it looks, I give it an image and write something to the label. And also changed label’s color to white.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f_8WPtaRcJlJjArpBoEE3A.png" /></figure><p>14- In ViewController.swift file, create an array that contains Music objects.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sZnkUalt9X1-3jUCQ1yz3g.png" /></figure><p>15- Now let’s connect the CollectionView to the ViewController, and add the delegate methods.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eozqidL2q5U94wqdc39wBA.png" /></figure><p>16- Give CollectionView some constraints:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LKE31WngbzVju37gnZZ2Cg.png" /></figure><p>17- Give cell a radius:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/596/1*I34r11oW3utXvLyLYHJi1w.png" /></figure><p>18- Now, I’m going to embed this ViewController to a Tabbar, and give some styling inside of the ViewController.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_vGf88H_3v1FAewB1_z90g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cc3nnc-msPUTmTGk35LAMA.png" /></figure><p>And finally, it’ll look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/296/1*WIjtIsy_zZmiU9n9z6SA6Q.gif" /></figure><p>That was it ! Thanks for taking time to read, hope you enjoyed! Have a good day. 👋</p><p>Source code:</p><p><a href="https://github.com/cerennnnn/AppleMusicSearchPageClone">https://github.com/cerennnnn/AppleMusicSearchPageClone</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c570d888be6d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SWIFT’S COLLECTION TYPES]]></title>
            <link>https://medium.com/@cerengunnes/swifts-collection-types-e5e5e0a597f?source=rss-4b6246117857------2</link>
            <guid isPermaLink="false">https://medium.com/p/e5e5e0a597f</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[uikit]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift-programming]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <dc:creator><![CDATA[Ceren]]></dc:creator>
            <pubDate>Thu, 12 Jan 2023 16:54:12 GMT</pubDate>
            <atom:updated>2023-01-12T16:54:12.084Z</atom:updated>
            <content:encoded><![CDATA[<p>Hey everyone! 👋</p><p>In my first Medium article, I’ll try to explain <strong>Swift’s collection types</strong>. Hope you enjoy, so let’s begin!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sK-__6rwsgOTOrwGqmdCBg.png" /><figcaption>Collection Types in Swift (from <a href="https://docs.swift.org/swift-book/LanguageGuide/CollectionTypes.html">Apple’s The Swift Programming Language Book</a>)</figcaption></figure><p>There are 3 collection types that Swift language provides us and they’re called <strong><em>Arrays, Sets and Dictionaries</em></strong>. These collection types help us to store data inside of a collection. Now let’s take a closer look at them !</p><h3>1- Arrays</h3><p><strong><em>Arrays</em></strong> are used for collecting values that are <strong>of the same type</strong>. The data in an array can be accessed using an index — which represents a number where the position of an item exists.</p><p>We can create an array in 3 different ways: <strong>type annotation, collection type annotation and an array initializer</strong>. Examples are shown below respectively:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QE9rwO_bBEax4hh1a2xN8g.png" /><figcaption>Example of type annotation declaration.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*beropgnF2gzz4puNSiaIww.png" /><figcaption>Example of collection type annotation declaration, which is less common in practice.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z-upz1jt6oUumqxdcSeC7g.png" /><figcaption>Example of array initializer declaration; putting () after [Int] emphasises that it’s an array of Int objects.</figcaption></figure><p>There’re some useful functions of arrays, let’s check them out:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mGPmJDWDMgNbJVjulV0IyQ.png" /></figure><p>Let me explain the functions briefly:</p><p><strong><em>append() </em></strong>function lets us append an item at the end of an array, with <strong><em>count</em> </strong>property we can get the number of items in an array,<em> </em><strong><em>insert(at: )</em> </strong>allows us to insert an item at the stated index, <strong><em>remove(at: ) </em></strong>helps us to remove an item at the given index,<em> </em><strong><em>removeLast()</em> </strong>removes<strong> </strong>the last item from an array, <strong><em>removeAll() </em></strong>basically empties out the array and <strong><em>isEmpty()</em></strong> returns a Bool to state whether the array is empty or not.</p><p>Arrays are zero-indexed, meaning that they start counting at 0 instead of 1. So in order to fetch the first item of an array, we’ll write this line of code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qq4xyeomoou0HzzNVSN-Rg.png" /></figure><blockquote>Swift also allows us to concatenate arrays of the same type:</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MaWJthlmZM4xYz6QyjMeWg.png" /></figure><blockquote>To access the items of an array, we can use a for-in loop:</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IDaCQlipIajG0kF8uBE-hQ.png" /></figure><p>Let’s take a look at <strong>Sets</strong> now!</p><h3>2- Sets</h3><p>A <strong><em>set</em></strong> stores its items in a random order and can store items of the same type. Every item that a set contains is unique.</p><blockquote>Sets can be used instead of arrays when the order is not important and an item can be appeared just once.</blockquote><p>We can create an empty set of a specified type using initializer syntax:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Uvk135pnMa1uPwGzSq01iQ.png" /><figcaption>Creates a <strong>set</strong> of type Character called letters.</figcaption></figure><blockquote>We can also create a set using the array literal syntax :</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5uLF-CVQwJchxaOt4-qusA.png" /></figure><blockquote>If we try to retrieve an item in a Set, we can use for-in loop :</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E-SUP4MPe28uvNugKlXcOQ.png" /><figcaption>Notice the output is unordered!</figcaption></figure><blockquote>Some functions we can execute in Sets:</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LBGAWQmPQ5eTbdTcHiJEDw.png" /><figcaption>Because of an item in <strong>set </strong>is may or may not be there -or maybe it’s written wrong — we need to fetch the item safely so we used if-let syntax.</figcaption></figure><p>Now let’s get to our last topic: <strong><em>Dictionaries</em></strong>!</p><h3>3- Dictionaries</h3><p>Just like Sets, dictionaries doesn’t store their data in order. Data is stored as key-value pairs and all the keys and values must be of the same type as when they declared.</p><blockquote>How to create a dictionary?</blockquote><p>There’re 3 declaration syntaxes of a dictionary as follows :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LtoWBmFKxIGjaQZdodWgjQ.png" /><figcaption>Dictionary declaration using initializer syntax.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r1EmEpp1Zka_eoKVDjpZWQ.png" /><figcaption>Dictionary declaration using Dictionary Literal syntax.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lzpEThAwlDu41SfFOGwosQ.png" /><figcaption>Declaration of a dictionary without inferring the type.</figcaption></figure><blockquote>We can add and change an item of a dictionary using <strong>subscript syntax</strong>:</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BNmOlLmCLGUkr6EdIuQghg.png" /><figcaption>Add a new item to the dictionary.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9mAZt7ELBmPjeJBnP_k_kA.png" /><figcaption>Change an existing item in the dictionary.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wrFq94SJZIIDyuFe61VB_A.png" /><figcaption>Because we’re not 100% sure whether if the key spelled correctly or simply just exists, we have to safely unwrap the key.</figcaption></figure><blockquote>We can use the for-in loop to get the values of a dictionary :</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_jCwBDkPJD2DNma-5xlMIQ.png" /></figure><blockquote>We can do the same thing but this time just for the values :</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wuTneHXwFP3qtMvICbFWvA.png" /></figure><blockquote>Or we can get both the key and the value like this :</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3NMxX3xaXXJd33NRXoLSCA.png" /></figure><p>So, that was it! 🤓</p><p>In my first article, I tried to explain Swift’s Collection Types as best as I can. Thank you for taking time to read, hope you enjoyed. Have a great day! 👋</p><p><strong>Resource for this article </strong>: <a href="https://docs.swift.org/swift-book/LanguageGuide/CollectionTypes.html">https://docs.swift.org/swift-book/LanguageGuide/CollectionTypes.html</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e5e5e0a597f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>