<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Rinalds Domanovs</title>
    <description>The latest articles on Forem by Rinalds Domanovs (@domanovdev).</description>
    <link>https://forem.com/domanovdev</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F608107%2F2205976d-80a1-43ef-8857-8d6eb5628d80.jpg</url>
      <title>Forem: Rinalds Domanovs</title>
      <link>https://forem.com/domanovdev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/domanovdev"/>
    <language>en</language>
    <item>
      <title>Exploring SwiftUI Basic Gestures</title>
      <dc:creator>Rinalds Domanovs</dc:creator>
      <pubDate>Mon, 17 May 2021 08:05:53 +0000</pubDate>
      <link>https://forem.com/domanovdev/exploring-swiftui-basic-gestures-188m</link>
      <guid>https://forem.com/domanovdev/exploring-swiftui-basic-gestures-188m</guid>
      <description>&lt;p&gt;In &lt;code&gt;SwiftUI&lt;/code&gt; we can make our Apps more interactive by adding different interactions that respond on our taps, clicks, and swipes.&lt;/p&gt;

&lt;p&gt;Today we will review &lt;code&gt;SwiftUI&lt;/code&gt; Basic Gestures:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;TapGesture&lt;/li&gt;
&lt;li&gt;LongPressGesture&lt;/li&gt;
&lt;li&gt;DragGesture&lt;/li&gt;
&lt;li&gt;MagnificationGesture&lt;/li&gt;
&lt;li&gt;RotationGesture&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  TapGesture &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Tap gestures allow us to recognise one or more taps on &lt;code&gt;View&lt;/code&gt;.&lt;br&gt;
We have several options how we can add a tap gesture.&lt;/p&gt;

&lt;p&gt;First one is by using &lt;code&gt;.onTapGesture&lt;/code&gt; modifier directly.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;And other option that is being used in &lt;code&gt;SwiftUI&lt;/code&gt; documentation is by creating and configuring a gesture as a property and then use it with &lt;code&gt;.gesture(_:including:)&lt;/code&gt; modifier.&lt;br&gt;
But remember that in order to do something or respond to a tap we need to use &lt;code&gt;.onEnded&lt;/code&gt; action closure that is triggered when the gesture ends.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Actually second approach I like better as in such way we can create different gestures and re-use them through our code.&lt;/p&gt;

&lt;p&gt;So if we put together code we can start making something like this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/kO6Lyz0GluRuZGe3Jz/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/kO6Lyz0GluRuZGe3Jz/giphy.gif" alt="Single Tap"&gt;&lt;/a&gt;&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Similarly we can control on how many taps we want to respond by just using &lt;code&gt;TapGesture(count: Int)&lt;/code&gt; initializer.&lt;br&gt;
In this case case you need to tap 3 times in order to trigger &lt;code&gt;.onEnded&lt;/code&gt; action closure.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/rEn90qFllwX7rzukkI/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/rEn90qFllwX7rzukkI/giphy.gif" alt="Multiple Taps"&gt;&lt;/a&gt;&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h2&gt;
  
  
  LongGesture &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Long Press Gesture allows us to perform action after user has long-pressed our defined time and during the time while user is long-pressing.&lt;/p&gt;

&lt;p&gt;We can set a minimum duration that must be met in order to recognise our long-press gesture. It can be set in &lt;code&gt;LongPressGesture&lt;/code&gt; initialiser.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="kt"&gt;LongPressGesture&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;minimumDuration&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Then we can use &lt;code&gt;.updating&lt;/code&gt; method to perform action during the long-press and &lt;code&gt;.onEnded&lt;/code&gt; to perform action when our gesture is recognised.&lt;/p&gt;

&lt;p&gt;In this example I'm updating &lt;code&gt;Circle()&lt;/code&gt; size and color during the long-press action, and when gesture is recognised I'm showing &lt;code&gt;Text&lt;/code&gt; done.&lt;/p&gt;

