<?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 Alkin Cakiralar on Medium]]></title>
        <description><![CDATA[Stories by Alkin Cakiralar on Medium]]></description>
        <link>https://medium.com/@acakiralar?source=rss-fb9fdb7f40a6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*x8L1EHJBwgPqUFUXPj-ddg.png</url>
            <title>Stories by Alkin Cakiralar on Medium</title>
            <link>https://medium.com/@acakiralar?source=rss-fb9fdb7f40a6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 00:48:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@acakiralar/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[iOS GraphQL Simplified: macOS Command Line Techniques for Sustainable Schema Operations]]></title>
            <link>https://medium.com/@acakiralar/ios-graphql-simplified-macos-command-line-techniques-for-sustainable-schema-operations-22921d436f74?source=rss-fb9fdb7f40a6------2</link>
            <guid isPermaLink="false">https://medium.com/p/22921d436f74</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[apollo]]></category>
            <category><![CDATA[macos]]></category>
            <dc:creator><![CDATA[Alkin Cakiralar]]></dc:creator>
            <pubDate>Wed, 20 Dec 2023 00:03:22 GMT</pubDate>
            <atom:updated>2023-12-20T06:52:35.697Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="iOS GraphQL Simplified: macOS Command Line Techniques for Efficient Structure Management" src="https://cdn-images-1.medium.com/max/1024/1*wSBk0zp0ugmkEcND9xXxWQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OxKiqqrxtxkasfWvd_ZAGQ.gif" /></figure><h3>Introduction</h3><p><strong>GraphQL</strong> is a powerful tool that optimizes data retrieval by allowing precise and efficient data requests. <strong>Apollo</strong> is a comprehensive GraphQL client that streamlines data management in the applications.</p><blockquote>Here is the “<strong>Getting Started with Apollo iOS”</strong> tutorial from Apollo documentation, where you can find more information about the setup and installation process</blockquote><blockquote><a href="https://www.apollographql.com/docs/ios/get-started">https://www.apollographql.com/docs/ios/get-started</a></blockquote><p>It requires different techniques from rest operations. First of all, we should install <strong>Apollo dependencies</strong> to be able to perform network operations. In the application folders, we must define<strong> “apollo-codegen-config.json”</strong> and then install <strong>“apollo-ios-cli”</strong>. We should define the operations path <strong>(including fragments, queries, mutations, etc.)</strong> and perform necessary scripts like “<strong>fetch-schema</strong>” or “<strong>generate”</strong> using <strong>apollo-ios-cli</strong>.</p><p>When you want to add a new operation or edit an operation this could be difficult for your new team-members or your project contributors.</p><h3><strong>What we gonna achieve</strong> ?</h3><p>We will gain more power to adapt our new contributors, allowing them to easily fetch the current <strong>GraphQL Scheme</strong> or generating operations <strong>(query, fragment, mutation etc.)</strong> into the swift files using <strong>macOS command line terminal target</strong>.</p><p>Our goal is to achieve the final snapshot as described below: we simply select the CLI scheme, then run <strong>⌘ + R</strong>. This will fetch the current schema from the server and regenerate all files with the .graphql extension into Swift files. In this way, by not having to do this task manually, we will have created a simple method <strong>for the developers who come after us.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/534/1*bSHD_ibhTwXqeOE8-iZ_DQ.png" /></figure><h3>Let’s Start 🚀</h3><p>In this tutorial, I’ll be using the endpoint from <a href="https://rickandmortyapi.com/graphql"><strong>https://rickandmortyapi.com/graphql</strong></a>.</p><p>Let’s create a new Xcode project called <strong>“GraphQLiOSBlueprint” </strong>and install this dependency below.</p><blockquote><a href="https://github.com/apollographql/apollo-ios.git">https://github.com/apollographql/apollo-ios.git</a></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lH9SVIsPl6qf0rQbkEo10A.png" /></figure><p>Once you’ve installed the package, you can install .apollo-ios-cli by right-clicking on your workspace.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-UT2UGNjprCVZgIM56l8XA.png" /></figure><p>In the screen presented, tap on the ‘Run’ button; this will generate the Apollo CLI in the root folder of your project. Then, create a new folder named ‘data’ and the subfolders as listed below: 👇</p><p>Drag the .apollo-ios-cli into the core folder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/606/1*-jLlAKKb2aOMxJJoI6iCmg.png" /></figure><h4>Core folder will include 3 item</h4><ul><li>graphql_schema.graphqls ( will be automatically downloaded when we execute the ‘fetch-schema’ command using .apollo-ios-cli )</li><li>apollo-codegen-config.json ( we will setup the apollo configuration in this file )</li><li>apollo-ios-cli</li></ul><p>Also, we will keep our queries, fragments and mutations inside the operations folder.</p><p>Here is the apollo-codegen-config.json below</p><pre>{<br>  &quot;schemaNamespace&quot;: &quot;GraphqlAPI&quot;, // spm package name that will consist <br>  // of generated swift files based on our graphql operations<br>  &quot;input&quot;: {<br>    &quot;operationSearchPaths&quot;: [<br>      &quot;../Operations/Query/*.graphql&quot;, // queries path url<br>      &quot;../Operations/Mutation/*.graphql&quot;, // mutations path url<br>      &quot;../Operations/Fragment/*.graphql&quot; // fragments path url<br>    ],<br>    &quot;schemaSearchPaths&quot;: [&quot;graphql_schema.graphqls&quot;]<br>  },<br>  &quot;output&quot;: {<br>    &quot;testMocks&quot;: {<br>      &quot;none&quot;: {}<br>    },<br>    &quot;schemaTypes&quot;: {<br>      &quot;path&quot;: &quot;.././GraphqlAPI&quot;, // spm package url, we will put the <br>                                 // spm file inside our data folder<br>      &quot;moduleType&quot;: {<br>        &quot;swiftPackageManager&quot;: {}<br>      }<br>    },<br>    &quot;operations&quot;: {<br>      &quot;inSchemaModule&quot;: {}<br>    }<br>  },<br>  &quot;schemaDownloadConfiguration&quot;: {<br>    &quot;downloadMethod&quot;: {<br>      &quot;introspection&quot;: {<br>        &quot;endpointURL&quot;: &quot;https://rickandmortyapi.com/graphql&quot;, // remote endpoint url<br>        &quot;httpMethod&quot;: {<br>          &quot;POST&quot;: {}<br>        },<br>        &quot;includeDeprecatedInputValues&quot;: false,<br>        &quot;outputFormat&quot;: &quot;SDL&quot; // we will use sdl instead of JSON<br>      }<br>    },<br>    &quot;downloadTimeout&quot;: 60,<br>    &quot;headers&quot;: [],<br>    &quot;outputPath&quot;: &quot;./graphql_schema.graphqls&quot; // schema download location<br>  }<br>}</pre><p>Now, open your terminal and navigate to the apollo-ios-cli folder. Run this command below</p><pre>./apollo-ios-cli fetch-schema</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WIXz3fFzOIsJkApIVD5Rjw.png" /></figure><p>This command will fetch the current schema from the server and will download the <strong>graphql_schema.graphql</strong> file to the core folder under the data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*suycV5ORhultBogekUiYSw.png" /></figure><p>Additionally, drag the file into the <strong>Core</strong> folder in Xcode. The current structure should then appear as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/610/1*wIQtdf9DVN2VNpwjJuqOrQ.png" /></figure><p>Before executing the <strong>generate</strong> command to convert files with a <strong>.graphql extension</strong> into <strong>Swift</strong> files, we must add at least one operation to our operations folder.</p><p>Let’s create <strong>characters.graphql</strong> file into our <strong>Query</strong> folder.</p><pre>query characters {<br>  characters {<br>    results {<br>      id<br>      image<br>    }<br>  }<br>}</pre><p>Open the terminal and navigate to the <strong>Core</strong> folder and <strong>execute</strong> this command below</p><pre>./apollo-ios-cli generate</pre><p>It will create an SPM package named <strong>GraphqlAPI</strong> which will contain the Swift files generated from our <strong>GraphQL</strong> operations. These swift files allows us to perform queries and mutations. Just drag this spm package into the data folder. Now the current structure of the project should looks like as below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*j6JRCls0z0rmFlXChy7B_g.png" /></figure><p>After you’ve dragged, we should add this dependency into our main target in <strong>Build Phases</strong>. Select your app target then navigate to <strong>Build Phases</strong>, open the <strong>Link Binary With Libraries</strong> and tap the plus button. Select the <strong>GraphqlAPI</strong> package and include it into our project.</p><h4>Let’s try out whether this query works or not in ContentView 📚</h4><p>Here is the ContentView code below</p><pre>//<br>//  ContentView.swift<br>//  GraphQLiOSBlueprint<br>//<br>//  Created by Alkın Çakıralar on 19.12.2023.<br>//<br><br>import Apollo<br>import GraphqlAPI<br>import SwiftUI<br><br>class ApolloManager {<br>    static let shared = ApolloManager()<br>    let client: ApolloClient<br><br>    private init() {<br>        client = ApolloClient(url: URL(string: &quot;https://rickandmortyapi.com/graphql&quot;)!)<br>    }<br>}<br><br>struct ContentView: View {<br>    var body: some View {<br>        VStack {<br>            Image(systemName: &quot;globe&quot;)<br>                .imageScale(.large)<br>                .foregroundStyle(.tint)<br>            Text(&quot;Hello, world!&quot;)<br>        }<br>        .padding()<br>        .task {<br>            ApolloManager.shared.client.fetch(query: CharactersQuery()) { result in<br>                do {<br>                    let data = try result.get().data<br>                    print(data?.characters?.results?.first??.image ?? &quot;&quot;)<br>                } catch {<br>                    print(error.localizedDescription)<br>                }<br>            }<br>        }<br>    }<br>}<br><br>#Preview {<br>    ContentView()<br>}</pre><p>When you run the application, you will see that the first image url of the characters will print out.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H3i_NIZMwm_9SZOV8i9l3w.png" /></figure><h3>Dive into the engineering part 👨‍💻</h3><p>So far, I’ve showed you how you can setup basic <strong>GraphQL</strong> integration with your server using <strong>Apollo</strong> library on iOS application. You have two commands that you will always use in your development process.</p><pre>./apollo-ios-cli fetch-schema<br>./apollo-ios-cli generate</pre><h4>We should automate these commands, but how ?</h4><p>Actually, there is a suggestion in the forums that we can add these commands as run script into the build phases. However, if these commands run in each build, your build time may not be efficient. Therefore I create another approach, using with macOS command line terminal target. Let me show you step by step.</p><p>First, create new target under macOS section called <strong>“Command Line Tool” </strong>and name it “<strong>GraphqliOSBlueprintCLI</strong>” so that it is understandable when selecting the schema.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O8yoTXONyd5oufS0AqpVJw.png" /></figure><p>You will see that the target created under the root folder with contains <strong>main.swift </strong>file as below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/596/1*Bi5Vi0_jAGV_lVOPxSkBJg.png" /></figure><p>Open the main.swift file and paste this code below.</p><pre>import Foundation<br><br>func executeShellCommand(command: String, in directoryPath: String) {<br>    let task = Process()<br>    task.launchPath = &quot;/bin/bash&quot;<br>    task.arguments = [&quot;-c&quot;, command]<br>    task.currentDirectoryPath = directoryPath<br><br>    task.launch()<br>    task.waitUntilExit()<br>}<br><br>let fileURL = URL(fileURLWithPath: #file)<br>let projectDirectoryURL = fileURL.deletingLastPathComponent().deletingLastPathComponent()<br>let apolloConfigDirectoryPath = projectDirectoryURL.appendingPathComponent(&quot;GraphQLiOSBlueprint/Data/Core&quot;).path<br>let apolloCliExecutablePath = projectDirectoryURL.appendingPathComponent(&quot;GraphQLiOSBlueprint/Data/Core/apollo-ios-cli&quot;).path<br><br>let apolloCommand = &quot;\(apolloCliExecutablePath) fetch-schema&quot;<br>executeShellCommand(command: apolloCommand, in: apolloConfigDirectoryPath)<br><br>let generateCommand = &quot;\(apolloCliExecutablePath) generate&quot;<br>executeShellCommand(command: generateCommand, in: apolloConfigDirectoryPath)<br><br>print(&quot;Successfully fetched and re-generated the apollo files&quot;)</pre><p>After copied this code, run <strong>⌘ + R </strong>then this script will fetch your schema and generate your swift files asynchronously.</p><p>Let’s add another character property to our characters query to <strong>try out</strong>.</p><pre>query characters {<br>  characters {<br>    results {<br>      id<br>      image<br>      status<br>    }<br>  }<br>}</pre><p>It’s the time that we test our engineering is good or not. Make sure that you select CLI schema, then run <strong>⌘ + R.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/634/1*jKcIvUgM9hzVmDaV8selKw.png" /></figure><p>After execution, we are able to use status property of character model 🥳</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FR3VbY4fSTnktAD4YDlB0g.png" /></figure><h3>Conclusion</h3><p>With this approach, we will be more organize when managing the data layer using this folder structure and our new team-members will adapt our <strong>GraphQL</strong> infra <strong>effortless</strong>.</p><blockquote>Besides, apart from all the context, we define a problem that would be happen in the future and we have created a solution for something that is not happening right now. This perspective always gains us lots of things during our careers 💪.</blockquote><p>Here is the github repository below:</p><p><a href="https://github.com/alkincakiralar1996/GraphQLiOSBlueprint">https://github.com/alkincakiralar1996/GraphQLiOSBlueprint</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=22921d436f74" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Discover Apple’s New Framework Called “TipKit”]]></title>
            <link>https://medium.com/@acakiralar/discover-apples-new-framework-called-tipkit-26c4f2ddfbe6?source=rss-fb9fdb7f40a6------2</link>
            <guid isPermaLink="false">https://medium.com/p/26c4f2ddfbe6</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[apple]]></category>
            <dc:creator><![CDATA[Alkin Cakiralar]]></dc:creator>
            <pubDate>Fri, 28 Jul 2023 13:46:04 GMT</pubDate>
            <atom:updated>2023-07-28T13:46:04.371Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="tipkit, apple, swift, Xcode, iOS, macOS, iPadOS, visionOS" src="https://cdn-images-1.medium.com/max/688/1*KNkr4eY7D5mtD0ZYi2cDPw.png" /></figure><h3><strong>Introduction</strong></h3><p>In WWDC23, Apple introduced lots of new things to help us to make more efficient, maintainable and be able to avoid third-party libraries frameworks. <strong>“TipKit” </strong>is the one of the framework that allows us to provide highlight the new features of our app among these.</p><h4><strong>Pros 🥳</strong></h4><ul><li>Both SwiftUI and UIKit implementation available</li><li>Compatible with whole Apple platforms including iOS, macOS, iPadOS, visionOS</li><li>Can be easily integrate, testable</li><li>Chance to avoid third-party libraries such as ephread/Instructions</li></ul><h4>Cons 🤔</h4><ul><li>Only compatible with iOS17 and newer versions as always ( Apple did this again without thinking the developers 😪 )</li><li>Could irritate the users whose using your app if you wouldn’t act correctly in the app while highlighting your new features</li></ul><blockquote><em>🚨 </em>Before we jumped out, please note that this feature only works with <strong><em>Xcode Beta 15–5.0 and newer versions</em></strong>. Here is the link that you can download the latest Xcode version below. ⬇️</blockquote><blockquote><a href="https://xcodereleases.com/"><strong><em>https://xcodereleases.com/</em></strong></a></blockquote><h3>Let’s dive in to explore more details about “TipKit”</h3><p>Let’s start with developing the screen that has an image to be to work on</p><pre>struct ContentView: View {<br>    var body: some View {<br>        VStack {<br>            Button {<br>                //<br>            } label: {<br>                Image(.profile)<br>                    .resizable()<br>                    .frame(width: 200, height: 200)<br>                    .clipShape(.circle)<br>                    .padding(.leading, 22)<br>            }<br>        }<br>        .padding()<br>        .preferredColorScheme(.dark)<br>    }<br>}</pre><p>The first scenario is when we launched the app we expect that tooltip appear with title, message, icon and button actions on the bottom of the image. To be able to do this we have to create a struct class that conformed by <strong>Tip </strong>protocol. This protocol consist of ⬇️</p><blockquote><strong><em>id: String </em></strong><em>// Unique Identifier that auto assigned</em><strong><em><br>title: Text </em></strong><em>// The text that shows on the top of TipView as Title</em><strong><em><br>message: Text? </em></strong><em>// The text that shows on the middle of TipView as Message</em><strong><em><br>asset: Image? </em></strong><em>// The image that shows on the left side of TipView as icon</em><strong><em><br>actions: [TipKit.Action] </em></strong><em>// The action buttons that you can trigger user in the TipView</em><strong><em><br>rules: [TipKit.Rule] </em></strong><em>// Rules for adjusting to appearing of TipView</em><strong><em><br>options: [TipOption]</em></strong><em> // Customization options for style of TipView</em></blockquote><p>Here is the UserWelcomeTip struct</p><pre>struct UserWelcomeTip: Tip {<br>    var title: Text {<br>        Text(&quot;Welcome to The App&quot;)<br>    }<br><br>    var message: Text? {<br>        Text(&quot;Enjoy it, discover and fun !&quot;)<br>    }<br><br>    var asset: Image? {<br>        Image(systemName: &quot;info.circle.fill&quot;)<br>    }<br><br>    var actions: [Action] {<br>        [<br>            Tip.Action(<br>                id: &quot;learn-about-me&quot;,<br>                title: &quot;Learn About Me&quot;<br>            ),<br>        ]<br>    }<br>}</pre><p>Create an instance of <strong>UserWelcomeTip</strong> struct in the ContentView, then we will add <strong>popoverTip</strong> to the related button and set the property which name is <strong>userWelcomeTip</strong>. In addition to present the tip we have to adjust some settings with <strong>TipsConfiguration</strong> when view has appeared.</p><pre>private let userWelcomeTip = UserWelcomeTip()</pre><pre>Button {<br>          // action          <br>        } label: {<br>            Image(.profile)<br>                .resizable()<br>                .frame(width: 100, height: 100)<br>                .clipShape(.circle)<br>                .padding(.leading, 22)<br>        }<br>        .popoverTip(userWelcomeTip, arrowEdge: .bottom)<br>        .task {<br>            try? await Tips.configure() {<br>                DisplayFrequency(.immediate)<br>                DatastoreLocation(.applicationDefault)<br>            }<br>        }</pre><p>You can add custom configurations into to the configure() closure that conforms by <strong>TipsConfiguration</strong> which is currently we got two options including <strong>DisplayFrequency</strong> and <strong>DatastoreLocation.</strong></p><p><strong>DisplayFrequency</strong> helps you to adjust your tips frequency which consist of immediate, hourly, daily, weekly, monthly. We established that frequency using <strong>UserDefaults</strong> before. How cool and very simple it is, right?</p><p><strong>DatastoreLocation</strong> allows you to configure the location that you want to store the tips preferences whatever path url inside the phone you want. In addition to this it has <strong>shouldReset</strong> parameter to reset the preferences as beginning. It’s default value is false, you can use this parameter depends on your needs.</p><pre>public init(_ location: DatastoreLocation, shouldReset: Bool = false)</pre><p>Run the application and you will be able to show your first tip that you just created on the bottom of the profile image as below 🥳</p><figure><img alt="tipkit, apple, swift, Xcode, iOS, macOS, iPadOS, visionOStipkit, apple, swift, Xcode, iOS, macOS, iPadOS, visionOS" src="https://cdn-images-1.medium.com/max/682/1*JhfFZQOAa6CcP_j6_2GPUw.png" /></figure><h3>What if we want to present tips depends on some condition ?</h3><p>Some scenarios, you may want to present your tips by conditionally. In this particular case Apple brings up with <strong>@Parameter</strong> and <strong>#Rule</strong> macros to allows us to manage conditions by each tip.</p><blockquote><em>🚨 Before we use these macros you have to implement this into the </em><strong><em>BuildSettings -&gt; Other Swift</em></strong><em> </em><strong><em>Flags</em></strong><em> section otherwise Xcode will not recognize these macros because it’s still experimental</em></blockquote><pre>-external-plugin-path<br>$(SYSTEM_DEVELOPER_DIR)/Platforms/iPhoneOS.platform/Developer/usr/lib/swift/host/plugins#$(SYSTEM_DEVELOPER_DIR)/Platforms/iPhoneOS.platform/Developer/usr/bin/swift-plugin-server</pre><h3>Let’s add the rule condition the our existing tip called UserWelcomeTip</h3><p>Imagine you want to present the tip when user click the profile image, to be able to do that we need a parameter that we used in the rules of tip structs and we need to define our rule inside of the struct.</p><p>Here is the modified version of UserWelcomeTip Struct file below</p><pre>struct UserWelcomeTip: Tip {<br>    @Parameter<br>    static var isActive: Bool = false<br>    <br>    var title: Text {<br>        Text(&quot;Welcome to The App&quot;)<br>    }<br><br>    var message: Text? {<br>        Text(&quot;Enjoy it, discover and fun !&quot;)<br>    }<br><br>    var asset: Image? {<br>        Image(systemName: &quot;info.circle.fill&quot;)<br>    }<br><br>    var actions: [Action] {<br>        [<br>            Tip.Action(<br>                id: &quot;learn-about-me&quot;,<br>                title: &quot;Learn About Me&quot;<br>            ),<br>        ]<br>    }<br>    <br>    var rules: [Rule] = [<br>        #Rule(Self.$isActive) { $0 == true }<br>    ]<br>}</pre><p>So, this tip only trigger when the static <strong>isActive</strong> property turns into the true. Until then, we <strong>will not encountered this tip in the application. </strong>Just set true to the isActive property when the button that has profile Image clicked to present the tip.</p><pre>Button {<br>          UserWelcomeTip.isActive = true<br>      } label: {<br>          Image(.profile)<br>              .resizable()<br>              .frame(width: 100, height: 100)<br>              .clipShape(.circle)<br>              .padding(.leading, 22)<br>      }<br>      .popoverTip(userWelcomeTip)<br>      .task {<br>          try? await Tips.configure() {<br>              DisplayFrequency(.immediate)<br>              DatastoreLocation(.applicationDefault, shouldReset: true)<br>          }<br>      }</pre><h4>👀 Let’s dive into what happens in the background of these macros</h4><p>Apple introduced <strong>SwiftMacros</strong> in <strong>WWDC23</strong>, basically it allows us to generate codes instead of us and help us to reduce our codebase more effective. Here is the link that you can get more knowledge about <strong>SwiftMacros</strong> from <strong>Apple Documentation</strong> below ⬇️</p><blockquote><a href="https://developer.apple.com/documentation/Swift/applying-macros#">https://developer.apple.com/documentation/Swift/applying-macros#</a></blockquote><p>When you select <strong>@Parameter</strong> or <strong>#Rule</strong> macros and right click you will see that there is an <strong>ExpandMacro</strong> selection in the panel, you will be able to see what code written from macro for you.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h0yqMTxr2e6lACIuHd2MCA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hHPUgHHGgXmzxrh_6N6Tdw.png" /></figure><blockquote>It’s awesome isn’t it ? Don’t be late to try SwiftMacros for your own projects in the future 🧑‍🎨</blockquote><p>Furthermore, let’s make our rules get more complex. Now we’re changing our scenario to user click count on the image to be able to present the tip.</p><p>Add an event to track our user click count into the UserWelcomeTip struct to be able to configure our rules depends on this event therefore we will have a chance to add click count condition rule depends on the user click count to present our tip</p><pre>struct UserWelcomeTip: Tip {<br>    @Parameter<br>    static var isActive: Bool = false<br><br>    // we define an event to capture user click count<br>    static let numberOfTimesShowedOption: Event = Event(id: &quot;dev.alkincakiralar.tip.numberOfTimesShowedOption&quot;)<br><br>    var title: Text {<br>        Text(&quot;Welcome to The App&quot;)<br>    }<br><br>    var message: Text? {<br>        Text(&quot;Enjoy it, discover and fun !&quot;)<br>    }<br><br>    var asset: Image? {<br>        Image(systemName: &quot;info.circle.fill&quot;)<br>    }<br><br>    var actions: [Action] {<br>        [<br>            Tip.Action(<br>                id: &quot;learn-about-me&quot;,<br>                title: &quot;Learn About Me&quot;<br>            ),<br>        ]<br>    }<br><br>    var rules: [Rule] = [<br>        #Rule(Self.$isActive) { $0 == true },<br>        // depends on the relevant capture event we add one more rule and <br>        // we&#39;re checking the click count is equal and larger than 3<br>        #Rule(Self.numberOfTimesShowedOption) { $0.donations.count &gt;= 3 }<br>    ]<br>}</pre><p>To be able to trigger that event we have to do call donate function from <strong>numberOfTimesShowedOption</strong> property wherever we want, it will kept in the storage that we defined in the <strong>DatastoreLocation</strong>. In this way, we can avoid to store these kind of rules in <strong>UserDefaults</strong>.</p><pre>Button {<br>        // we called the donate function every click of this button.<br>        // when user clicked 3 times to that button the tips that we adjusted<br>        // will be present immediately<br>        UserWelcomeTip.numberOfTimesShowedOption.donate()<br>        UserWelcomeTip.isActive = true<br>    } label: {<br>        Image(.profile)<br>            .resizable()<br>            .frame(width: 100, height: 100)<br>            .clipShape(.circle)<br>            .padding(.leading, 22)<br>    }<br>    .popoverTip(userWelcomeTip)<br>    .task {<br>        try? await Tips.configure {<br>            DisplayFrequency(.immediate)<br>            DatastoreLocation(.applicationDefault, shouldReset: true)<br>        }<br>    }</pre><h3>What about testing process ?</h3><p>Apple gives us an opportunity to be able to test the tips scenarios in the app while making the UITests.</p><p>In the following methods will help you to test your tips easily.</p><ul><li><strong>Tips.showAllTips()</strong></li><li><strong>Tips.showTips([userWelcomeTip]</strong></li><li><strong>Tips.hideTips([userWelcomeTip]</strong></li><li><strong>Tips.hideAllTips()</strong></li></ul><h3><strong>Conclusion</strong></h3><p>This framework is a great chance to introduce our new features in the app. However, we should be aware of it’d be consequences when we use it more than it’s purpose. We should be avoid using this framework unnecessary times. Apple gives us some recommendations that when we should use use this inside the app. Here are the recommendations and not recommendations images from WWDC23 about TipKit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1APTsVGkSKNG1x2jgwaTUQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fYZglWpe9N4hk21GYFeeFg.png" /></figure><h3>References</h3><ul><li>WWDC23 Session: <a href="https://lnkd.in/dDFtHqkG">https://lnkd.in/dDFtHqkG</a></li><li>TipKit Documentation: <a href="https://lnkd.in/dJBbG6zz">https://lnkd.in/dJBbG6zz</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=26c4f2ddfbe6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Create a Code Snipped in Xcode, What’re the Benefits?]]></title>
            <link>https://medium.com/@acakiralar/how-to-create-a-code-snipped-in-xcode-whatre-the-benefits-db480f78ed4b?source=rss-fb9fdb7f40a6------2</link>
            <guid isPermaLink="false">https://medium.com/p/db480f78ed4b</guid>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Alkin Cakiralar]]></dc:creator>
            <pubDate>Sun, 09 Apr 2023 21:11:38 GMT</pubDate>
            <atom:updated>2023-04-09T21:11:38.907Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j-eHfM_k1q-9a2FvUScx5g.png" /></figure><p>Sometimes you may get bored of writing code snippets that you use all the time, therefore looking for a good way about this situation. <strong>Code snippets</strong> allow you to create shortcuts to snippets of code that you use frequently. In the following, we will dive into how we use this Xcode feature efficiently.</p><p>Let’s think about the side of <strong>SwiftUI</strong>, we regularly use <strong>VStack</strong> and <strong>HStack</strong> while we are writing <strong>SwiftUI </strong>and we want to make it easy to use them.</p><p>First of all, create those snippets as below then select the VStack snippet. Right-click and choose the “Create Code Snippet” option.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/968/1*MLUQvA5i2CVjPeNaETukgA.png" /></figure><p>In the following screen, I recommend you define a sensible title to distinguish it from other snippets. Because after a while you may have plenty of snippets therefore if you didn’t write a sensible title you may not find what you are looking for. In the completion text field, we need to set which shortcuts we want to call this snipped with.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XZIOdljKUlVmbiqv-i4CrQ.png" /></figure><p>When we come back to the code, just write your shortcut and you will see the snipped suggestion that you created recently with your snipped title. Hit enter and access the <strong>code snippet</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P3XawNWw0K8EESZkXJER-Q.png" /></figure><p>Let’s make it a more useful snippet for <strong>VStack. </strong>This time I created a VStack snippet with a spacing option as below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/814/1*VbY_H8D0Z3tRC-0DGKKZyQ.png" /></figure><blockquote>You may wonder how we can specify the “code” sign in the snippet. To do this put “ &lt;#Code#&gt;” whenever you want to sign it.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/402/1*7c3i2H2iV9vO01Q1QNJBBA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/354/1*RkwThcWsozF3utv4oIWaqA.png" /></figure><p>In addition, I want to show an example of the snipped that I use the most for creating SwiftUI views automatically.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TWMZCa6HNW3r_KZRhrpgxg.png" /></figure><p>After that, we can access justly all the snipped that we create writing “create”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/746/1*FJjIIk3Z0Bu5opwJkiu8nw.png" /></figure><h4>The Conclusion</h4><p>Code snippets are a valuable tool for developers that can save time, reduce errors, standardize code, and facilitate collaboration. By creating and using code snippets in Xcode, you can improve your development process and create higher-quality code.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=db480f78ed4b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Sunday Tips  How to show build time in Xcode?]]></title>
            <link>https://medium.com/@acakiralar/sunday-tips-how-to-show-build-time-in-xcode-3daeda121137?source=rss-fb9fdb7f40a6------2</link>
            <guid isPermaLink="false">https://medium.com/p/3daeda121137</guid>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Alkin Cakiralar]]></dc:creator>
            <pubDate>Sun, 02 Apr 2023 11:47:48 GMT</pubDate>
            <atom:updated>2023-04-02T11:47:48.734Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/332/0*Y4ePYujZZLxWjcU8" /></figure><p>Execute the following command via terminal, after execution you will be able to show build time per each build on Xcode.</p><pre>defaults write com.apple.dt.Xcode ShowBuildOperationDuration YES</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Bo76jdnw3JM1xScR" /></figure><p>But the important thing is it only works for CMD+B (build), not works for CMD+R(run)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3daeda121137" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[@backDeployed feature is available with Swift 5.8 ]]></title>
            <link>https://medium.com/@acakiralar/backdeployed-feature-is-available-with-swift-5-8-99057cbd6aa7?source=rss-fb9fdb7f40a6------2</link>
            <guid isPermaLink="false">https://medium.com/p/99057cbd6aa7</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[backdeployed]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[xcode]]></category>
            <dc:creator><![CDATA[Alkin Cakiralar]]></dc:creator>
            <pubDate>Fri, 31 Mar 2023 21:56:09 GMT</pubDate>
            <atom:updated>2023-03-31T21:56:09.992Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*AZnUYAK-irHiONhA.png" /></figure><p>As you know, <strong>SwiftUI</strong> evolves every new year with new features. However, a lot of new features may not compatible with old versions of os versions. Therefore we need to wait to upgrade the app’s os version <em>for a few years</em> to use those features or we need to divide our codes checking availability according to the os version by functions. With <strong>@backDeployed</strong> helps us to make functions to compatible with old os versions.</p><h4>Let’s take a look at how it is working</h4><p>For example, we have a function that helps us calculate BMI and set this function only available with <strong>iOS 16.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kXP0NVoA5hQ6W1mqWbLUWg.png" /></figure><p>And if we support <strong>older iOS 16</strong> for our app we should check the availability of the os version when we want to use it as below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/854/1*A-EYcpx39swmbYk8zX9VBA.png" /></figure><p>Let’s make <strong>“calculateBMI”</strong> function to available with older versions of <strong>iOS 16</strong> and use it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yybZwQE6CHuRwM9D1mWvFg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/792/1*QrwDU5RNgiYQk6quhtTH_w.png" /></figure><p>See! It’s so simple and useful. With this attribute, we can get through it our concerns about users who are using old versions.</p><p>I hope we will able to use the new SwiftUI components with older versions of os with this attribute.</p><blockquote>If you want more click the link below</blockquote><p><a href="https://github.com/apple/swift-evolution/blob/main/proposals/0376-function-back-deployment.md">https://github.com/apple/swift-evolution/blob/main/proposals/0376-function-back-deployment.md</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=99057cbd6aa7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to automate your TestFlight internal/external processes via Xcode Cloud?]]></title>
            <link>https://medium.com/@acakiralar/how-to-automate-your-testflight-internal-external-processes-via-xcode-cloud-c44a1018c58f?source=rss-fb9fdb7f40a6------2</link>
            <guid isPermaLink="false">https://medium.com/p/c44a1018c58f</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[xcode-cloud]]></category>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Alkin Cakiralar]]></dc:creator>
            <pubDate>Fri, 24 Feb 2023 13:45:50 GMT</pubDate>
            <atom:updated>2023-02-24T13:45:50.111Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Xcode Cloud" src="https://cdn-images-1.medium.com/max/1024/0*UQL_GHKJ-Pp0LnUO.jpg" /></figure><h3>Introduction</h3><p><a href="https://developer.apple.com/xcode-cloud/">Xcode Cloud</a> is a CI/CD tool that you use to create automated integrations with Xcode, App Store Connect and TestFlight.</p><h4>You can do this with Xcode Cloud:</h4><ul><li>Build, test or analyze your app with any platform or scheme by any <strong>Xcode</strong> or <strong>MacOS</strong> version.</li><li>Publish your app’s test version to the <strong>TestFlight</strong> for internal/external users.</li><li>Parallel testing</li></ul><figure><img alt="Xcode Cloud" src="https://cdn-images-1.medium.com/max/1024/0*6274jQKSavGqNyjx.jpg" /></figure><h3>The cons</h3><ul><li>You can’t add your test notes while you are publishing your app’s test version to the <strong>TestFlight 😥</strong></li></ul><h3><strong>Let’s Start 🚀</strong></h3><p>In the following, we will take a look at only TestFlight part.</p><p><strong>Create Workflow</strong> from <strong>Product -&gt; Xcode Cloud.</strong></p><p>You can see a warning like the one below on the screen that pops up.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*94xPXFZp23CH2lyAg8A1fQ.png" /></figure><p>⚠️ As you can see, you must have a connected repository with xcode which contains your project to create a <strong>Workflow.</strong></p><p>After that, select your product and <strong>click</strong> next on the upcoming screen. <strong>( Remember to select your team )</strong></p><p>Now, you should see the workflow management screen. Write your workflow name as you wish. For example we will configure internal testing therefore i wrote <strong><em>“TestFlight Internal User”. </em></strong>Check your repository and select your project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jCGlJJeCQ744UPCbR9rOiw.png" /></figure><p>In the <strong>Start Conditions </strong>menu<strong> Branch Changes </strong>option comes with default which means whenever something is changed on the selected branch or if you choose the <strong>Any Branch</strong> option the workflow will start. <strong>Custom Branches</strong> option integrated with your <strong>Github repository branches</strong> therefore you can choose any branch from your repository. In this example i decided to use <strong>the Beta Branch</strong> to deploy test version to TestFlight.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oI8iPnQ7CU9rhOCsGpLGSA.png" /></figure><p><strong>“Start a Build If Any File Changes” </strong>comes with default, i prefer to use this option because Beta branch is only meant for releasing test versions. If you don’t want to work like that you can create your own conditions with “<strong>Custom Conditions” </strong>option.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cmrh8VrR9vbf318e_ShfEw.png" /></figure><h3>Actions</h3><p>In the actions menu we create three actions to be sure that everything is okay.</p><ul><li>Build stage</li><li>Test Stage</li><li>Archive Stage</li></ul><h4>Build Stage</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q8yhkLT1f1dzu0_YKSnnfQ.png" /></figure><h4>Test Stage</h4><p>In this stage we can create our test rules to be sure that everything is okay. Choose your platform and scheme again and set the requirement option according to your need.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MlaPi7KGy0aLaQOx56z1hQ.png" /></figure><h4>Archive Stage</h4><p>As simple as shown in the picture below, choose your platform and schema that you need and select the deployment preparation. We’ll be continuing with“ <strong>Internal Testing Only”</strong> option but if we wanted to the create this workflow to upload the application to the app store or publish the test version for the external users, we should have chosen “<strong>TestFlight and App Store”</strong> option.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cEpM7flSMU6xlU3vUb694A.png" /></figure><h3>Post-Actions</h3><p>We got three options to complete our workflow according to our need in this menu.</p><ul><li>External Testing</li><li>Internal Testing</li><li>Notify</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*HUcLPKVUx7MJVHwi_V9qWA.png" /></figure><blockquote>Before using the <strong>Post Actions</strong> make sure you that have <strong>external or internal testers groups in your App Store Connect. </strong>If you don’t have it, you can add it from App Store Connect under the TestFlight menu.</blockquote><h4>TestFlight External Testing</h4><p>Add your tester groups or individual testers’ mails to this section and remember that external testing may take some time because it also needs to be reviewed by <strong>Apple</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e-Cs_Cb_konhoG3-571PRQ.png" /></figure><p>In order to fix the warning of the top, go the the <strong>Environment</strong> tab and <strong>check the Clean option</strong>.</p><h4>TestFlight Internal Testing</h4><p>Add your internal testing groups that you have created in the “<strong>App Store Connect</strong>”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3crBYBSwx_nPwx-2c5NYeg.png" /></figure><h4>Notify</h4><p>Actually, it’s the greatest part of the workflow. These workflow steps may take some time therefore we need to know when the workflow is completed. We have <strong>Slack</strong> and <strong>Email</strong> options to be notified when the workflow process is finished. You are able to connect your slack channels and add individual mails easily.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yRSlaRGi41RzrEZCcPwEuQ.png" /></figure><h3><strong>That’s All 🚀</strong></h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F26u4lOMA8JKSnL9Uk%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F26u4lOMA8JKSnL9Uk%2Fgiphy.gif&amp;image=https%3A%2F%2Fmedia4.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExc3Bxam9kNWk1bWxtcmVyeDV3bDZnZHF4NWVzdnJ0cjY2emJiM3RmYSZlcD12MV9naWZzX2dpZklkJmN0PWc%2F26u4lOMA8JKSnL9Uk%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="322" frameborder="0" scrolling="no"><a href="https://medium.com/media/22b4719199411629c39e1ff30ae52b20/href">https://medium.com/media/22b4719199411629c39e1ff30ae52b20/href</a></iframe><blockquote>You can change all the steps according to your needs. I just wanted to tell you the most used and simplest scenario.</blockquote><p>Now just change anything on the branch that you have selected on the “<strong>Start Conditions</strong>” screen, <strong>the workflow</strong> will start. You can manage and check the whole operations under the <strong>Xcode Cloud</strong> menu in the <strong>App Store Connect</strong> page. When the workflow is finished you’ll get a notification from the channel that you selected.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c44a1018c58f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Swift UI — LookAroundMapView ( StreetView )]]></title>
            <link>https://medium.com/@acakiralar/swift-ui-lookaroundmapview-streetview-574a062f1045?source=rss-fb9fdb7f40a6------2</link>
            <guid isPermaLink="false">https://medium.com/p/574a062f1045</guid>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[apple]]></category>
            <category><![CDATA[mapkit]]></category>
            <dc:creator><![CDATA[Alkin Cakiralar]]></dc:creator>
            <pubDate>Mon, 02 Jan 2023 22:52:55 GMT</pubDate>
            <atom:updated>2023-01-02T22:52:55.330Z</atom:updated>
            <content:encoded><![CDATA[<h3>Swift UI — LookAroundMapView ( StreetView )</h3><p>How to implement <strong>LookAroundView</strong> in <strong>SwiftUI</strong></p><figure><img alt="LookAroundView AppleMapKit SwiftUI" src="https://cdn-images-1.medium.com/max/740/1*LG-jNHXNplEzEKJZiFxf1A.png" /><figcaption>Results on Iphone 14 Pro Max</figcaption></figure><h3>Introduction</h3><p>In the following, we will take a look at about the use of LookAroundView, aka street view, which Apple introduced at WWDC22. Nowadays, google map costs can be a little high, so I think it is useful to evaluate alternatives for iOS devices also completely free for apple developer members.</p><h3>The Cons</h3><p>As with every new apple development, we can only use it on the highest iOS version. Here is the compatible version list on <a href="https://developer.apple.com/documentation/mapkit/explore_a_location_with_a_highly_detailed_map_and_look_around"><strong>Apple Documentation</strong></a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/908/1*bs1qxjqpMjTG8y7okeJzPA.png" /></figure><p>In addition, the <strong>LookAroundView</strong> feature can work in certain locations for now. But don’t worry, we will set up a control mechanism accordingly while writing our code 💪. You can check the latest available locations from <a href="https://en.wikipedia.org/wiki/Apple_Look_Around#:~:text=As%20of%20December%202022%2C%20Look,San%20Marino%2C%20Australia%2C%20Germany%2C"><strong>here</strong></a><strong>.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PYvS68AF4k2stjlhi0jbGA.png" /></figure><h3>Let’s Start 🚀</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*lTpLnVRPGu9oKjEX" /></figure><p>First of all open a new Swift UI project and create the following file structure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/868/1*9oZll3tMAiAeBRQ5T0uAsQ.png" /></figure><h3>Info.plist</h3><p>In this file we should add<strong> “Privacy — Location When In Use Usage Description” </strong>to get user location permission request.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gVqKi59H2Mte5jTNA2AH9w.png" /></figure><h3>LocationManager</h3><p>LocationManager will be managing our map location operations.</p><pre>final class LocationManager: NSObject, ObservableObject, CLLocationManagerDelegate {<br>    private let locationManager = CLLocationManager()<br>    <br>    override init() {<br>        super.init()<br>        locationManager.delegate = self<br>        locationManager.desiredAccuracy = kCLLocationAccuracyBest<br>        locationManager.requestWhenInUseAuthorization()<br>        locationManager.startUpdatingLocation()<br>    }<br>}</pre><p>in this class we need to get the user location. For this, we will use “<em>didUpdateLocations” </em>and store the “<em>userLocation”</em> as <strong>published</strong> object.</p><pre>@Published var userLocation: CLLocationCoordinate2D?<br><br>func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {<br>    if userLocation != nil { return }<br>    <br>    guard let location = locations.last else { return }<br>    <br>    userLocation = location.coordinate<br>}</pre><h3>UIViewRepresentable</h3><p>In SwiftUI we can use <strong>UIViewRepresentable</strong> protocol to wrap <strong>UIKit</strong> views and use it as a <strong>SwiftUI</strong> views. In this example we need two wrap class for <strong>MKMapView</strong> and <strong>MKLookAroundViewController</strong></p><h3>MapView Representable</h3><p>To implement <strong>MkMapView </strong>as SwiftUI Object we have to create <strong>MapView</strong> class which inherited by <strong>UIViewRepresentable</strong> protocol.</p><pre>struct MapView: UIViewRepresentable {<br>    typealias UIViewType = MKMapView<br>    <br>    func makeUIView(context: Context) -&gt; MKMapView {<br>        <br>    }<br>    <br>    func updateUIView(_ uiView: MKMapView, context: Context) {<br>        <br>    }<br>}</pre><p>UIViewRepresentable protocol has two mandatory methods “<em>makeUIView”</em> and “<em>updateUIView”</em>.</p><p><strong>makeUIView</strong> works only once when the view is created.</p><p><strong>updateUIView</strong> works when the state of the view changes.</p><p>Let’s define our locationManager class and getting the user location and then set the <strong>MapView</strong> region in <strong>updateUIView</strong> function.</p><pre>@StateObject var locationManager = LocationManager()<br><br>func updateUIView(_ uiView: MKMapView, context: Context) {<br>    if uiView.delegate != nil { return }<br><br>    if let userLocation = locationManager.userLocation {<br>        uiView.setRegion(.init(center: userLocation, latitudinalMeters: 200, longitudinalMeters: 200), animated: false)<br>    }<br>}</pre><p>With this way we move the camera to the user location when the map is initialized.</p><p>And also we need to initialize the MKMapView class in makeUIView as below.</p><pre>func makeUIView(context: Context) -&gt; MKMapView {<br>    let mapView = MKMapView(frame: .zero)<br>    <br>    mapView.showsUserLocation = true<br>    <br>    return mapView<br>}</pre><p>That’s all for now, go to the <strong>LocationScreen</strong> and use the <em>MapView</em> <em>representable</em> class inside of that, then run the application. You should be able to see your current location in the map 🥳.</p><pre>struct LocationScreen: View {<br>    var body: some View {<br>        ZStack {<br>            MapView()<br>        }.ignoresSafeArea(.all)<br>    }<br>}</pre><blockquote>Don’t forget to change the class name as <strong>LocationScreen</strong> under the <strong>WindowGroup</strong> in the <strong>LookAroundMapKitApp</strong> main app class</blockquote><h3>MapViewCoordinator</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*T7Vt_ETaZ4Q53eab" /></figure><blockquote><em>UIViewRepresentable</em> provides a <strong>Coordinator</strong> object that allows us to deal with delegates, data sources, and other <em>UIKit</em> stuff. The coordinator is a bridge between your <em>UIKit</em> and SwiftUI views</blockquote><p>We want to show LookAroundView when user tapped anywhere in the map. For this, we need to add <strong>UITapGestureRecognizer </strong>to our mapView object in <strong>MapView</strong> <em>Representable</em> class. Before that we have to create our <strong>MapViewCoordinator</strong> class.</p><pre>class MapViewCoordinator: NSObject, MKMapViewDelegate {<br>    @Binding var tappedLocation: CLLocationCoordinate2D?<br>    <br>    var mapViewController: MapView<br>        <br>    init(_ mapView: MapView, tappedLocation: Binding&lt;CLLocationCoordinate2D?&gt;) {<br>        self.mapViewController = mapView<br>        self._tappedLocation = tappedLocation<br>    }<br>    <br>    @objc func mapTapped(_ sender: UITapGestureRecognizer) {<br>        guard let mapView = sender.view as? MKMapView else { return }<br>        <br>        let touchLocation = sender.location(in: sender.view) // getting the user touch location<br>        <br>        let locationCoordinate = mapView.convert(touchLocation, toCoordinateFrom: sender.view) // converting the touch location into the real map location<br>        <br>        let annotation = MKPointAnnotation() // creating the new annotation instance<br>        annotation.coordinate = .init(latitude: locationCoordinate.latitude, longitude: locationCoordinate.longitude) // setting the user touch location to theannotation<br>        <br>        self.tappedLocation = locationCoordinate<br>        <br>        mapView.removeAnnotations(mapView.annotations) // clearing the previous annotations<br>        <br>        mapView.addAnnotation(annotation) // adding the user tapped location annotation<br>    }<br>}</pre><p>Let’s go back to the <strong>MapView</strong> class and use the <strong>MapViewCoordinator</strong> like below</p><pre>struct MapView: UIViewRepresentable {<br>    typealias UIViewType = MKMapView<br>    <br>    @Binding var tappedLocation: CLLocationCoordinate2D?<br>    <br>    @StateObject var locationManager = LocationManager()<br>    <br>    func makeUIView(context: Context) -&gt; MKMapView {<br>        let mapView = MKMapView(frame: .zero)<br>        <br>        mapView.showsUserLocation = true<br>        <br>        let mapTap = UITapGestureRecognizer(target: context.coordinator, action: #selector(MapViewCoordinator.mapTapped(_:)))<br>        mapView.addGestureRecognizer(mapTap) // creating touch event on the mapview<br>        <br>        return mapView<br>    }<br>    <br>    func updateUIView(_ uiView: MKMapView, context: Context) {<br>        if uiView.delegate != nil { return }<br><br>        if let userLocation = locationManager.userLocation {<br>            uiView.setRegion(.init(center: userLocation, latitudinalMeters: 200, longitudinalMeters: 200), animated: false)<br>            <br>            uiView.delegate = context.coordinator // setting the coordinator to the MkMapView<br>        }<br>    }<br>    <br>    func makeCoordinator() -&gt; MapViewCoordinator {<br>         MapViewCoordinator(self, tappedLocation: $tappedLocation)<br>    }<br>}</pre><p>So, we bind the <em>tappedLocation</em> object in order to get the last touch point inside the <strong>LocationScreen</strong>.</p><p>Let’s go back to the <strong>LocationScreen</strong> class and define the <em>tappedLocation</em> variable as a <strong>State</strong> object then send it to the <strong>MapView</strong> as a parameter.</p><pre>struct LocationScreen: View {<br>    @State var tappedLocation: CLLocationCoordinate2D?<br><br>    var body: some View {<br>        ZStack {<br>            MapView(tappedLocation: $tappedLocation)<br>        }.ignoresSafeArea(.all)<br>    }<br>}</pre><p>When we run the application and click on anywhere on the map we should be able to see the annotation wherever we tap as below. 🤩</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*NbM5yakcQr8-C-QUXMRbIw.png" /></figure><h3>LookAroundView Representable</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*KamXh6u9tA5N9fxA" /></figure><p>This time we have to create a new representable class to wrap <strong>MKLookAroundViewController </strong>as <em>SwiftUI View.</em></p><pre>struct LookAroundView: UIViewControllerRepresentable {<br>    typealias UIViewControllerType = MKLookAroundViewController<br>    <br>    @Binding var tappedLocation: CLLocationCoordinate2D?<br>    @Binding var showLookAroundView: Bool<br>    <br>    func makeUIViewController(context: Context) -&gt; MKLookAroundViewController {<br>        return MKLookAroundViewController()<br>    }<br>}</pre><p>We define <strong><em>tappedLocation</em></strong> state variable to check if there is any <strong>LookAround</strong> data for the clicked location each time. If there is no data in the clicked location, we define the <strong><em>showLookAroundView</em></strong> binding variable to hide <strong>LookAroundView</strong>.</p><p>In this file, we create a <strong><em>getScene</em></strong> function to check if there is any <strong>LookAroundScene</strong> data.</p><pre>func getScene(tappedLocation: CLLocationCoordinate2D?) async -&gt; MKLookAroundScene? {<br>    if let latitude = tappedLocation?.latitude, let longitude = tappedLocation?.longitude {<br>        let sceneRequest = MKLookAroundSceneRequest(coordinate: .init(latitude: latitude, longitude: longitude))<br><br>        do {<br>            return try await sceneRequest.scene<br>        } catch {<br>            return nil<br>        }<br>    } else {<br>        return nil<br>    }<br>}</pre><p>Each time the state of the <strong>LookAroundView</strong> changes, we check the scene and change the <strong><em>showLookAroundView</em></strong> state.</p><pre>func updateUIViewController(_ uiViewController: MKLookAroundViewController, context: Context) {<br>    if let tappedLocation {<br>        Task {<br>            let scene = await getScene(tappedLocation: .init(latitude: tappedLocation.latitude, longitude: tappedLocation.longitude))<br><br>            if scene == nil {<br>                withAnimation {<br>                    self.showLookAroundView = false<br>                }<br>                return<br>            }<br><br>            withAnimation {<br>                self.showLookAroundView = true<br>            }<br><br>            uiViewController.scene = scene<br>        }<br>    }<br>}</pre><p>Now we go back to the <strong>LocationScreen</strong> class again and use the <strong>LookAroundView</strong> and change the view opacity by data condition with <em>showLookAroundView</em> variable.</p><pre>struct LocationScreen: View {<br>    @State var tappedLocation: CLLocationCoordinate2D?<br>    @State var showLookAroundView: Bool = false<br><br>    var body: some View {<br>        ZStack {<br>            MapView(tappedLocation: $tappedLocation)<br>            LookAroundView(tappedLocation: $tappedLocation,<br>                                           showLookAroundView: $showLookAroundView)<br>                                .frame(width: 250, height: 150)<br>                                .opacity(showLookAroundView ? 1 : 0)<br>                                .cornerRadius(10)<br>        }.ignoresSafeArea(.all)<br>    }<br>}</pre><p>That’s all. Now we are good to go. 🎉 🎉 🎉</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*h-0hmDkcnybgOyS1.gif" /></figure><blockquote>Remember that If you try to click on the map in a region other than the regions I mentioned above, the view will not appear.</blockquote><h3>Bonus Part 🤩</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*ME4E-wugld6m0Gde" /></figure><p>Let’s add drag gesture to our <strong>LookAroundView</strong></p><p>In the <strong>LocationScreen </strong>we need to store the <strong>LookAroundView</strong> position as below</p><pre>@State private var lookAroundViewLocation: CGPoint = .zero</pre><p>And also we need a <strong><em>dragGesture</em></strong> to tell us about the new position of <strong>LookAroundView</strong> each time we change it.</p><pre>var dragGesture: some Gesture {<br>    DragGesture()<br>        .onChanged { value in<br>            self.lookAroundViewLocation = value.location<br>        }<br>}</pre><p>In the body part we just need to add it the lookAroundViewLocation variable to the LookAroundView.position attribute.</p><p>The final result as below;</p><pre>struct LocationScreen: View {<br>    @State var tappedLocation: CLLocationCoordinate2D?<br>    @State var showLookAroundView: Bool = false<br><br>    @State private var lookAroundViewLocation: CGPoint = .zero<br><br>    var body: some View {<br>        GeometryReader { geo in<br>            ZStack {<br>                Color.white.onAppear {<br>                    self.lookAroundViewLocation = .init(x: 150, y: geo.size.height - 100)<br>                }<br>                MapView(tappedLocation: $tappedLocation)<br>                LookAroundView(tappedLocation: $tappedLocation,<br>                               showLookAroundView: $showLookAroundView)<br>                    .frame(width: 250, height: 150)<br>                    .cornerRadius(10)<br>                    .position(lookAroundViewLocation)<br>                    .gesture(dragGesture)<br>                    .opacity(showLookAroundView ? 1 : 0)<br>            }<br>        }.ignoresSafeArea(.all)<br>    }<br>    <br>    var dragGesture: some Gesture {<br>        DragGesture()<br>            .onChanged { value in<br>                self.lookAroundViewLocation = value.location<br>            }<br>    }<br>}</pre><p>You can <strong>download</strong> the source code through the <strong>github</strong> link provided below 🔽</p><p><a href="https://github.com/alkincakiralar1996/LookAroundMapKit">GitHub - alkincakiralar1996/LookAroundMapKit: An example swift UI project about LookAroundMapView</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=574a062f1045" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>