&lt;p&gt;Additionally I'm here using a &lt;code&gt;GestureState&lt;/code&gt; property wrapper that is set to &lt;code&gt;true&lt;/code&gt; during the long-press and it's set to &lt;code&gt;false&lt;/code&gt; when the gesture ends. I'm using this property wrapper for sample animations.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/eNHX7pDzqgVSx0CCz6/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/eNHX7pDzqgVSx0CCz6/giphy.gif" alt="LongPressGesture"&gt;&lt;/a&gt; &lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;h2&gt;
  
  
  DragGesture &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Drag Gesture allows us to perform an action when &lt;code&gt;View&lt;/code&gt; is dragged.&lt;/p&gt;

&lt;p&gt;We can take advantage and use &lt;code&gt;.onChanged&lt;/code&gt; and &lt;code&gt;.onEnded&lt;/code&gt; closure methods to perform some action. Both of those methods provide us great attribute &lt;code&gt;DragGesture.Value&lt;/code&gt; that stores the following drag action information:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;location&lt;/li&gt;
&lt;li&gt;predictedEndLocation&lt;/li&gt;
&lt;li&gt;predictedEndTranslation&lt;/li&gt;
&lt;li&gt;startLocation&lt;/li&gt;
&lt;li&gt;time&lt;/li&gt;
&lt;li&gt;translation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We can use this attribute to create movable &lt;code&gt;Views&lt;/code&gt;. In current example I'm using &lt;code&gt;.onChanged&lt;/code&gt; method to update &lt;code&gt;Circle()&lt;/code&gt; location coordinates.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/feZxhEyRtkNuwsDLig/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/feZxhEyRtkNuwsDLig/giphy.gif" alt="DragGesture"&gt;&lt;/a&gt;&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;And here I've added &lt;code&gt;.onEnded&lt;/code&gt; method to reset &lt;code&gt;Circle()&lt;/code&gt; location coordinates when drag has ended.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/MAXVvk8K0bdsn6PlOg/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/MAXVvk8K0bdsn6PlOg/giphy.gif" alt="DragGesture"&gt;&lt;/a&gt;&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h2&gt;
  
  
  MagnificationGesture &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Magnification gesture allows to respond with some action when we are applying a magnification motion on &lt;code&gt;View&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Here we also have &lt;code&gt;.onChanged&lt;/code&gt;, and &lt;code&gt;.onEnded&lt;/code&gt; closures that we can use in order to respond during magnification action or when it's ended. As an attribute we receive &lt;code&gt;MagnificationGesture.Value&lt;/code&gt; that is &lt;code&gt;CGFloat&lt;/code&gt;. We can use this to change &lt;code&gt;View&lt;/code&gt; size as an example.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/hbnMu8vCYGu7DzFcOv/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/hbnMu8vCYGu7DzFcOv/giphy.gif" alt="MagnificationGesture"&gt;&lt;/a&gt;&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h2&gt;
  
  
  RotationGesture &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Rotation gesture allows to rotate &lt;code&gt;View&lt;/code&gt; and respond with some action during rotation and when rotation has ended.&lt;/p&gt;

&lt;p&gt;It also provides us with &lt;code&gt;.onChanged&lt;/code&gt;, and &lt;code&gt;.onEnded&lt;/code&gt; closures that gives us &lt;code&gt;RotationGesture.Value&lt;/code&gt; that represents gestures &lt;code&gt;Angle&lt;/code&gt; value. We can use this value to rotate &lt;code&gt;View&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/zycjf4usBZed4nB6FE/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/zycjf4usBZed4nB6FE/giphy.gif" alt="RotationGesture"&gt;&lt;/a&gt;&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h2&gt;
  
  
  Final thoughts
&lt;/h2&gt;

&lt;p&gt;This was only review of the basic Gestures that &lt;code&gt;SwiftUI&lt;/code&gt; gives us. And we can do a lot with them to make our apps &lt;code&gt;live&lt;/code&gt;. For more advanced use gestures can be combined or used simultaneously to make response or we can make our own custom gestures.&lt;/p&gt;

&lt;p&gt;Follow on &lt;a href="https://twitter.com/domanovdev"&gt;Twitter&lt;/a&gt;.&lt;br&gt;
Link on full project code on &lt;a href="https://github.com/Sangsom/SwiftUI-Basic-Gestures"&gt;GitHub&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>swift</category>
      <category>swiftui</category>
      <category>ios</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Creating in SwiftUI UITextField Representable</title>
      <dc:creator>Rinalds Domanovs</dc:creator>
      <pubDate>Wed, 21 Apr 2021 02:25:02 +0000</pubDate>
      <link>https://forem.com/domanovdev/creating-in-swiftui-uitextfield-representable-490c</link>
      <guid>https://forem.com/domanovdev/creating-in-swiftui-uitextfield-representable-490c</guid>
      <description>&lt;p&gt;There may be cases when you would like bigger control over the &lt;code&gt;TextField&lt;/code&gt; that you are adding in your app. Of course in most cases it's completely fine and enough to use &lt;code&gt;SwiftUI Textfield&lt;/code&gt;, but I recently needed to create a &lt;code&gt;UITextField&lt;/code&gt; representable and to be honest it wasn't so easy to do initially. So I want to share what I did in order to get working solution.&lt;/p&gt;

&lt;h2&gt;
  
  
  Result
&lt;/h2&gt;

&lt;p&gt;For the tutorial we will create a custom &lt;code&gt;URLTextField&lt;/code&gt; that will be used in &lt;code&gt;SwiftUI&lt;/code&gt; app and is a &lt;code&gt;UIViewRepresentable&lt;/code&gt; of &lt;code&gt;UITextField&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Project
&lt;/h2&gt;

&lt;p&gt;Let's start with creating project.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open Xcode.&lt;/li&gt;
&lt;li&gt;Choose an &lt;code&gt;App&lt;/code&gt; template for your new project.
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DaViafPH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/INpWyix.png" alt="New project"&gt;
&lt;/li&gt;
&lt;li&gt;Create project name and make sure that you have selected &lt;code&gt;SwiftUI&lt;/code&gt; interface and life cycle.
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pl8G5Lqe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/3WsBSd8.png" alt="Project name"&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  URLTextField
&lt;/h2&gt;

&lt;p&gt;Now let's make &lt;code&gt;URLTextField&lt;/code&gt; component that will be conforming to &lt;code&gt;UIViewRepresentable&lt;/code&gt; protocol that is a wrapper for &lt;code&gt;UIKit&lt;/code&gt; view which allows us to integrate that view into our &lt;code&gt;SwiftUI&lt;/code&gt;.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create new file &lt;code&gt;Command + N&lt;/code&gt;
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qnTCSNyH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/ROIzyQD.png" alt="Create new file"&gt;
&lt;/li&gt;
&lt;li&gt;Save as &lt;code&gt;URLTextField.swift&lt;/code&gt;
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--raCRaNQw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/uE2qq8P.png" alt="Save as URLTextField.swift"&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now create &lt;code&gt;URLTextField&lt;/code&gt; struct that conforms to &lt;code&gt;UIViewRepresentable&lt;/code&gt; protocol and don't forget to import &lt;code&gt;SwiftUI&lt;/code&gt; framework for the protocol.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Good, now we have error:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;Type 'URLTextField' does not conform to protocol 'UIViewRepresentable'&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So now to satisfy &lt;code&gt;UIViewRepresentable&lt;/code&gt; protocol requirements we need to implement two methods:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;makeUIView()&lt;/code&gt; - here we will create our &lt;code&gt;text field&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;updateUIView()&lt;/code&gt; - it's called whenever data in our text field will be changed&lt;/li&gt;
&lt;/ul&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Actually we can already use this component in our &lt;code&gt;SwiftUI&lt;/code&gt; view. Let's add it to &lt;code&gt;ContentView.swift&lt;/code&gt; file.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;br&gt;
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zMAwDs9c--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/YpIbqo7.png" alt="URLTextField"&gt;&lt;br&gt;
Nice, we have a &lt;code&gt;UITextField&lt;/code&gt; that is configured for typing URLs, but we need something more. &lt;br&gt;
We want it to have a &lt;code&gt;SwiftUI&lt;/code&gt; functionality that allows us to store its value into &lt;code&gt;@State&lt;/code&gt; property wrapper and update it accordingly.&lt;br&gt;
Sounds simple, let's create &lt;code&gt;@Binding&lt;/code&gt; property wrapper inside our &lt;code&gt;URLTextField&lt;/code&gt; struct that will store and update text value. And we can use now our &lt;code&gt;updateUIView&lt;/code&gt; method for updating our view as it should do.


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;And update our &lt;code&gt;ContentView.swift&lt;/code&gt; file. Add &lt;code&gt;@State&lt;/code&gt; property wrapper and pass it to our &lt;code&gt;URLTextField&lt;/code&gt; in order to track typed text.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;It looks good, we have &lt;code&gt;@State&lt;/code&gt; property wrapper that is passed to our &lt;code&gt;URLTextField&lt;/code&gt; &lt;code&gt;@Binding&lt;/code&gt;. &lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;But we still need one more thing, we need to create a &lt;code&gt;delegate&lt;/code&gt; and in order to communicate with our view we need to implement a &lt;code&gt;Coordinator&lt;/code&gt; instance. &lt;br&gt;
Basically in &lt;code&gt;Coordinator&lt;/code&gt; you will create all &lt;code&gt;UITextFieldDelegate&lt;/code&gt; methods that are communicated through &lt;code&gt;makeCoordinator()&lt;/code&gt; method that is required now. And of course set the &lt;code&gt;delegate&lt;/code&gt; property to &lt;code&gt;context.coordinator&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Quite a lot of steps to be done and still not finished yet. Now the last part. We need to add one more &lt;code&gt;@Binding&lt;/code&gt; method for tracking &lt;code&gt;URLTextField&lt;/code&gt; text and we need to update that text manually through &lt;code&gt;textFieldDidChangeSelection()&lt;/code&gt; delegate method. And also we need to use &lt;code&gt;DispatchQueue&lt;/code&gt; in our &lt;code&gt;textFieldDidChangeSelection()&lt;/code&gt; method or we will get an error while typing.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;Modifying state during view update, this will cause undefined behavior.&lt;/code&gt; &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So there is finished code you can use for such cases.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;And here you can see result.&lt;br&gt;
&lt;a href="https://i.giphy.com/media/OC9nORubT4NJbMHwN8/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/OC9nORubT4NJbMHwN8/giphy.gif" alt="URLTextField"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Final thoughts
&lt;/h2&gt;

&lt;p&gt;Of course it's a lot of code just for creating &lt;code&gt;TextField&lt;/code&gt; and as I mentioned previously for the most time you probably will be good for using &lt;code&gt;SwiftUI TextField&lt;/code&gt;, but when I had a need to create more advanced &lt;code&gt;UITextField&lt;/code&gt; where I can have a full power of &lt;code&gt;UITextField&lt;/code&gt; delegate methods it wasn't so easy to understand for me how to implement it. So I wanted to write about it and strenghten my understanding on using &lt;code&gt;UIViewRepresentable&lt;/code&gt; protocol.&lt;/p&gt;

&lt;p&gt;Any critique, comments are highly welcome.&lt;br&gt;
Follow on &lt;a href="https://twitter.com/domanovdev"&gt;Twitter&lt;/a&gt;.&lt;br&gt;
Link on full project code on &lt;a href="https://github.com/Sangsom/URLTextField-Representable"&gt;GitHub&lt;/a&gt;. &lt;/p&gt;

</description>
      <category>swift</category>
      <category>swiftui</category>
      <category>ios</category>
    </item>
    <item>
      <title>SwiftUI Onboarding View</title>
      <dc:creator>Rinalds Domanovs</dc:creator>
      <pubDate>Mon, 19 Apr 2021 12:55:16 +0000</pubDate>
      <link>https://forem.com/domanovdev/swiftui-onboarding-view-1165</link>
      <guid>https://forem.com/domanovdev/swiftui-onboarding-view-1165</guid>
      <description>&lt;p&gt;This post is intended for &lt;code&gt;iOS 14.0+&lt;/code&gt; versions as I'm using &lt;code&gt;PageTabViewStyle&lt;/code&gt; for creating this onboarding view.&lt;/p&gt;

&lt;h2&gt;
  
  
  What we will create
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/cL4ussBwKGLWGxgQYD/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/cL4ussBwKGLWGxgQYD/giphy.gif" alt="Onboarding"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating project
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Open Xcode.&lt;/li&gt;
&lt;li&gt;Choose an &lt;code&gt;App&lt;/code&gt; template for your new project.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2F1j6KfOt.png%3F1" alt="New project"&gt;
&lt;/li&gt;
&lt;li&gt;Create project name and make sure that you have selected &lt;code&gt;SwiftUI&lt;/code&gt; interface and life cycle.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FFymsocJ.png" alt="Project name"&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Project assets
&lt;/h2&gt;

&lt;p&gt;To follow along you can download project assets from &lt;a href="https://github.com/Sangsom/Onboarding-view-weather/tree/main/Project%20Assets" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;.&lt;br&gt;
Or even better find your own images for your onboarding view.&lt;/p&gt;

&lt;p&gt;Take downloaded assets and move them into Xcode project &lt;code&gt;Assets&lt;/code&gt; folder.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FjUDjzsA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FjUDjzsA.png" alt="Project assets"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  TabView
&lt;/h2&gt;

&lt;p&gt;Now let's implement the &lt;code&gt;TabView&lt;/code&gt; structure in our &lt;code&gt;ContentView.swift&lt;/code&gt; file that will be used for this project.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;Create a &lt;code&gt;State&lt;/code&gt; property wrapper that will track which &lt;code&gt;Tab&lt;/code&gt; is currently active.&lt;/li&gt;
&lt;li&gt;Add &lt;code&gt;TabView&lt;/code&gt; with sample views currently that will be later replaced with onboarding views.&lt;/li&gt;
&lt;li&gt;Set &lt;code&gt;.tag&lt;/code&gt; identifiers for each view so &lt;code&gt;SwiftUI&lt;/code&gt; can differentiate our views. &lt;code&gt;Tag&lt;/code&gt; values basically can be any type that conforms to &lt;code&gt;Hashable&lt;/code&gt; protocol. By default these are &lt;code&gt;String&lt;/code&gt;, &lt;code&gt;integers&lt;/code&gt;, &lt;code&gt;floating-point&lt;/code&gt;, and &lt;code&gt;Boolean&lt;/code&gt; values. In our case we are just using &lt;code&gt;Int&lt;/code&gt; values.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If we compile and run our app we now have the following:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FJ75cs9c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FJ75cs9c.png" alt="TabView"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And it doesn't do much. We can't use swipe to change the screen and actually in the bottom you can see that there is empty &lt;code&gt;TabView&lt;/code&gt; appeared that you can tap and views will be changed, but this is not what we want to achieve.&lt;/p&gt;

&lt;p&gt;Add to &lt;code&gt;TabView&lt;/code&gt; following modifier:&lt;br&gt;
&lt;code&gt;.tabViewStyle(PageTabViewStyle())&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;And if you run your app again you will see that the &lt;code&gt;TabView&lt;/code&gt; is disappeared from the bottom, but now you can use swipe control to switch between views. Looks good but we need one more modifier.&lt;br&gt;
&lt;code&gt;.indexViewStyle(PageIndexViewStyle(backgroundDisplayMode: .always))&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This modifier adds to the bottom of our view a paging dots that shows visually on which page you currently are.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/sEZWTJHvSmfOR1Qj9H/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/sEZWTJHvSmfOR1Qj9H/giphy.gif" alt="TabView Swipe"&gt;&lt;/a&gt;&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Basically you have implemented the main part of the onboarding view experience. Now you can create your own &lt;code&gt;SwiftUI&lt;/code&gt; views add it to &lt;code&gt;TabView&lt;/code&gt; and don't forget to assign it's &lt;code&gt;.tag&lt;/code&gt; attribute.&lt;/p&gt;

&lt;p&gt;If you want you can follow to read and see my implementation of onboarding view or use this &lt;code&gt;TabView&lt;/code&gt; structure and create your own.&lt;/p&gt;

&lt;h2&gt;
  
  
  Onboarding Views
&lt;/h2&gt;

&lt;p&gt;For the tutorial we will have 3 onboarding views that have the same structure and style, just different images and text. So we will create re-usable &lt;code&gt;OnboardingView&lt;/code&gt; component to which we will pass &lt;code&gt;OnboardingData&lt;/code&gt; model that contains view images and text.&lt;/p&gt;

&lt;p&gt;Let's start with &lt;code&gt;OnboardingData&lt;/code&gt; struct.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create new &lt;code&gt;Swift File&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Call it &lt;code&gt;OnboardingData.swift&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Create struct.&lt;/li&gt;
&lt;li&gt;And also for the tutorial lets add all our sample data in our &lt;code&gt;OnboardingData&lt;/code&gt; struct itself.&lt;/li&gt;
&lt;li&gt;Additionally we will make this structer  to conform &lt;code&gt;Hashable&lt;/code&gt;, and &lt;code&gt;Identifiable&lt;/code&gt; protocol so we can later use in our &lt;code&gt;ContentView&lt;/code&gt; to iterate through &lt;code&gt;ForEach&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Doing so we will be able to easily iterate through &lt;code&gt;OnboardingData&lt;/code&gt; list and pass data to our onboarding views, and also we will use this four our &lt;code&gt;SwiftUI preview&lt;/code&gt; debugging.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Now when we have created OnboardingData model we can start creating our OnboardingView.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create new &lt;code&gt;SwiftUI View&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Call it &lt;code&gt;OnboardingView.swift&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Create an &lt;code&gt;OnboardingData&lt;/code&gt; property.&lt;/li&gt;
&lt;li&gt;Pass to our preview data to fix the error and allow to see in our assistant window dummy data so we can see and create &lt;code&gt;UI&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;And then create an &lt;code&gt;UI&lt;/code&gt;. Nothing fancy here just two &lt;code&gt;Image&lt;/code&gt; views that are positioned on top of another, two &lt;code&gt;Text&lt;/code&gt; views, and a &lt;code&gt;Button&lt;/code&gt;.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Looks good but lets add a small animation to make it live.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Add &lt;code&gt;@State&lt;/code&gt; property wrapper for holding animation state.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;@State private var isAnimating: Bool = false&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Add scale effect modifier to second image.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;.scaleEffect(isAnimating ? 1 : 0.9)&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Trigger animation when &lt;code&gt;View&lt;/code&gt; will appear. So every time when the user will swipe onboarding view we will get a small scale animation. See the finished &lt;code&gt;OnboardingView.swift&lt;/code&gt; code.&lt;/li&gt;
&lt;/ol&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;And the last thing is update our &lt;code&gt;ContentView.swift&lt;/code&gt; file so we can see our Onboarding views.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;And that's all we have created a nice looking onboarding view.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/cL4ussBwKGLWGxgQYD/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/cL4ussBwKGLWGxgQYD/giphy.gif" alt="Onboarding View"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Final thoughts
&lt;/h2&gt;

&lt;p&gt;If you wonder why I'm resetting &lt;code&gt;isAnimating&lt;/code&gt; state property wrapper on view appearing every time as it already is declared as false, then I did this because I received unexpected behaviour that the animation wasn't triggered smoothly every time I swiped the view. So I did this workaround and it works well. If you have any ideas why is that happening, let me know.&lt;br&gt;
And please leave your critique, comments for this post as it's my first post ever made! I would really appreciate that!&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Thank you!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Follow on &lt;a href="https://twitter.com/domanovdev" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;.&lt;br&gt;
Link on full project code on &lt;a href="https://github.com/Sangsom/Onboarding-view-weather" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>swift</category>
      <category>swiftui</category>
      <category>ios</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
