<?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>DEV Community: Ione Souza Junior</title>
    <description>The latest articles on DEV Community by Ione Souza Junior (@ionixjunior).</description>
    <link>https://dev.to/ionixjunior</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%2F174209%2F56b754fa-829b-4f95-bef0-32c185d7d1fa.png</url>
      <title>DEV Community: Ione Souza Junior</title>
      <link>https://dev.to/ionixjunior</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ionixjunior"/>
    <language>en</language>
    <item>
      <title>Why Understanding, Not Just Generating Code, Still Matters</title>
      <dc:creator>Ione Souza Junior</dc:creator>
      <pubDate>Fri, 02 May 2025 13:12:00 +0000</pubDate>
      <link>https://dev.to/ionixjunior/why-understanding-not-just-generating-code-still-matters-43me</link>
      <guid>https://dev.to/ionixjunior/why-understanding-not-just-generating-code-still-matters-43me</guid>
      <description>&lt;p&gt;In the last few weeks, everybody has been talking about vibe coding and how easily you can develop an entire system, from zero to hero. This is blowing the minds of most people, and I'll talk about it in today's post. But, before talking about vibe coding, I'll talk about "normal coding" 🤔. Let's do it!&lt;/p&gt;

&lt;h2&gt;
  
  
  Normal coding? WTF??
&lt;/h2&gt;

&lt;p&gt;Calm down, guys. I’m a Senior Software Engineer who develops mobile applications, but I’ve been learning Python and Django since February, and I’m using the expression “normal coding” to refer to the default process to develop software: learn, practice, develop, and repeat it over and over again.&lt;/p&gt;

&lt;h3&gt;
  
  
  Learning
&lt;/h3&gt;

&lt;p&gt;I took great courses at Pluralsight. Actually, I completed two Pluralsight paths with a lot of courses in each one. The first one was &lt;a href="https://app.pluralsight.com/paths/skills/python-3" rel="noopener noreferrer"&gt;Python 3 Path&lt;/a&gt;, and the second one was &lt;a href="https://app.pluralsight.com/paths/skills/building-web-applications-with-django" rel="noopener noreferrer"&gt;Building Web Applications with Django Path&lt;/a&gt;. Both are excellent resources to learn and remember how the web works and how to apply these concepts using Python. Maybe you don’t know, but I already worked with web development full time until 2014. So, for me, learning Python and Django was like remembering how to develop for the web.&lt;/p&gt;

&lt;h3&gt;
  
  
  Practicing
&lt;/h3&gt;

&lt;p&gt;Between each course that I took, I developed some tiny applications just for practicing the concepts of each course module. It was a good moment to understand the Python style, main tools, and which code editor provides the best coding experience.&lt;/p&gt;

&lt;p&gt;Fun fact: sometimes I feel a little bit lost when changing the language that I’m coding in. It’s very common to leave Swift and go back to C# and try to create methods using the &lt;code&gt;func&lt;/code&gt; keyword, or just try to put curly braces into Python code to define a function. Does this happen with you too?&lt;/p&gt;

&lt;h3&gt;
  
  
  Developing
&lt;/h3&gt;

&lt;p&gt;When I finished these courses, I started to think about a software to develop, and an Anki board solution came to my mind. I’m studying English, so I like to use an Anki board to practice words and expressions commonly used day-to-day. I know there are a lot of options for this kind of software. Even so, I thought about developing my own flash cards solution, and then I started.&lt;/p&gt;

&lt;h3&gt;
  
  
  The flash cards saga
&lt;/h3&gt;

&lt;p&gt;During the development time, I learned a lot about the Python way to develop and how Django works. If you’re fluent in Python, I truly believe you know about:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Creating a requirements file for each flavor (debug / release) is good to split developer dependencies from production dependencies.&lt;/li&gt;
&lt;li&gt;Adding the folder &lt;code&gt;__pycache__&lt;/code&gt; into the &lt;code&gt;.gitignore&lt;/code&gt; file to avoid putting the Python generated files in version control.&lt;/li&gt;
&lt;li&gt;Using some linter to improve code style and understanding how to configure it.&lt;/li&gt;
&lt;li&gt;Creating a Django app to put your code, because you can’t do this in the main project.&lt;/li&gt;
&lt;li&gt;Mapping your Django models to manage its data in the Django admin.&lt;/li&gt;
&lt;li&gt;Using the debug toolbar to understand the reason for some bottlenecks, mainly when you use the magic Django ORM to load data into an HTML file.&lt;/li&gt;
&lt;li&gt;The importance of the empty &lt;code&gt;__init__.py&lt;/code&gt; file when we create a folder and want to make it a separated package.&lt;/li&gt;
&lt;li&gt;The importance of avoiding using &lt;code&gt;datetime.now()&lt;/code&gt; and replacing it with &lt;code&gt;timezone.now()&lt;/code&gt; to avoid naive datetime.&lt;/li&gt;
&lt;li&gt;And so much more!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I know you, Python developer, already know all of these things, but for me, a newbie in Python and Django, all of it was new.&lt;/p&gt;

&lt;p&gt;I spent two days making this small app, and it was really fun for me. I didn’t use AI for coding, but I used AI just as a consultant, where I validated my plan about how to develop my flash cards app, and asked questions about the Python way to develop software.&lt;/p&gt;

&lt;p&gt;Maybe you think this funny. but during development, I through to create some “interfaces” and make an abstraction until I discover the duck type.&lt;/p&gt;

&lt;p&gt;If you’re feeling curious, &lt;a href="https://github.com/ionixjunior/django-flash-cards" rel="noopener noreferrer"&gt;here is the repository&lt;/a&gt; with the source code.&lt;/p&gt;

&lt;h3&gt;
  
  
  Validation and networking
&lt;/h3&gt;

&lt;p&gt;After version 1.0 was finished, I talked with some colleagues to seek feedback. Where I’m working, there are a lot of great Software Engineers who know a lot about this stack, so I believe they’re the best guys to help me in this learning journey. I received some good feedback about decisions that I made well or not.&lt;/p&gt;

&lt;p&gt;But the main insight is here: I could learn and understand a lot of concepts just by practicing, developing, and seeking feedback from other experienced engineers. Now I feel capable of continuing my project and my journey through Python.&lt;/p&gt;

&lt;h2&gt;
  
  
  The vibe coding idea
&lt;/h2&gt;

&lt;p&gt;After this, I made an experiment: try to reproduce the same Python app just using vibe code, and the result really surprised me.&lt;/p&gt;

&lt;p&gt;To do this, I used &lt;a href="https://code.visualstudio.com" rel="noopener noreferrer"&gt;VS Code&lt;/a&gt;, an extension called &lt;a href="https://cline.bot" rel="noopener noreferrer"&gt;Cline&lt;/a&gt; configured in Act mode, and Gemini 2.5 Pro Preview 03-25, which is amazing. I made two attempts. The first one using a simple and very generic prompt, and a second one using a more detailed prompt. Let’s talk about them.&lt;/p&gt;

&lt;h3&gt;
  
  
  First attempt
&lt;/h3&gt;

&lt;p&gt;The idea here was to create a simple prompt that just expressed the main goal. My script was:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Create a web-based app in Python and Django. This app is a Flash Cards app, where I need to show my decks and have a possibility to open it and study my cards.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;After this, Cline did the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Python version verification.&lt;/li&gt;
&lt;li&gt;The creation of a virtual environment and the activation of it.&lt;/li&gt;
&lt;li&gt;The creation of a Django project.&lt;/li&gt;
&lt;li&gt;The creation of a Django app.&lt;/li&gt;
&lt;li&gt;The registration of the new app into &lt;code&gt;settings.py&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The models creation into &lt;code&gt;models.py&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The creation and execution of migrations.&lt;/li&gt;
&lt;li&gt;The implementation into the &lt;code&gt;views.py&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The insertion of views references into the &lt;code&gt;urls.py&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The HTML creation.&lt;/li&gt;
&lt;li&gt;The models configuration into the Django admin.&lt;/li&gt;
&lt;li&gt;The super user creation into the database.&lt;/li&gt;
&lt;li&gt;The server initialization by command line.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All of it just took a few minutes (or seconds), and I had the entire project created. I tried to open the browser, but I saw a 404 error. Following the vibe coding, I just sought help using a new prompt:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I can’t see the first screen because I get a 404 error. Here is the message: Page not found (404) Request Method: GET Request URL: &lt;a href="http://127.0.0.1:8000/" rel="noopener noreferrer"&gt;http://127.0.0.1:8000/&lt;/a&gt; Using the URLconf defined in flashcards_project.urls, Django tried these URL patterns, in this order: admin/ cards/ The empty path didn’t match any of these. You’re seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Looking at the message, it’s easy to understand, but I did vibe coding here, and I delegated this fix to the AI.&lt;/p&gt;

&lt;p&gt;After this, the project worked very well and I could see my new flash cards app. But there was a problem: when I opened a deck, I saw all my cards, with the front and back text appearing together. My app wasn’t finished properly, because I didn’t provide enough context.&lt;/p&gt;

&lt;p&gt;I thought about continuing talking with the chat to improve this code, but I had another idea: create a detailed prompt.&lt;/p&gt;

&lt;h3&gt;
  
  
  Second attempt
&lt;/h3&gt;

&lt;p&gt;For the second attempt, I thought about a well-detailed prompt. So, here it is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Create a web-based app in Python and Django. This app is a Flash cards app. This app only I’ll use, locally. I don’t have the necessity to publish it. So, to store data, I want to use SQLite. Python needs to be the version 3.11.4, and Django 5.2. This project should be called as “flashcards”, and the main app should be called “core”. Create two models, one for the decks, and another one for cards. The “Deck” model should have the following properties: name (max_length=50), and last_studied (nullable and blank). The “Card” model should have the following properties: deck_id, front (max_length=100), back (max_length=100), last_review_date (nullable and blank), and next_review_date (nullable and blank). The first screen should have my list of decks. In this screen, I want to see the name of the deck, the amount of cards on it, and the last studied date. I can click in a deck and it will open another screen to see the cards. This new screen will show only one card at a time. I want to see the front text of it, and when I click on it, I want to see the back text. Also, when I click on the card to see the back text, the feedback buttons will appear too. These buttons are “again”, “hard”, “good”, and “easy”. When I click on these buttons, I will process a post request form, update the last studied deck, and the last review date and next review date of the card. To calculate the next review date, I want to use a simple implementation of a SRS (Spaced Repetition System). If I click in “again”, add 1 minute from now into the next review date file. If I click in “hard”, add 1 day. “Good”, 3 days. “Easy”, 7 days. Create a class called SimpleSRS to create this logic. So, to get a card, create a CardManager class and assign it into the model. With this, implement a next_card function to filter by deck, the next_review_date greater than the current date or next_review_date is null. Order by next_review_date and get the first result. For these two pages, create a template called base.html. For my decks page, create a file called decks.html. For flash cards, create a flash_card.html. Create a 404.html custom page to handle error requests. To register new decks and cards, use Django admin. It’s enough. Use the following dependencies for the dev environment: django-debug-toolbar, pytest, pylint, pylint-django, python-dotenv. Also, create a README file with instructions about how to use the project and how to prepare the machine to use it.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Okay, maybe I exaggerated a little, but it worked too. I won’t detail all the execution now, because it was very similar, but this second prompt provided me with a new app totally customized based on my input.&lt;/p&gt;

&lt;p&gt;Initially, the app didn’t work. There were problems of syntax in some files, but after some prompts, everything was fine and I had my new flash cards app working as expected. The result was very interesting here.&lt;/p&gt;

&lt;p&gt;An interesting think that I found looking at the Python Debug Toolbar, was a bottleneck on the main screen. Looking at the SQL queries, I saw two queries executing a count to get the total of cards in a deck. When I saw the source code into the HTML file, I found the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{ { deck.card_count } } card{ { deck.card_count|pluralize } }

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Do you see the problem here? When we use the &lt;code&gt;card_count&lt;/code&gt; we’re making a new SQL query on the database. But wait, there are two &lt;code&gt;card_count&lt;/code&gt; references in this line. One for print the result, and another to properly print the “card” word using plural or no, depending of the total of cards. Now, imagine this in a big system. Are prepared to solve all this unwanted issues? Are you prepared to solve all these bottlenecks?&lt;/p&gt;

&lt;p&gt;Another fun fact: I told the prompt to install the pytest dependency, so the AI should create some tests too, right? Unfortunately, no tests were created. Maybe I should make this request explicit.&lt;/p&gt;

&lt;h2&gt;
  
  
  Normal coding or just vibe coding?
&lt;/h2&gt;

&lt;p&gt;The best answer I could provide is: it depends! If you just want a simple and fast solution, and don’t care about the artifacts that AI will generate, vibe coding could work using an advanced model and a good tool like Cline. But if you really want or need to understand what is happening, delegating the entire development to an AI tool can be tricky.&lt;/p&gt;

&lt;p&gt;The point is, it isn’t a problem to create a fast solution using some AI tool, but think about: are you learning something or are you just seeing the code generated and understanding nothing? Are you accepting all generated code without review it and adjusting it to your project standards? If you’re delegating all this work to the AI in your company, maybe you should care about the final solution, because when you commit these files into the version control in the project of your company, it’s your name that appears there as an author, so the responsibility is yours.&lt;/p&gt;

&lt;h2&gt;
  
  
  Polemic: vibe coding can be good for experienced developers and harmful for newbies
&lt;/h2&gt;

&lt;p&gt;This topic can be polemic, but it reflects my point of view about it. Since I started working with software development in 2008, the moments that I really learned a lot were moments that I focused on the three main pillars: learning, practicing, and developing. Sometimes we take shortcuts to evolve faster, or just to finish a task or a job, and there’s no problem. The problem is when we start to do things without understanding them. This can be very bad, mainly if you don’t have experience developing.&lt;/p&gt;

&lt;p&gt;Do you think I’m wrong or have bad feelings about it? It’s not a problem. This post just reflects my bias. Tell me in the comments your thoughts about this post. But just for the record: there are other guys with interesting points of view too:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=6TbuelpcfS4" rel="noopener noreferrer"&gt;Does AI write better code than Humans? - from Lucas Montano&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://addyo.substack.com/p/vibe-coding-is-not-an-excuse-for" rel="noopener noreferrer"&gt;Vibe Coding is not an excuse for low-quality work - from Addy Osmani&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.linkedin.com/posts/rodriveracom_the-more-i-vibe-code-the-more-i-realize-activity-7321495011328495616-WFnq" rel="noopener noreferrer"&gt;Reflections about vibe coding - from Rod Rivera&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I highly recommend you check these contents out, because they provide excellent insights about this reflection.&lt;/p&gt;

&lt;p&gt;To be clear: I like AI tools, and I’m using them a lot day-to-day. But also, I’m continuing to prepare myself, evolving in my career, and learning how to use these tools to boost my work, not replace my job.&lt;/p&gt;

&lt;p&gt;With more ability, maybe I could solve, in the future, issues created today by AI tools, because all of us will need to be better Software Engineers to keep in our jobs.&lt;/p&gt;

</description>
      <category>career</category>
    </item>
    <item>
      <title>The Human Side of Software Engineering: Reflections on Growth and Impact</title>
      <dc:creator>Ione Souza Junior</dc:creator>
      <pubDate>Fri, 31 Jan 2025 00:00:00 +0000</pubDate>
      <link>https://dev.to/ionixjunior/the-human-side-of-software-engineering-reflections-on-growth-and-impact-5aeo</link>
      <guid>https://dev.to/ionixjunior/the-human-side-of-software-engineering-reflections-on-growth-and-impact-5aeo</guid>
      <description>&lt;p&gt;I believe it's not so difficult to understand what makes us successful in our careers, but sometimes we need guidance to move forward. So, I dedicated time to read "The Software Engineer's Guidebook," and I'll share some of my thoughts about it, based on my perspective and experience as a Software Engineer and Team Lead.&lt;/p&gt;

&lt;h2&gt;
  
  
  About the Book
&lt;/h2&gt;

&lt;p&gt;The book, &lt;a href="https://www.engguidebook.com" rel="noopener noreferrer"&gt;“The Software Engineer’s Guidebook - Navigating Senior, Tech Lead, and Staff Engineer Positions at Tech Companies and Startups”&lt;/a&gt;, is written by &lt;a href="https://www.linkedin.com/in/gergelyorosz/" rel="noopener noreferrer"&gt;Gergely Orosz&lt;/a&gt;, author of &lt;a href="https://newsletter.pragmaticengineer.com/about" rel="noopener noreferrer"&gt;The Pragmatic Engineer Newsletter&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In this book, Gergely shares many perceptions and tips based on his experience. From my point of view, this content is a great opportunity to understand the &lt;strong&gt;key points to being successful in your career&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;I’ll be careful not to reveal too many spoilers, but some might be inevitable. I’ll do my best.&lt;/p&gt;

&lt;h2&gt;
  
  
  My Thoughts
&lt;/h2&gt;

&lt;p&gt;Along this reading, I thought about many situations that happened in my career, and I’ll share below the most important insights.&lt;/p&gt;

&lt;h3&gt;
  
  
  Good Advice for Growth
&lt;/h3&gt;

&lt;p&gt;I didn’t feel this book revealed any big surprises. Most of what I read, I understand as basic behavior a Software Engineer should have.&lt;/p&gt;

&lt;p&gt;I believe the last five years acting as a Team Lead changed my perspective, allowing me to understand this book very well. Leading a team helped me see the big picture and understand how to proceed in many situations. Also, this experience allowed me to understand how a company approaches an engineer’s career progression.&lt;/p&gt;

&lt;p&gt;Some things we read don’t make sense until we have experience. I believe some examples might be difficult to understand if you’re in an initial position.&lt;/p&gt;

&lt;p&gt;Don’t worry, because you can and will get there! But here’s my first thought:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This book explained many things I know today, but I wish someone had told me when I started as a developer.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is a good book for people starting as Software Developers who need to understand how professional growth works in a company. It’s also a good book for experienced developers who want to ensure they continue growing and stay on the right track.&lt;/p&gt;

&lt;h3&gt;
  
  
  Take Charge of Your Career
&lt;/h3&gt;

&lt;p&gt;Simply wanting to grow isn’t enough. You need to be in charge of your career. This isn’t your leader’s responsibility; it’s yours. Here’s my second thought:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Think about your career growth and try to answer where you want to be in the next few years. Don’t leave this decision to your leader.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;When you know where you want to go, it’s easier to choose the correct path. I know this can be a challenging and stressful exercise, but only you can do it. Not your colleagues, not your leader, not your company. &lt;strong&gt;You need to be in charge of your career&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Of course, you can ask for help from an experienced person to clarify paths, understand challenges, or discuss experiences, but only you can decide where to go and how to invest your time.&lt;/p&gt;

&lt;h3&gt;
  
  
  Deliver Value
&lt;/h3&gt;

&lt;p&gt;Sometimes we work hard and don’t feel recognized. This causes a bad feeling and demotivation. The best way to avoid this is to stay aligned with your leader to understand what’s most important for delivering value. So:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Talk with your leader to understand how you can deliver value for the team, project, other engineers, or the company.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Don’t give up. Wanting to grow doesn’t guarantee success. &lt;strong&gt;You need to ensure you’re moving in the right direction&lt;/strong&gt; and have opportunities where you are.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Asking for feedback is also important to understand if you’re on the right track, need to improve in some areas, or make adjustments.&lt;/strong&gt; Do this periodically, not just before performance reviews. Remember: &lt;strong&gt;your career is your responsibility, so stay in charge.&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Understand Why
&lt;/h3&gt;

&lt;p&gt;It’s detrimental to start developing a new feature or bug fix without fully understanding it. We might think we’re being productive by making things faster, but that’s often not the case. Sometimes, we fail. To avoid this, keep this in mind:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Ensure you know why you need to achieve an objective. This way, you’ll understand why, how, and when you need to do something because you’ll see the big picture.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Make sure everything is clear&lt;/strong&gt; by asking questions, discussing edge cases and side effects. Don’t forget that when it comes to the code, you’re the expert. Only you can reveal certain details that Product folks, Designers, or Stakeholders might not see.&lt;/p&gt;

&lt;p&gt;Before development, it’s important to see the big picture. This makes it more likely you’ll achieve the expected objective, enabling you to break it down into smaller parts, understand the main difficulties or challenges, and estimate them accurately.&lt;/p&gt;

&lt;h3&gt;
  
  
  Clarify to Get Unstuck
&lt;/h3&gt;

&lt;p&gt;I’ve seen many great developers get stuck on issues, struggling to understand what to do. Try to avoid this by understanding and planning your work, and don’t be afraid to seek help.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Even if a problem is large, break it down to understand the challenges and where you’re focusing your efforts. If you don’t know how to do this, ask for help.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;When you break a large task into smaller parts, you tend to isolate problems when they occur. Because you’re not focused on solving the entire task at once, but on a specific part, it’s easier to understand the real problem. This prevents you from feeling desperate in daily meetings (or any other meeting) because you’re making progress on a specific piece of the larger puzzle.&lt;/p&gt;

&lt;p&gt;Remember: &lt;strong&gt;you don’t need to have all the answers&lt;/strong&gt; , not even as a highly experienced developer. But &lt;strong&gt;you do need to be able to break problems down into smaller parts to create a concise plan.&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Be Aware of Your Level
&lt;/h3&gt;

&lt;p&gt;Seniority level is another important topic. What are the main differences between a Software Developer and a Software Engineer? Have you considered this? Many people think there’s no difference, but I’ll share my perspective. But first, think about this:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Understand, through conversations with your leader and teammates, how you are performing your work.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A Software Developer can write code, debug, and deliver tasks, but a Software Engineer goes deeper. They can plan a feature, discover and discuss requirements, estimate effort, build a solution, ship it, and maintain it. They can handle the entire process.&lt;/p&gt;

&lt;p&gt;A Software Engineer delivers value for the team, not just for themselves. They provide guidance, take initiative, help the team understand software challenges, collaborate effectively, mentor others, and continuously learn. They also understand team and company challenges, quarterly objectives, and can break down large tasks into smaller ones.&lt;/p&gt;

&lt;p&gt;I believe this is somewhat controversial and sometimes subjective. It can affect our egos, but believe me, there’s a big difference between someone who knows how to write code and someone who understands why to write code and how it achieves an objective.&lt;/p&gt;

&lt;p&gt;Ask your leader and teammates about your deliveries. Seek feedback on your work and performance. Ask your colleagues about their perception of your work. Only this way you’ll really understand where you are and what is the best way to proceed. Think about it!&lt;/p&gt;

&lt;h3&gt;
  
  
  It Isn’t All About Code
&lt;/h3&gt;

&lt;p&gt;We often think the fastest way to grow is by learning new technologies, frameworks, or design patterns. But we forget that we work with people on a team, so we also need to improve our soft skills, such as communication (asynchronous and synchronous), time management, and collaboration. Keep this in mind:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Even if you’re working as a developer, you’ll deal with people, and human skills are crucial for growth and making yourself understood.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It’s not just you and the machine. There’s a team with you. Don’t forget it. Always communicate well, providing updates on your issues, meetings, and documenting decisions.&lt;/p&gt;

&lt;h3&gt;
  
  
  Understand When a Task Is Done
&lt;/h3&gt;

&lt;p&gt;It’s amazing to finish an issue and close it, but is that the end? What’s next? Should you follow up to ensure your task or bug fix was applied correctly or solved the main problem? The answer is yes. So, one more thing to keep in mind:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Your task is done when the objective is completed—that is, when your customer confirms everything is okay through feedback.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;We always develop a product for a customer,&lt;/strong&gt; so we need to develop what they need. It’s that simple.&lt;/p&gt;

&lt;h3&gt;
  
  
  Soft Skills Are Crucial (Sometimes More Than Hard Skills)
&lt;/h3&gt;

&lt;p&gt;Another controversial topic. As you grow in your Software Engineering career, your impact increases. You’ll likely make more contributions that affect the whole team, department, or even company, impacting more people with your work. It’s common to use this expertise to work more closely with Product folks, Designers, Stakeholders, and other Managers to understand what’s truly necessary to make a real impact on the company.&lt;/p&gt;

&lt;p&gt;Because of this, foundational abilities are crucial to progressing beyond a Senior Software Engineer career, such as into a Staff Engineer role.&lt;/p&gt;

&lt;p&gt;Don’t neglect human skills. Include developing areas like communication, time management, meeting management, stress management, collaboration, emotional intelligence, active listening, empathy, and conflict resolution in your roadmap. Here’s the tip:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;As much as you might like to just develop, building relationships with others is inevitable for growth and creating a greater impact.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This usually leads to developing leadership skills, and sometimes you might face decisions about which direction to take - just like it happened to me. But don’t be afraid. This will make you stronger and more capable of facing challenges.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;This book has dozens of great tips and pieces of advice, and I’ve shared some of my thoughts about them. While experienced engineers might find some advice familiar, The Software Engineer’s Guidebook provides valuable tips and insights for career progression and is a must-read for those looking to advance to a senior position or beyond.&lt;/p&gt;

&lt;p&gt;Every company is different, and you need to understand the rules and expectations for your current role or future aspirations. But these are the basics, and they tend to work well.&lt;/p&gt;

&lt;p&gt;As I mentioned, I didn’t find any groundbreaking revelations in this book, but I wish someone had told me these things when I started in IT.&lt;/p&gt;

&lt;p&gt;So, if you’re new to this career, I highly recommend this book. If you’re already a Senior or Staff Engineer, this is an excellent resource to remind yourself how you achieved your current role and how to continue growing.&lt;/p&gt;

&lt;p&gt;I hope you enjoyed this post and consider reading the book. Remember that I’ve shared my thoughts based on my experience as a Software Engineer and Team Lead. If you have a different point of view, please share it in the comments. I’d love to discuss it.&lt;/p&gt;

&lt;p&gt;See you in the next post!&lt;/p&gt;

</description>
      <category>career</category>
    </item>
    <item>
      <title>2024 Year in Review</title>
      <dc:creator>Ione Souza Junior</dc:creator>
      <pubDate>Fri, 27 Dec 2024 00:00:00 +0000</pubDate>
      <link>https://dev.to/ionixjunior/2024-year-in-review-4bj</link>
      <guid>https://dev.to/ionixjunior/2024-year-in-review-4bj</guid>
      <description>&lt;p&gt;Before the end of the year seems like the perfect moment to reflect on what we did throughout the year. I believe this is the first year I've done this reflection, and I'll share some of my thoughts with you. Let's talk about 2024 from my career perspective.&lt;/p&gt;

&lt;h2&gt;
  
  
  Blog Posts
&lt;/h2&gt;

&lt;p&gt;Since January, I’ve started writing on my blog again. Initially, I chose a topic I enjoy immensely: Git. I wrote many posts discussing Git commands. I also wrote posts about iOS development and career development. I like sharing content, but the best part is interacting with you through comments. So, thank you to everyone who interacts with me by commenting on posts both on the blog and on &lt;a href="https://www.linkedin.com/in/ionixjunior/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Live Streaming
&lt;/h2&gt;

&lt;p&gt;This year I didn’t create any live streams on my &lt;a href="https://www.youtube.com/ionixjunior" rel="noopener noreferrer"&gt;YouTube&lt;/a&gt; and &lt;a href="https://www.twitch.tv/ionixjunior" rel="noopener noreferrer"&gt;Twitch&lt;/a&gt; channels, but I participated in six live streams on the &lt;a href="https://www.youtube.com/@CanalDotNET" rel="noopener noreferrer"&gt;Canal .NET&lt;/a&gt; and &lt;a href="https://www.youtube.com/@azurebrasilcloud" rel="noopener noreferrer"&gt;Azure Brasil&lt;/a&gt; channels. I appreciated all these opportunities, and I’d like to express my gratitude for them.&lt;/p&gt;

&lt;p&gt;Here are the links to these live streams:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=CLFaMNJRChk" rel="noopener noreferrer"&gt;Automating the Build and Deployment of Mobile Apps in Practice! - First Edition&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=ZfjvroVEa_s" rel="noopener noreferrer"&gt;Automating the Build and Deployment of Mobile Apps in Practice! - Second Edition&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=pOrzMb-YXFM" rel="noopener noreferrer"&gt;Automating the Build and Deployment of Mobile Apps in Practice! - Third Edition&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=qic347r3R2A" rel="noopener noreferrer"&gt;.NET Conf 2024: .NET 9, C# 13, MAUI, ASP.NET, Blazor - First Edition&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=o4GBUUMnedg" rel="noopener noreferrer"&gt;.NET Conf 2024: .NET 9, C# 13, MAUI, ASP.NET, Blazor - Second Edition&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=i6Ef-ex7-3s" rel="noopener noreferrer"&gt;Multiplatform Development with .NET MAUI&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Podcast
&lt;/h2&gt;

&lt;p&gt;This year, a colleague, Fernando Okuma, invited me to participate in an episode of the Lambda3 podcast. It was an amazing experience to talk with him about Git. Thank you so much for inviting me! Below is the link:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://tivit.com/podcast/podcast-401/" rel="noopener noreferrer"&gt;Versioning Branching Strategies&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Study on iOS Development
&lt;/h2&gt;

&lt;p&gt;In 2024, I dedicated time to learning and practicing iOS development. I encountered a lot of great content, and I’ll share some of it with you.&lt;/p&gt;

&lt;h3&gt;
  
  
  Courses
&lt;/h3&gt;

&lt;p&gt;I took several long and short courses.&lt;/p&gt;

&lt;h4&gt;
  
  
  Backfront Plus
&lt;/h4&gt;

&lt;p&gt;First, I started a course at &lt;a href="https://backfront.com.br/backfront-plus" rel="noopener noreferrer"&gt;Backfront Plus&lt;/a&gt;. This platform contains many excellent courses about mobile development, and I found amazing content there. UIKit, ViewCode, and SwiftUI are some examples. If you’re looking for good content at a fair price, this is the platform. Just for the record: this isn’t a paid post. This is a genuine recommendation. I really liked this platform.&lt;/p&gt;

&lt;h4&gt;
  
  
  Functional Programming with Swift
&lt;/h4&gt;

&lt;p&gt;Good content that I found on LinkedIn Learning was the short course called &lt;a href="https://www.linkedin.com/learning/learning-functional-programming-with-swift/welcome" rel="noopener noreferrer"&gt;Learning Functional Programming with Swift&lt;/a&gt;. This course was very simple but very effective for understanding and practicing functional programming using Swift.&lt;/p&gt;

&lt;h4&gt;
  
  
  iOS Development: Architecture
&lt;/h4&gt;

&lt;p&gt;In this course, I learned about fundamental architectural design patterns, SOLID principles, how to build responsive apps, and more concepts about iOS development. It was a good course for learning many details applied to the platform. If you’re interested, here’s the link: &lt;a href="https://www.linkedin.com/learning/ios-development-architecture/the-value-in-architecting-your-apps" rel="noopener noreferrer"&gt;iOS Development: Architecture&lt;/a&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  100 Days of SwiftUI
&lt;/h4&gt;

&lt;p&gt;Another great resource that I used extensively was from Paul Hudson. I started the &lt;a href="https://www.hackingwithswift.com/100/swiftui" rel="noopener noreferrer"&gt;100 Days of SwiftUI&lt;/a&gt; course, but unfortunately, I haven’t finished it yet. After I moved to Brasília, my routine changed, and I needed to rethink my study plan. But if you’re looking for great free content, this is it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Book
&lt;/h3&gt;

&lt;p&gt;I read an excellent book called &lt;a href="https://www.hackingwithswift.com/store/testing-swift" rel="noopener noreferrer"&gt;Testing Swift&lt;/a&gt; by Paul Hudson. I highly recommend it. This book is easy to read, understand, and has great examples. It’s incredible how easy it can be to test iOS apps, and this book helps a lot with that.&lt;/p&gt;

&lt;p&gt;I did other reading as well, but it wasn’t technical, so I won’t describe it here.&lt;/p&gt;

&lt;h3&gt;
  
  
  Open-Source Contribution
&lt;/h3&gt;

&lt;p&gt;Unlike previous years, I didn’t start any clone app projects this year. Instead, I started contributing to an open-source project, programming in real software. I found a welcoming community in the &lt;a href="https://github.com/mozilla-mobile/firefox-ios" rel="noopener noreferrer"&gt;Firefox iOS&lt;/a&gt; project and jumped in.&lt;/p&gt;

&lt;p&gt;I started contributing with small pull requests, of course. My first pull request refactored a font reference, and then I started resolving some linter issues. I continue helping with linter issues, but I’m now committed to a large refactor, which has been an amazing experience, and I’m learning a lot from this great team.&lt;/p&gt;

&lt;p&gt;Throughout the year, I made more than 40 pull requests, helping the Firefox iOS team enable some linter rules, make font updates, and resolve a flaky unit test. Thank you to all Firefox iOS team members for your patience and for helping me achieve these goals! You’re all doing great work and have a well-organized project.&lt;/p&gt;

&lt;h2&gt;
  
  
  Study on CI/CD
&lt;/h2&gt;

&lt;p&gt;Recently, I faced some challenges using Azure DevOps Pipelines to build an app, and I found a course on Udemy called &lt;a href="https://www.udemy.com/course/azurepipelines/" rel="noopener noreferrer"&gt;Azure Pipelines - CI/CD, Docker and Kubernetes in Azure DevOps&lt;/a&gt;. This is a good course for understanding Azure Pipelines, from beginner to advanced topics. I didn’t complete all the lessons, as I needed help with a very specific topic, but if you need more advanced information, this is a great course to check out.&lt;/p&gt;

&lt;h2&gt;
  
  
  Leaving Team Leadership
&lt;/h2&gt;

&lt;p&gt;2024 was a year of another career change. Since 2020, I’ve been working as a team leader. In this role, I faced many challenges, which helped me grow significantly in soft skills — communication, difficult conversations, emotional intelligence, time management, team management, and delegation. I feel these skills are sometimes neglected by developers, but they contribute significantly to career growth, especially for those who work from home.&lt;/p&gt;

&lt;p&gt;After this period of leading a team, I felt the need to refocus on my personal growth in my tech career. So, since the end of 2023, I’ve been discussing this with my leadership, and we created a plan to find another leader for the team, allowing me to return to focusing on mobile development. Now, at the end of 2024, we’ve found someone, and this will allow me to finalize my plan at the beginning of 2025.&lt;/p&gt;

&lt;h2&gt;
  
  
  2025 is Coming
&lt;/h2&gt;

&lt;p&gt;2024 is ending, and 2025 is coming. Now is the best time to reflect on everything we’ve done, what worked and what didn’t, and think about the next year, ensuring we choose a path that makes sense for us.&lt;/p&gt;

&lt;p&gt;Thank you for your attention, and see you next year!&lt;/p&gt;

</description>
      <category>career</category>
    </item>
    <item>
      <title>Taking Pauses is Okay, But Not Planning Can Be Costly</title>
      <dc:creator>Ione Souza Junior</dc:creator>
      <pubDate>Fri, 04 Oct 2024 00:00:00 +0000</pubDate>
      <link>https://dev.to/ionixjunior/taking-pauses-is-okay-but-not-planning-can-be-costly-2f9h</link>
      <guid>https://dev.to/ionixjunior/taking-pauses-is-okay-but-not-planning-can-be-costly-2f9h</guid>
      <description>&lt;p&gt;Hello, everyone! I'm back after a short break. Recently, I changed my routine and it became challenging to write every week. Since I love sharing knowledge, I'm excited to be back. This past month has given me a lot to think about, so I want to share some thoughts with you. I hope you enjoy today's post.&lt;/p&gt;

&lt;p&gt;Last month, my wife and I moved to a new city. This wasn’t our first rodeo – we’ve moved several times in our relationship (five by my count!). Moving is always time-consuming, so I took a short break to get settled into our new apartment, office, and routines.&lt;/p&gt;

&lt;p&gt;Personally, I’m not a big fan of breaks. It’s easy to get used to doing nothing, especially when you’re tired. However, sometimes breaks are essential for recharging and moving forward. That’s what I want to discuss today.&lt;/p&gt;

&lt;p&gt;I thrive on routine. I schedule all my tasks and try to stick to my daily and weekly plans. Of course, unexpected things happen, but having a plan helps me readjust.&lt;/p&gt;

&lt;p&gt;But what happens to your routine when you’re moving or facing a wave of new responsibilities? That’s the big question I’ve grappled with these past few weeks.&lt;/p&gt;

&lt;p&gt;To avoid frustration, understanding the situation is crucial. But are you truly prepared for it? Ask yourself: what happens when your carefully laid plans need to change direction? What if you realize something can’t continue? What if you need a pause before moving forward?&lt;/p&gt;

&lt;h2&gt;
  
  
  Embrace the Changes
&lt;/h2&gt;

&lt;p&gt;As I mentioned, I live by my calendar. It holds my work schedule, personal appointments – everything. It’s what works for me. Others might prefer reminders, notebooks, or even their memory (personally, I don’t trust mine!).&lt;/p&gt;

&lt;p&gt;My recent move was only about 62 miles (100 kilometers), but it still required time and attention. I had to accept that I wouldn’t be able to focus on writing and maintaining my blog schedule consistently. Recognizing this reality helped me avoid a lot of unnecessary frustration.&lt;/p&gt;

&lt;p&gt;I’m a very pragmatic person. I like things planned, organized, and under control. Much of what I faced during the move fell outside these ideals, so it was vital to mentally prepare myself.&lt;/p&gt;

&lt;p&gt;While I did consider writing posts in advance, I had to remind myself that I’m not a machine. I have a family, I need to prioritize my health, and sometimes life simply gets in the way.&lt;/p&gt;

&lt;p&gt;These are simple yet crucial things to acknowledge. Failing to recognize the changes happening around you and adapt your routine accordingly can lead to intense frustration and burnout.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Power of the Pause
&lt;/h2&gt;

&lt;p&gt;Short breaks offer a fresh perspective. When we’re caught in the flow, it’s easy to overlook details. Breaks allow us to zoom out.&lt;/p&gt;

&lt;p&gt;Taking a step back provides the opportunity to course-correct and make sure you’re still on the right track. For instance, I have a career path planned out, and every three months, I dedicate time to reflect on my progress. While I have “checkpoint days” scheduled, short breaks offer additional moments for this valuable exercise.&lt;/p&gt;

&lt;p&gt;Whether you have designated checkpoints or take spontaneous pauses, these moments are crucial for evaluating if things are progressing as intended.&lt;/p&gt;

&lt;h3&gt;
  
  
  Reflecting on Achievements
&lt;/h3&gt;

&lt;p&gt;When we fall short of our goals, it’s easy to feel like failures. I’m very self-critical, so when I don’t achieve something, my instinct is to assume I’m doing something wrong.&lt;/p&gt;

&lt;p&gt;However, this isn’t a healthy or productive mindset. It can seriously hinder our motivation. I’m actively working on shifting this perspective and focusing on both successes and setbacks. The goal is to understand what’s working, why something went wrong, and how to adjust.&lt;/p&gt;

&lt;p&gt;This reflection is vital. Without it, we risk repeating the same mistakes. And trust me, it’s not easy to self-reflect, especially for us software engineers! But developing this self-awareness is crucial, even (or perhaps especially) in a technical field. We need soft skills too.&lt;/p&gt;

&lt;h3&gt;
  
  
  Embracing Necessary Changes
&lt;/h3&gt;

&lt;p&gt;Sticking to a plan is great, but what happens when change is unavoidable? Are you willing to adapt to ensure the success of your journey?&lt;/p&gt;

&lt;p&gt;Recognizing and understanding changes – whether due to internal factors or external events – is essential for maintaining motivation. Short breaks can clear the fog and help you see the bigger picture.&lt;/p&gt;

&lt;p&gt;By understanding &lt;em&gt;what&lt;/em&gt; changed and &lt;em&gt;why&lt;/em&gt;, you can make informed decisions and continue progressing on your journey.&lt;/p&gt;

&lt;h3&gt;
  
  
  Reconnecting with Your Motivation
&lt;/h3&gt;

&lt;p&gt;It’s okay to realize that what you’re doing no longer resonates with you. Our passions and goals evolve. Regularly checking in with yourself ensures you’re staying true to what motivates and excites you.&lt;/p&gt;

&lt;h2&gt;
  
  
  Back on Track
&lt;/h2&gt;

&lt;p&gt;Getting back into a routine after a break can be challenging. For me, it’s a battle against inertia. It’s so easy to get comfortable doing nothing. But inaction leads to stagnation, and I know that ultimately, it’s up to me to make things happen.&lt;/p&gt;

&lt;p&gt;I find that once I push through the initial resistance and stick to my routine for a few days, things start to flow naturally again. So, don’t be discouraged! The first step is always the hardest. Once you take it, the rest becomes easier.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Importance of Focus
&lt;/h2&gt;

&lt;p&gt;It might seem counterintuitive, but I often find myself self-sabotaging. A demanding routine can lead to exhaustion, making it tempting to give up at the end of the day. This is where discipline is critical. Without it, it’s easy to lose sight of your goals and veer off track.&lt;/p&gt;

&lt;h2&gt;
  
  
  Keep Moving Forward
&lt;/h2&gt;

&lt;p&gt;Life is full of unexpected twists and turns. We might feel tempted to power through without pausing, but sometimes the most productive thing we can do is hit the reset button. And that’s where planning comes in. It might seem counterintuitive when you’re feeling overwhelmed, but having a plan, even a flexible one, can be your saving grace during times of change. Without a roadmap, even a loose one, it’s incredibly easy to get lost in the chaos, lose motivation, and potentially make decisions that don’t align with your long-term goals.&lt;/p&gt;

&lt;p&gt;So, take that break when you need it, embrace the changes that come your way, and don’t be afraid to adjust your plans. The journey might not always be linear, but with a bit of focus and self-awareness, you’ll keep moving forward.&lt;/p&gt;

&lt;p&gt;See you in the next post!&lt;/p&gt;

</description>
      <category>career</category>
    </item>
    <item>
      <title>SwiftUI Basics: Project Structure, Views, and Previews</title>
      <dc:creator>Ione Souza Junior</dc:creator>
      <pubDate>Fri, 09 Aug 2024 00:00:00 +0000</pubDate>
      <link>https://dev.to/ionixjunior/swiftui-basics-project-structure-views-and-previews-4fcd</link>
      <guid>https://dev.to/ionixjunior/swiftui-basics-project-structure-views-and-previews-4fcd</guid>
      <description>&lt;p&gt;This is a new post of the "100 Days of SwiftUI" series. In today's post we'll embark on a fundamental journey: understanding the core structure of a SwiftUI app. We'll demystify the Xcode project setup and explore the essential building blocks of every SwiftUI masterpiece. Let's get started!&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating a New SwiftUI Project
&lt;/h2&gt;

&lt;p&gt;To create a new SwiftUI project is very simple. Just open Xcode and click on “Create New Project” option. Another way is pressing the shortcut &lt;code&gt;CMD + SHIFT + N&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fionixjunior.dev%2Fassets%2Fimg%2Fxcode-create-new-project.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fionixjunior.dev%2Fassets%2Fimg%2Fxcode-create-new-project.webp" alt="Xcode welcome screen with “Create New Project…” highlighted." width="800" height="400"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Launch Xcode and start a new project.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;You’ll see a screen to choose a template to you new project. Select “Multiplatform” menu, and them the “App” option on “Application” section. The multiplatform option will ensure you’ll create a new SwiftUI app, compatible with other platforms. Press “Next”.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fionixjunior.dev%2Fassets%2Fimg%2Fxcode-select-multiplatform-app-template.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fionixjunior.dev%2Fassets%2Fimg%2Fxcode-select-multiplatform-app-template.webp" alt="Xcode project template selection window with “App” template selected." width="800" height="400"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Choose the "App" template under the multiplatform tab.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;You’ll see a screen to choose some options for your new project. Let’s see about them:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Product Name&lt;/strong&gt; : This is the name of your project. Think about it, because it will be used on bundle identifier too.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Team&lt;/strong&gt; : This is your Apple developer account team. For a new “hello world” app, just keep it as “None”.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Organization Identifier&lt;/strong&gt; : Here is the prefix of your app bundle. On my machine, the default bundle is “dev.ionixjunior”, and you can change it for your apps.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Bundle Identifier&lt;/strong&gt; : This is the result of your organization identifier and the product name.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Storage&lt;/strong&gt; : In this option you can select if you want to use Core Data or SwiftData. Just keep it as “None”.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Also, there’s another two checkboxes: “Host in CloudKit” and “Include Tests”. Ensure they’re unselected and click “Next”. I’ve defined the product name of my app as “Sample App”.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fionixjunior.dev%2Fassets%2Fimg%2Fxcode-set-project-name-swiftui.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fionixjunior.dev%2Fassets%2Fimg%2Fxcode-set-project-name-swiftui.webp" alt="Xcode project options with “Product Name” field highlighted." width="800" height="400"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Give your project a name.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Now, you need to choose the location where you want to save your new project. If you want to create a local Git repository on your machine, select the option “Create Git repository on my Mac”. Press “Create”.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fionixjunior.dev%2Fassets%2Fimg%2Fxcode-create-git-repository.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fionixjunior.dev%2Fassets%2Fimg%2Fxcode-create-git-repository.webp" alt="Xcode project creation with “Create Git repository on my Mac” option checked." width="800" height="400"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Optionally, initialize a Git repository for version control.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The Xcode project will open, and we’ll talk about it now.&lt;/p&gt;
&lt;h2&gt;
  
  
  Exploring the Xcode Workspace
&lt;/h2&gt;

&lt;p&gt;When a SwiftUI new project open, we can split the Xcode Workspace in five different main areas: Navigator Area, Editor Area, Preview Canvas, Inspector Area, and Debug Area. Let’s talk about each one.&lt;/p&gt;
&lt;h3&gt;
  
  
  Navigator Area
&lt;/h3&gt;

&lt;p&gt;Maybe this is the most important area of the project, because we can find our core files there. He’s located on the left side of Xcode workspace, as you can see below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fionixjunior.dev%2Fassets%2Fimg%2Fxcode-navigator-area.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fionixjunior.dev%2Fassets%2Fimg%2Fxcode-navigator-area.webp" alt="Xcode workspace with Project Navigator, ContentView.swift, and the Preview Canvas visible." width="800" height="400"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;The Navigator Area (highlighted) is where you find the files of your project.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Note we have a lot of tabs located in this area - nine in total, but the first one is selected, and it is showing the core files of our new project. This first tab is called “Project navigator”, and you can easily show the content from it hitting the shortcut &lt;code&gt;CMD + 1&lt;/code&gt;. All other tabs has a shortcut too, from &lt;code&gt;CMD + 1&lt;/code&gt; to &lt;code&gt;CMD + 9&lt;/code&gt;, as you can see below.&lt;/p&gt;


    
    Your browser does not support video playback.


&lt;p&gt;A quick overview about these tabs and shortcuts:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Tab&lt;/th&gt;
&lt;th&gt;Shortcut&lt;/th&gt;
&lt;th&gt;Functionality&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Project navigator&lt;/td&gt;
&lt;td&gt;&lt;code&gt;CMD + 1&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Is where the files of the project are located&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Source control navigator&lt;/td&gt;
&lt;td&gt;&lt;code&gt;CMD + 2&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Is where you can see information about the source control changes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Bookmark navigator&lt;/td&gt;
&lt;td&gt;&lt;code&gt;CMD + 3&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Is where you can see your code bookmarks&lt;br&gt;You can add / remove them to easily find some code&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Find navigator&lt;/td&gt;
&lt;td&gt;&lt;code&gt;CMD + 4&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Is where you can make a search query on your project files&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Issue navigator&lt;/td&gt;
&lt;td&gt;&lt;code&gt;CMD + 5&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Is where you can see the project warnings&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Test navigator&lt;/td&gt;
&lt;td&gt;&lt;code&gt;CMD + 6&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Is where you can see the unit and UI tests of your project&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Debug navigator&lt;/td&gt;
&lt;td&gt;&lt;code&gt;CMD + 7&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Is where you can see debug information when you run your app and stop at a breakpoint&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Breakpoint navigator&lt;/td&gt;
&lt;td&gt;&lt;code&gt;CMD + 8&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Is where you can see all of your project breakpoints&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Report navigator&lt;/td&gt;
&lt;td&gt;&lt;code&gt;CMD + 9&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Is where you can see reports about the app compilation, like warnings, time compilation, and test coverage&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;
&lt;h3&gt;
  
  
  Editor Area
&lt;/h3&gt;

&lt;p&gt;The heart of your coding. Here is the location where your code is written and edited.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fionixjunior.dev%2Fassets%2Fimg%2Fxcode-editor-area-swiftui-code.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fionixjunior.dev%2Fassets%2Fimg%2Fxcode-editor-area-swiftui-code.webp" alt="Xcode Editor Area highlighted, showing ContentView.swift code." width="800" height="400"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;The Editor Area (highlighted) is where you write and edit your SwiftUI code.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;To show a file here, you just go to project navigator, choose a file, and it will appear on editor area.&lt;/p&gt;
&lt;h3&gt;
  
  
  Preview Canvas
&lt;/h3&gt;

&lt;p&gt;Here we can show the real-time magic of SwiftUI previews. This definitely a killer feature of SwiftUI, because it helps a lot the development workflow providing real-time preview of the screen developed.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fionixjunior.dev%2Fassets%2Fimg%2Fxcode-preview-canvas-swiftui.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fionixjunior.dev%2Fassets%2Fimg%2Fxcode-preview-canvas-swiftui.webp" alt="Xcode Preview Canvas highlighted, displaying a preview of the ContentView." width="800" height="400"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;The Preview Canvas (highlighted) gives you an instant view of your UI.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This preview is very interesting. As you can see on the image above, it appears when you type the &lt;code&gt;#Preview&lt;/code&gt; code, like this:&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="cp"&gt;#Preview {&lt;/span&gt;
    &lt;span class="kt"&gt;ContentView&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code won’t ship when you publish your app on Apple Store, it’s only works under development. A nice think that I discovered recently is it works with UIKit too. It helps a lot to prototype some screen or UI component. Try it!&lt;/p&gt;

&lt;h3&gt;
  
  
  Inspector Area
&lt;/h3&gt;

&lt;p&gt;This is a hidden area when you create a new project, but you can show it hitting a top right button from Xcode toolbar. When you open it, you’ll see a contextualized area based on selected view elements.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fionixjunior.dev%2Fassets%2Fimg%2Fxcode-inspector-area.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fionixjunior.dev%2Fassets%2Fimg%2Fxcode-inspector-area.webp" alt="Xcode Inspector Area with ContentView settings displayed." width="800" height="400"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Use the Inspector to adjust view properties and settings without coding.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This area contains 5 tabs&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Tab&lt;/th&gt;
&lt;th&gt;Shortcut&lt;/th&gt;
&lt;th&gt;Functionality&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;File inspector&lt;/td&gt;
&lt;td&gt;&lt;code&gt;CMD + OPTION + 1&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Show information about the selected file&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;History inspector&lt;/td&gt;
&lt;td&gt;&lt;code&gt;CMD + OPTION + 2&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Show information about project history (Git commits)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Help inspector&lt;/td&gt;
&lt;td&gt;&lt;code&gt;CMD + OPTION + 3&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Show technical information about selected elements in the file&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Accessibility inspector&lt;/td&gt;
&lt;td&gt;&lt;code&gt;CMD + OPTION + 5&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Show information about screen accessibility&lt;br&gt;(I didn’t see this tab working until now, so please let me know if you know how to do it)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Attributes inspector&lt;/td&gt;
&lt;td&gt;&lt;code&gt;CMD + OPTION + 4&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Show information about the selected element on screen&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;


    
    Your browser does not support video playback.

&lt;h3&gt;
  
  
  Debug Area
&lt;/h3&gt;

&lt;p&gt;This is a dedicated area to use when you’re running your app. In this area you can interact when you create a breakpoint on your app and need to see values on variables or objects. To see it, click on the button located at bottom right side, and you’ll see a spliced area that will can contain values when you’re running your app.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fionixjunior.dev%2Fassets%2Fimg%2Fxcode-debug-area.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fionixjunior.dev%2Fassets%2Fimg%2Fxcode-debug-area.webp" alt="Xcode Debug Area that shows app information when it's running." width="800" height="400"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Use the Debug Area to see information when your app is running.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Now you know about the Xcode workspace, let’s explore about the SwiftUI code.&lt;/p&gt;
&lt;h2&gt;
  
  
  Exploring the SwiftUI Code
&lt;/h2&gt;

&lt;p&gt;Now that you’ve set up your SwiftUI project and understand the basics of Xcode, let’s explore the core code that brings your app to life. Let’s see the main file.&lt;/p&gt;
&lt;h3&gt;
  
  
  “YourAppName.swift” file
&lt;/h3&gt;

&lt;p&gt;Now I’m seeing that “Sample App” isn’t a good name for the app, because SwiftUI create a file called “your app name” + “App”. So, my file is called &lt;code&gt;Sample_AppApp.swift&lt;/code&gt; 😂. But that’s okay, no problem.&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="kd"&gt;import&lt;/span&gt; &lt;span class="kt"&gt;SwiftUI&lt;/span&gt;

&lt;span class="kd"&gt;@main&lt;/span&gt;
&lt;span class="kd"&gt;struct&lt;/span&gt; &lt;span class="kt"&gt;Sample_AppApp&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;App&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;some&lt;/span&gt; &lt;span class="kt"&gt;Scene&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;WindowGroup&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="kt"&gt;ContentView&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;@main&lt;/code&gt; attribute above the struct declaration might seem subtle, but it’s crucial. It signals to Xcode that this structure, &lt;code&gt;Sample_AppApp&lt;/code&gt;, serves as the entry point of your application. Think of it as the “front door” where execution begins.&lt;/p&gt;

&lt;p&gt;The struct &lt;code&gt;Sample_AppApp: App&lt;/code&gt; line defines your app’s overall structure and behavior. This means &lt;code&gt;Sample_AppApp&lt;/code&gt; conforms to the &lt;code&gt;App&lt;/code&gt; protocol. By conforming to &lt;code&gt;App&lt;/code&gt;, you’re telling SwiftUI that this structure knows how to assemble and manage the different parts of your application.&lt;/p&gt;

&lt;p&gt;Inside the body property of your app structure, you’ll find the &lt;code&gt;WindowGroup&lt;/code&gt;. This powerful element determines what users see on their screens.&lt;/p&gt;

&lt;p&gt;Within the &lt;code&gt;WindowGroup&lt;/code&gt;, you’ll usually see &lt;code&gt;ContentView()&lt;/code&gt;, witch creates an instance of another SwiftUI view called &lt;code&gt;ContentView&lt;/code&gt;. Your &lt;code&gt;ContentView.swift&lt;/code&gt; file (created automatically by Xcode) is where you’ll start building the actual user interface of your app.&lt;/p&gt;

&lt;p&gt;In essence, the code in the &lt;code&gt;Sample_AppApp.swift&lt;/code&gt; sets the stage by defining the entry point, app structure, and the initial view (&lt;code&gt;ContentView&lt;/code&gt;) that users will see when they launch your app.&lt;/p&gt;

&lt;p&gt;In the next section, we’ll dive into &lt;code&gt;ContentView.swift&lt;/code&gt; and start crafting the visual elements of your SwiftUI masterpiece!&lt;/p&gt;

&lt;h3&gt;
  
  
  ContentView.swift file
&lt;/h3&gt;

&lt;p&gt;Let’s dive into &lt;code&gt;ContentView.swift&lt;/code&gt;, the heart of your SwiftUI app. Open it up, and you’ll see a structure similar to this:&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="kd"&gt;import&lt;/span&gt; &lt;span class="kt"&gt;SwiftUI&lt;/span&gt;

&lt;span class="kd"&gt;struct&lt;/span&gt; &lt;span class="kt"&gt;ContentView&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;View&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;some&lt;/span&gt; &lt;span class="kt"&gt;View&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;VStack&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="kt"&gt;Image&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;systemName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"globe"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;imageScale&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;large&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;foregroundStyle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tint&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="kt"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello, world!"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;accessibilityLabel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"hello"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;accessibilityAction&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"teste"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt;
                &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;accessibilityHint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hellou"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="cp"&gt;#Preview {&lt;/span&gt;
    &lt;span class="kt"&gt;ContentView&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The line &lt;code&gt;struct ContentView: View&lt;/code&gt; declares a structure named &lt;code&gt;ContentView&lt;/code&gt; that conforms to the &lt;code&gt;View&lt;/code&gt; protocol. This is how you create all visual elements in SwiftUI.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;body&lt;/code&gt; is where the magic happens. This computed property is responsible for defining the appearance and layout of your view.&lt;/p&gt;

&lt;p&gt;Inside the &lt;code&gt;body&lt;/code&gt;, you’ll find SwiftUI views that make up your UI. The default code includes a simple &lt;code&gt;Image&lt;/code&gt; and &lt;code&gt;Text&lt;/code&gt; views.&lt;/p&gt;

&lt;p&gt;Below &lt;code&gt;ContentView&lt;/code&gt;, you’ll notice &lt;code&gt;#Preview&lt;/code&gt; block. This enables SwiftUI’s incredible live previews using the Preview Canvas.&lt;/p&gt;

&lt;p&gt;With this foundation, you’re well on your way to crafting beautiful and interactive user interfaces in SwiftUI. The possibilities are limitless, and we explore some of them in the next blog posts.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrap up
&lt;/h2&gt;

&lt;p&gt;You’ve taken your first steps into the world of SwiftUI, and you’ve already got a good grasp of the basics. You know how to set up a new Xcode project, know about the Xcode workspace, and understand the roles of key elements like &lt;code&gt;@main&lt;/code&gt;, &lt;code&gt;App&lt;/code&gt;, &lt;code&gt;WindowGroup&lt;/code&gt;, and &lt;code&gt;ContentView&lt;/code&gt;. Plus, you’ve experienced the magic of SwiftUI Previews, which give you instant feedback as you code.&lt;/p&gt;

&lt;p&gt;But this is just the beginning! There’s so much more to learn and explore in SwiftUI. Get ready to master layout techniques, create dynamic user interfaces with data, and build smooth navigation between different parts of your app.&lt;/p&gt;

&lt;p&gt;Keep experimenting, have fun, and never stop learning. The possibilities with SwiftUI are limitless, and you’re well on your way to creating incredible apps.&lt;/p&gt;

&lt;p&gt;See you in the next post!&lt;/p&gt;

</description>
      <category>100daysofswiftui</category>
    </item>
    <item>
      <title>Swift Essentials: Protocols, Extensions, and Optionals (Part 4)</title>
      <dc:creator>Ione Souza Junior</dc:creator>
      <pubDate>Fri, 02 Aug 2024 00:00:00 +0000</pubDate>
      <link>https://dev.to/ionixjunior/swift-essentials-protocols-extensions-and-optionals-part-4-1po</link>
      <guid>https://dev.to/ionixjunior/swift-essentials-protocols-extensions-and-optionals-part-4-1po</guid>
      <description>&lt;p&gt;We're back with the "100 Days Of SwiftUI" posts! In today's post, we'll continue the Swift Essentials series, exploring protocols, extensions, and optionals. This will be the final installment on Swift Essentials. Let's get started.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Is a Protocol?
&lt;/h2&gt;

&lt;p&gt;To simplify things: protocols are like interfaces. I’m not sure why Apple changed the terminology, but there you have it. In the Apple world, you’ll see a lot of this, as much of iOS development is based on protocol-oriented programming (POP).&lt;/p&gt;

&lt;h3&gt;
  
  
  How to Create a Protocol
&lt;/h3&gt;

&lt;p&gt;Creating a protocol is very simple. Just use the &lt;code&gt;protocol&lt;/code&gt; keyword and choose a name. By convention, I’ve chosen to suffix it with &lt;code&gt;Protocol&lt;/code&gt;. Thinking about it, I believe I’m influenced by some DotNet conventions, because put “Protocol” at the end is redundant. Anyway, let’s see:&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="kd"&gt;protocol&lt;/span&gt; &lt;span class="kt"&gt;SearchProtocol&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;search&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code defines a protocol named &lt;code&gt;SearchProtocol&lt;/code&gt;. This protocol requires conforming types to implement a &lt;code&gt;search(text:)&lt;/code&gt; function, which would presumably perform some kind of search operation using the provided text as input. So, how do we use it?&lt;/p&gt;

&lt;h3&gt;
  
  
  How to Use a Protocol
&lt;/h3&gt;

&lt;p&gt;Here’s how you could use this protocol:&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="kd"&gt;struct&lt;/span&gt; &lt;span class="kt"&gt;YourStruct&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;SearchProtocol&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;search&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Searching for: &lt;/span&gt;&lt;span class="se"&gt;\(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;YourStruct&lt;/code&gt; conforms to &lt;code&gt;SearchProtocol&lt;/code&gt; and provides its own implementation for the &lt;code&gt;search(text:)&lt;/code&gt; function. As mentioned earlier, it’s the same concept as interfaces.&lt;/p&gt;

&lt;p&gt;This is very important in iOS, so let’s explore a slightly different example. Suppose we need to create a small component to represent some type of search UI element, like this:&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="kd"&gt;import&lt;/span&gt; &lt;span class="kt"&gt;SwiftUI&lt;/span&gt;

&lt;span class="kd"&gt;struct&lt;/span&gt; &lt;span class="kt"&gt;SearchComponent&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;View&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;@State&lt;/span&gt; &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;""&lt;/span&gt;

    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;some&lt;/span&gt; &lt;span class="kt"&gt;View&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;VStack&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;alignment&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;leading&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="kt"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"What are you looking for?"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

            &lt;span class="kt"&gt;TextField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Type here"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;$text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;onChange&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;of&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;oldValue&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;newValue&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt;
                    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;newValue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we have a view with a &lt;code&gt;TextField&lt;/code&gt;, and we’re monitoring changes using the &lt;code&gt;onChange&lt;/code&gt; event and capturing the text typed inside it using the &lt;code&gt;print&lt;/code&gt; function. It works. Now we can use it in a screen, like this:&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="kd"&gt;import&lt;/span&gt; &lt;span class="kt"&gt;SwiftUI&lt;/span&gt;

&lt;span class="kd"&gt;struct&lt;/span&gt; &lt;span class="kt"&gt;SearchView&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;View&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;some&lt;/span&gt; &lt;span class="kt"&gt;View&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;VStack&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="kt"&gt;SearchComponent&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
            &lt;span class="kt"&gt;Spacer&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The component is displayed correctly, but how can we get the value typed inside the &lt;code&gt;TextField&lt;/code&gt;? We can use protocols and delegates. It’s very common in iOS to use this approach to achieve a decoupled implementation. Instead of the view knowing all the details about the component, we just make it conform to the &lt;code&gt;SearchComponent&lt;/code&gt; protocol and use it. Let’s see how.&lt;/p&gt;

&lt;p&gt;I’ve placed the protocol near the component, created an optional property on the component, and replaced the &lt;code&gt;print&lt;/code&gt; function call with the protocol function call through the delegate.&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="kd"&gt;import&lt;/span&gt; &lt;span class="kt"&gt;SwiftUI&lt;/span&gt;

&lt;span class="kd"&gt;protocol&lt;/span&gt; &lt;span class="kt"&gt;SearchProtocol&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;search&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;struct&lt;/span&gt; &lt;span class="kt"&gt;SearchComponent&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;View&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// rest of the code&lt;/span&gt;

    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;delegate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;SearchProtocol&lt;/span&gt;&lt;span class="p"&gt;?&lt;/span&gt;

    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;some&lt;/span&gt; &lt;span class="kt"&gt;View&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// rest of the code&lt;/span&gt;

        &lt;span class="kt"&gt;TextField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Type here"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;$text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;onChange&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;of&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;oldValue&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;newValue&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt;
                &lt;span class="n"&gt;delegate&lt;/span&gt;&lt;span class="p"&gt;?&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;search&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;newValue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="c1"&gt;// rest of the code&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now I can go back to the view, make it conform to the protocol, and pass the delegate parameter when creating the instance of the component.&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="kd"&gt;import&lt;/span&gt; &lt;span class="kt"&gt;SwiftUI&lt;/span&gt;

&lt;span class="kd"&gt;struct&lt;/span&gt; &lt;span class="kt"&gt;SearchView&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;View&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;SearchProtocol&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;some&lt;/span&gt; &lt;span class="kt"&gt;View&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// rest of the code&lt;/span&gt;

        &lt;span class="kt"&gt;SearchComponent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;delegate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="c1"&gt;// rest of the code&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;search&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we can get the values typed in the component right here on the screen, maintaining low coupling between them.&lt;/p&gt;

&lt;p&gt;This pattern is very common when working with &lt;code&gt;UITableView&lt;/code&gt; on iOS. It uses protocols to keep the component easy to use and reusable.&lt;/p&gt;

&lt;p&gt;Let’s continue by talking about extensions.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Is an Extension?
&lt;/h2&gt;

&lt;p&gt;Extensions are an easy way to add more functionality to your code. Extensions in Swift are very powerful because you can create them even for primitive types. Let’s explore this.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to Create an Extension
&lt;/h3&gt;

&lt;p&gt;In Swift, it’s very simple to create one. You just use the &lt;code&gt;extension&lt;/code&gt; keyword followed by the type name you want to extend. The &lt;code&gt;String&lt;/code&gt; type has a property called &lt;code&gt;isEmpty&lt;/code&gt;, and sometimes we want to create an expression to validate if a string is not empty. We can do this in three ways:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Use &lt;code&gt;yourStringVariable.isEmpty == false&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;!yourStringVariable.isEmpty&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Create an extension, choosing one of the options above.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="kd"&gt;extension&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;isNotEmpty&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Bool&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;isEmpty&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you can use &lt;code&gt;yourStringVariable.isNotEmpty&lt;/code&gt;. This is an extension property, but you can create extension functions too. It works the same way, even for primitive types, as you can see above.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Is an Optional?
&lt;/h2&gt;

&lt;p&gt;In Swift, optionals are a powerful safeguard against a notorious coding issue: the dreaded “unexpectedly found nil” error or something like this. But what are optionals, and why are they so important?&lt;/p&gt;

&lt;p&gt;Imagine a variable as a container. A regular variable must always hold a value of its declared type. An optional, however, introduces the possibility of emptiness. It’s like a container that can either hold a value or be explicitly marked as empty, a state represented by the keyword &lt;code&gt;nil&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This “nullability” is incredibly valuable. For instance, when fetching data from a server or a user’s device, there’s no guarantee the operation will always succeed. Optionals handle these scenarios elegantly.&lt;/p&gt;

&lt;p&gt;Consider a function that tries to convert a string to an integer:&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="kd"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;convertToInt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;from&lt;/span&gt; &lt;span class="nv"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;Int&lt;/span&gt;&lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kt"&gt;Int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;Int?&lt;/code&gt; return type signifies that this function might return an integer, or it might return &lt;code&gt;nil&lt;/code&gt; if the conversion fails (for example, trying to convert “hello” to an integer). Let’s explore how to safely access an optional value.&lt;/p&gt;

&lt;h3&gt;
  
  
  if let
&lt;/h3&gt;

&lt;p&gt;To safely access the potential value inside an optional, you use “unwrapping” mechanisms. One common way is using &lt;code&gt;if let&lt;/code&gt;:&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="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;userInput&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"123"&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;convertToInt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;from&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;userInput&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"The number is &lt;/span&gt;&lt;span class="se"&gt;\(&lt;/span&gt;&lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Invalid input"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, &lt;code&gt;number&lt;/code&gt; is only assigned a value if &lt;code&gt;convertToInt&lt;/code&gt; succeeds. Otherwise, the &lt;code&gt;else&lt;/code&gt; block executes, preventing crashes from trying to use a non-existent value.&lt;/p&gt;

&lt;h3&gt;
  
  
  guard let
&lt;/h3&gt;

&lt;p&gt;You can check for “nullability” in different ways. For instance, you can use &lt;code&gt;guard let&lt;/code&gt;. This approach is better to use when you need to create an early return statement.&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="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;userInput&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"123"&lt;/span&gt;

&lt;span class="kd"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;yourFunction&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;guard&lt;/span&gt; &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;convertToInt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;from&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;userInput&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Invalid input"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; 
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"The number is &lt;/span&gt;&lt;span class="se"&gt;\(&lt;/span&gt;&lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;yourFunction&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Nil Coalescing
&lt;/h3&gt;

&lt;p&gt;Nil coalescing provides a concise and elegant way to handle optional values by providing a default value when an optional is &lt;code&gt;nil&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Here’s a simple example:&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="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;userInput&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"hello"&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;convertedValue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;convertToInt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;from&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;userInput&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;convertedValue&lt;/span&gt; &lt;span class="p"&gt;??&lt;/span&gt; &lt;span class="s"&gt;"empty value"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As a result, the &lt;code&gt;print&lt;/code&gt; function will display “empty value” because &lt;code&gt;convertedValue&lt;/code&gt; is an optional without a value.&lt;/p&gt;

&lt;h3&gt;
  
  
  Optional Chaining
&lt;/h3&gt;

&lt;p&gt;Optional chaining acts like a careful safeguard when you’re accessing data that might be missing in your Swift code. Imagine you’re following a treasure map with instructions like “Go to the old oak tree, then check under the loose rock, and you’ll find the prize!” But what if the tree is gone, the rock is missing, or the prize was already taken? In code, when we try to access something that doesn’t exist, we get a fatal error, but using optional chaining prevents this from happening. Let’s look at the previous example where I showed you about protocols:&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="kd"&gt;import&lt;/span&gt; &lt;span class="kt"&gt;SwiftUI&lt;/span&gt;

&lt;span class="kd"&gt;protocol&lt;/span&gt; &lt;span class="kt"&gt;SearchProtocol&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;search&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;struct&lt;/span&gt; &lt;span class="kt"&gt;SearchComponent&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;View&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// rest of the code&lt;/span&gt;

    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;delegate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;SearchProtocol&lt;/span&gt;&lt;span class="p"&gt;?&lt;/span&gt;

    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;some&lt;/span&gt; &lt;span class="kt"&gt;View&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// rest of the code&lt;/span&gt;

        &lt;span class="kt"&gt;TextField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Type here"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;$text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;onChange&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;of&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;oldValue&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;newValue&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt;
                &lt;span class="n"&gt;delegate&lt;/span&gt;&lt;span class="p"&gt;?&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;search&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;newValue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="c1"&gt;// rest of the code&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the line &lt;code&gt;delegate?.search(text: newValue)&lt;/code&gt;, we’re accessing the &lt;code&gt;search&lt;/code&gt; method of the &lt;code&gt;delegate&lt;/code&gt; property, but it will only be called if the property actually contains a value.&lt;/p&gt;

&lt;p&gt;Optionals, while initially appearing as an extra layer of complexity, are a fundamental safety net in Swift. They encourage you to think about and handle situations where data might be missing, leading to more robust and crash-resistant applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrap Up
&lt;/h2&gt;

&lt;p&gt;As we reach the end of our exploration, it’s clear that protocols, extensions, and optionals form a powerful trio in the world of Swift programming.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Protocols&lt;/strong&gt; , with their blueprint-like nature, empower you to define consistent behavior across different types, fostering code reusability and maintainability. They bring order to chaos, ensuring your code adheres to a common standard.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Extensions&lt;/strong&gt; , like skilled artisans, add functionality and elegance to existing types without requiring access to their original blueprints. They enhance and extend, making your code more expressive and adaptable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Optionals&lt;/strong&gt; , the ever-vigilant guardians, equip you to handle the uncertainty of missing data. They gracefully guide your code through potential pitfalls, preventing crashes and fostering resilience in the face of the unknown.&lt;/p&gt;

&lt;p&gt;Together, this dynamic trio empowers you to write safer, cleaner, and more flexible Swift code. Embrace their strengths, experiment with their possibilities, and watch as your code transforms into a masterpiece of clarity and robustness.&lt;/p&gt;

&lt;p&gt;See you in the next post!&lt;/p&gt;

</description>
      <category>100daysofswiftui</category>
    </item>
    <item>
      <title>Git-ifying SVN: How I Brought Modern Version Control to an Age-Old System</title>
      <dc:creator>Ione Souza Junior</dc:creator>
      <pubDate>Fri, 26 Jul 2024 00:00:00 +0000</pubDate>
      <link>https://dev.to/ionixjunior/git-ifying-svn-how-i-brought-modern-version-control-to-an-age-old-system-4o3e</link>
      <guid>https://dev.to/ionixjunior/git-ifying-svn-how-i-brought-modern-version-control-to-an-age-old-system-4o3e</guid>
      <description>&lt;p&gt;Rewind the clock ten years. The year was 2014, smartphones were still finding their feet, and I was a bright-eyed developer, eager to conquer the world, one line of code at a time. But a formidable foe stood in my path – our company’s steadfast reliance on Subversion (SVN) for version control. Don't get me wrong, SVN had served us well for a time. But as our projects grew in complexity and our team expanded, its limitations became increasingly apparent. Branching and merging were exercises in frustration, collaboration felt clunky, and don't even get me started on trying to work offline! The very tool that was meant to streamline our development process was slowing us down. A solution was needed, but a full-blown migration to a new system (Git was beckoning) felt like a distant dream. Then, I stumbled upon something that promised the best of both worlds... a way to "Git-ify" our SVN workflow. Let me tell you how git svn changed everything.&lt;/p&gt;

&lt;h2&gt;
  
  
  The SVN Struggle
&lt;/h2&gt;

&lt;p&gt;Every developer knows that sinking feeling when their tools become roadblocks instead of enablers. With SVN, that feeling was becoming a constant companion.&lt;/p&gt;

&lt;p&gt;The branching and merging process was the stuff of nightmares. Each branch felt like a delicate ecosystem, and merging them back into the trunk was a high-stakes operation fraught with the peril of conflicts. Hours would disappear into resolving these conflicts, often introducing new ones in the process. It felt like we were spending more time battling the version control system than writing actual code. I believe this was why the company choose to work only on the “trunk” branch - this is the name of the main branch on SVN.&lt;/p&gt;

&lt;p&gt;Collaboration wasn’t much better. SVN’s centralized nature meant we were tethered to a constant internet connection. Want to commit a small change? Make sure you’re online! Working remotely? Better hope your VPN is cooperating. This lack of offline access was a major productivity killer.&lt;/p&gt;

&lt;p&gt;And let’s not forget that code review didn’t exist. You just made a commit and done. We lived this way. It was funny when you and your colleague were working on the same file and whoever commit last without updating the repository ended up removing the implementation of the colleague who commit first.&lt;/p&gt;

&lt;p&gt;The impact of these SVN struggles was undeniable. As I was used to working with good tools, it was a bit difficult to work with SVN. Something had to give. A full switch to Git seemed ideal, but migrating our entire codebase and getting everyone on board felt like a Herculean task we weren’t prepared for.&lt;/p&gt;

&lt;h2&gt;
  
  
  Discovering git svn
&lt;/h2&gt;

&lt;p&gt;Just when my developer despair was at its peak, I stumbled across a glimmer of hope while scouring the internet for SVN workarounds (as one does when facing a mountain of merge conflicts). Enter &lt;code&gt;git svn&lt;/code&gt;: a seemingly magical command that promised to bridge the chasm between my SVN reality and the Git-powered dreams I held dear.&lt;/p&gt;

&lt;p&gt;In essence, &lt;code&gt;git svn&lt;/code&gt; acts as a translator between the two systems. It allows you to work locally with all the power and flexibility of Git - branching, merging, offline commits – while still interacting with a remote SVN repository. Imagine having your cake and eating it too, but for version control!&lt;/p&gt;

&lt;p&gt;The beauty of &lt;code&gt;git svn&lt;/code&gt; lay in its simplicity. I could keep using my familiar Git commands (&lt;code&gt;git checkout&lt;/code&gt;, &lt;code&gt;git branch&lt;/code&gt;, &lt;code&gt;git merge&lt;/code&gt;, oh my!) without forcing my colleagues to abandon SVN. It was the perfect stealth operation to bring some modern version control sanity into our workflow, all while flying under the radar of a full-blown migration.&lt;/p&gt;

&lt;p&gt;The possibilities were exhilarating: I could finally branch and merge with ease, commit changes offline to my heart’s content, and gain much-needed visibility into our project’s history, all without rocking the SVN boat. Could this be the answer to our version control woes? I was determined to find out.&lt;/p&gt;

&lt;h2&gt;
  
  
  Implementing the Solution
&lt;/h2&gt;

&lt;p&gt;Armed with newfound hope and a healthy dose of developer enthusiasm, I dove headfirst into the world of &lt;code&gt;git svn&lt;/code&gt;. My first order of business? Cloning our SVN repository into a local Git repository using the magic command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git svn clone &lt;span class="nt"&gt;--stdlayout&lt;/span&gt; SVN_REPOSITORY_URL
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It felt like opening a portal to a parallel universe – a universe where I could branch and merge without breaking a sweat. Once the clone was complete, I was greeted by a familiar sight: my very own Git repository, complete with the entire project history.&lt;/p&gt;

&lt;p&gt;To show you, I’m using a free SVN repo from &lt;a href="https://riouxsvn.com" rel="noopener noreferrer"&gt;RiouxSVN&lt;/a&gt;, create a project, make some commits and clone it. When I typed the command above, I can see the following where I typed &lt;code&gt;git log&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;*&lt;/span&gt; 899c967 &lt;span class="o"&gt;(&lt;/span&gt;origin/trunk, main&lt;span class="o"&gt;)&lt;/span&gt; Replace age by birthDate
&lt;span class="k"&gt;*&lt;/span&gt; c6e470f Replace name by first and last name properties
&lt;span class="k"&gt;*&lt;/span&gt; 0645868 Add User struct
&lt;span class="k"&gt;*&lt;/span&gt; 9d3fa32 Creating initial repository structure
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that the main branch of Git is synched with the trunk branch of SVN. Now, you can imagine that we’re in the Git world and can create new branches, make merges, updates, and so on. I’ve created a new branch called “new_feature”, and make a small implementation. Seeing the log, we have the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;*&lt;/span&gt; 9ec48e4 &lt;span class="o"&gt;(&lt;/span&gt;HEAD -&amp;gt; new_feature&lt;span class="o"&gt;)&lt;/span&gt; Change to a computed property
&lt;span class="k"&gt;*&lt;/span&gt; 9a03f1b Add fullName method
&lt;span class="k"&gt;*&lt;/span&gt; 899c967 &lt;span class="o"&gt;(&lt;/span&gt;origin/trunk, main&lt;span class="o"&gt;)&lt;/span&gt; Replace age by birthDate
&lt;span class="k"&gt;*&lt;/span&gt; c6e470f Replace name by first and last name properties
&lt;span class="k"&gt;*&lt;/span&gt; 0645868 Add User struct
&lt;span class="k"&gt;*&lt;/span&gt; 9d3fa32 Creating initial repository structure
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we have the “new_feature” branch ahead of the trunk. Suppose we finish our development and needs merge. But first, let’s do another think: let’s make another commit into SVN repo (simulation a teammate work), and keep our new branch updated before merge and send changed to SVN. How can we do this? Well, we can simple use the &lt;code&gt;fetch&lt;/code&gt; command to get the newest updates from SVN, and them merge it if our local repository. Let’s see it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git svn fetch   

        M User.swift
r5 &lt;span class="o"&gt;=&lt;/span&gt; 8bfc98b61c4e4c0eaf4062d5dacdaeb634b97cc7 &lt;span class="o"&gt;(&lt;/span&gt;refs/remotes/origin/trunk&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Seeing the log, we get the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;*&lt;/span&gt; 8bfc98b &lt;span class="o"&gt;(&lt;/span&gt;origin/trunk&lt;span class="o"&gt;)&lt;/span&gt; Add &lt;span class="nb"&gt;id &lt;/span&gt;property
| &lt;span class="k"&gt;*&lt;/span&gt; 9ec48e4 &lt;span class="o"&gt;(&lt;/span&gt;HEAD -&amp;gt; new_feature&lt;span class="o"&gt;)&lt;/span&gt; Change to a computed property
| &lt;span class="k"&gt;*&lt;/span&gt; 9a03f1b Add fullName method
|/  
&lt;span class="k"&gt;*&lt;/span&gt; 899c967 &lt;span class="o"&gt;(&lt;/span&gt;main&lt;span class="o"&gt;)&lt;/span&gt; Replace age by birthDate
&lt;span class="k"&gt;*&lt;/span&gt; c6e470f Replace name by first and last name properties
&lt;span class="k"&gt;*&lt;/span&gt; 0645868 Add User struct
&lt;span class="k"&gt;*&lt;/span&gt; 9d3fa32 Creating initial repository structure
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we see the trunk branch is one commit ahead of our main branch. Let’s update it and them make a rebase of our feature branch.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git checkout main
git merge origin/trunk

Updating 899c967..8bfc98b
Fast-forward
 User.swift | 1 +
 1 file changed, 1 insertion&lt;span class="o"&gt;(&lt;/span&gt;+&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the trunk and main branches are synched.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;*&lt;/span&gt; 8bfc98b &lt;span class="o"&gt;(&lt;/span&gt;HEAD -&amp;gt; main, origin/trunk&lt;span class="o"&gt;)&lt;/span&gt; Add &lt;span class="nb"&gt;id &lt;/span&gt;property
| &lt;span class="k"&gt;*&lt;/span&gt; 9ec48e4 &lt;span class="o"&gt;(&lt;/span&gt;new_feature&lt;span class="o"&gt;)&lt;/span&gt; Change to a computed property
| &lt;span class="k"&gt;*&lt;/span&gt; 9a03f1b Add fullName method
|/  
&lt;span class="k"&gt;*&lt;/span&gt; 899c967 Replace age by birthDate
&lt;span class="k"&gt;*&lt;/span&gt; c6e470f Replace name by first and last name properties
&lt;span class="k"&gt;*&lt;/span&gt; 0645868 Add User struct
&lt;span class="k"&gt;*&lt;/span&gt; 9d3fa32 Creating initial repository structure
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let’s go back to our feature branch, make a rebase and prepare to commit into SVN.&lt;/p&gt;

&lt;p&gt;Checkout to the “new_feature” branch.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git checkout new_feature
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Make the rebase.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git rebase main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After it, everything is okay again and all synched.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;*&lt;/span&gt; 6e1f665 &lt;span class="o"&gt;(&lt;/span&gt;HEAD -&amp;gt; new_feature&lt;span class="o"&gt;)&lt;/span&gt; Change to a computed property
&lt;span class="k"&gt;*&lt;/span&gt; e171831 Add fullName method
&lt;span class="k"&gt;*&lt;/span&gt; 8bfc98b &lt;span class="o"&gt;(&lt;/span&gt;origin/trunk, main&lt;span class="o"&gt;)&lt;/span&gt; Add &lt;span class="nb"&gt;id &lt;/span&gt;property
&lt;span class="k"&gt;*&lt;/span&gt; 899c967 Replace age by birthDate
&lt;span class="k"&gt;*&lt;/span&gt; c6e470f Replace name by first and last name properties
&lt;span class="k"&gt;*&lt;/span&gt; 0645868 Add User struct
&lt;span class="k"&gt;*&lt;/span&gt; 9d3fa32 Creating initial repository structure
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We’re prepared to make our commit to SVN. First, let’s checkout to the main branch.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git checkout main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Merge the feature branch using the &lt;code&gt;--no-ff&lt;/code&gt; (no-fast-forward) option. This will create a merge commit into main branch, and this will be good to the SVN because won’t mess with a lot of commits.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git merge &lt;span class="nt"&gt;--no-ff&lt;/span&gt; new_feature
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Git will ask you a commit message. Type the message and finish the merge. Seeing the log, everything is okay.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;*&lt;/span&gt; 3c13eb4 &lt;span class="o"&gt;(&lt;/span&gt;HEAD -&amp;gt; main&lt;span class="o"&gt;)&lt;/span&gt; Implement the fullName computed property
|&lt;span class="se"&gt;\ &lt;/span&gt; 
| &lt;span class="k"&gt;*&lt;/span&gt; 6e1f665 &lt;span class="o"&gt;(&lt;/span&gt;new_feature&lt;span class="o"&gt;)&lt;/span&gt; Change to a computed property
| &lt;span class="k"&gt;*&lt;/span&gt; e171831 Add fullName method
|/  
&lt;span class="k"&gt;*&lt;/span&gt; 8bfc98b &lt;span class="o"&gt;(&lt;/span&gt;origin/trunk&lt;span class="o"&gt;)&lt;/span&gt; Add &lt;span class="nb"&gt;id &lt;/span&gt;property
&lt;span class="k"&gt;*&lt;/span&gt; 899c967 Replace age by birthDate
&lt;span class="k"&gt;*&lt;/span&gt; c6e470f Replace name by first and last name properties
&lt;span class="k"&gt;*&lt;/span&gt; 0645868 Add User struct
&lt;span class="k"&gt;*&lt;/span&gt; 9d3fa32 Creating initial repository structure
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now comes the best part: push changes to SVN. To do it, we just type the &lt;code&gt;git svn dcommit&lt;/code&gt; command to push our local changes on main branch to the trunk branch on SVN server.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git svn dcommit
Committing to https://svn.riouxsvn.com/ionixjunior-prj/trunk ...
        M User.swift
Committed r6
        M User.swift
r6 &lt;span class="o"&gt;=&lt;/span&gt; 42e0f095ec453b6416f954958479f39842028f58 &lt;span class="o"&gt;(&lt;/span&gt;refs/remotes/origin/trunk&lt;span class="o"&gt;)&lt;/span&gt;
No changes between 3c13eb4501d858e7b7c225fa687b08667d97bcb4 and refs/remotes/origin/trunk
Resetting to the latest refs/remotes/origin/trunk
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Seeing the log, we will see the branches synched.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;*&lt;/span&gt; 42e0f09 &lt;span class="o"&gt;(&lt;/span&gt;HEAD -&amp;gt; main, origin/trunk&lt;span class="o"&gt;)&lt;/span&gt; Implement the fullName computed property
|&lt;span class="se"&gt;\ &lt;/span&gt; 
| &lt;span class="k"&gt;*&lt;/span&gt; 6e1f665 &lt;span class="o"&gt;(&lt;/span&gt;new_feature&lt;span class="o"&gt;)&lt;/span&gt; Change to a computed property
| &lt;span class="k"&gt;*&lt;/span&gt; e171831 Add fullName method
|/  
&lt;span class="k"&gt;*&lt;/span&gt; 8bfc98b Add &lt;span class="nb"&gt;id &lt;/span&gt;property
&lt;span class="k"&gt;*&lt;/span&gt; 899c967 Replace age by birthDate
&lt;span class="k"&gt;*&lt;/span&gt; c6e470f Replace name by first and last name properties
&lt;span class="k"&gt;*&lt;/span&gt; 0645868 Add User struct
&lt;span class="k"&gt;*&lt;/span&gt; 9d3fa32 Creating initial repository structure
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Works like a charm 😎.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Impact
&lt;/h2&gt;

&lt;p&gt;The introduction of &lt;code&gt;git svn&lt;/code&gt; wasn’t just a technological shift; it was a breath of fresh air for me. I went from battling our version control system to embracing it as a valuable ally in our quest to build great software. Unfortunately, I’ve tried to evangelize my teammates to work this way, but I felt from them some fear and disturb. Even though it was cool, it was something very “new”, and we know that changes take time to be introduced.&lt;/p&gt;

&lt;p&gt;The most noticeable change was the boost in productivity. Branching and merging, once dreaded tasks, became routine operations. The fear of merge conflicts subsided, replaced by the confidence that Git’s powerful algorithms had our back. I was finally free to experiment, iterate, and collaborate with ease, and the way that I love: commit a lot, every piece of code, and I finally can use Git as a strategic tool in development, not just for versioning code.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git svn&lt;/code&gt; was the silent hero, bridging the gap between two worlds and empowering us to become better, happier, and more productive developer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using git svn today
&lt;/h2&gt;

&lt;p&gt;In 2014 I just typed &lt;code&gt;git svn&lt;/code&gt;, and everything works. But today, maybe you need to install the &lt;code&gt;git-svn&lt;/code&gt; using Homebrew. Just type &lt;code&gt;brew install git-svn&lt;/code&gt;, and you’ll get the &lt;code&gt;git svn&lt;/code&gt; command on your command line. But this is an official command, as you can see &lt;a href="https://git-scm.com/docs/git-svn" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Lessons Learned and Conclusion
&lt;/h2&gt;

&lt;p&gt;Looking back, my journey with &lt;code&gt;git svn&lt;/code&gt; was an eye-opener. It taught me that you don’t always need a radical overhaul to make a significant impact. Sometimes, the most effective solutions are the ones that bridge the gaps between existing systems and individual preferences.&lt;/p&gt;

&lt;p&gt;While my teammates were content with the familiar flow of SVN, I was eager to tap into the power and flexibility of Git. &lt;code&gt;git svn&lt;/code&gt; became my secret weapon, allowing me to work more efficiently and with far less friction, all while remaining a contributing member of our SVN-centric team.&lt;/p&gt;

&lt;p&gt;What did I learn?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The right tool can make all the difference. Don’t be afraid to explore solutions that cater to your specific workflow and preferences, even within constraints.&lt;/li&gt;
&lt;li&gt;Sometimes, a gradual approach is key. &lt;code&gt;git svn&lt;/code&gt; provided a perfect steppingstone, allowing me to reap the benefits of Git without disrupting the team’s established workflow.&lt;/li&gt;
&lt;li&gt;Embrace flexibility. Development is a diverse field, and what works for one person might not work for another. Respecting different tools and approaches is crucial for team harmony.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;While our team eventually moved on to embrace Git fully (hey, progress waits for no one!), my time with &lt;code&gt;git svn&lt;/code&gt; taught me valuable lessons about adaptability, the importance of choosing the right tools for the job, and finding ways to thrive, even within the constraints of legacy systems. And sometimes, a little bit of silent revolution is all it takes to make a world of difference in your own coding journey.&lt;/p&gt;

&lt;p&gt;Happy coding and choose the best tools for work!&lt;/p&gt;

</description>
      <category>git</category>
    </item>
    <item>
      <title>Swift Essentials: Structs, Classes, and More (Part 3)</title>
      <dc:creator>Ione Souza Junior</dc:creator>
      <pubDate>Fri, 19 Jul 2024 00:00:00 +0000</pubDate>
      <link>https://dev.to/ionixjunior/swift-essentials-structs-classes-and-more-part-3-971</link>
      <guid>https://dev.to/ionixjunior/swift-essentials-structs-classes-and-more-part-3-971</guid>
      <description>&lt;p&gt;In the first two parts of "100DaysOfSwiftUI", we explored the fundamental building blocks of Swift - variables, data types, control flow, loops, functions, and closures. Now, we're ready to dive into a crucial aspect of Swift programming: structs and classes. These powerful tools allow us to create custom data structures that organize and represent real-world objects in our code. Understanding structs and classes is essential for building complex and modular applications in SwiftUI, and they will empower you to create more powerful and robust iOS apps. Let's learn about it!&lt;/p&gt;

&lt;h2&gt;
  
  
  Structs: Value Types
&lt;/h2&gt;

&lt;p&gt;Structs in Swift are value types that allow you to create custom data structures. Imagine them as blueprints for creating your own unique data containers, similar to how you might design a blueprint for a house.&lt;/p&gt;

&lt;p&gt;Think of structs as “boxes” that hold related information. Each box has specific compartments (properties) to store different types of data, and you can define actions (methods) that can be performed on the data within the box. Here’s a breakdown of structs.&lt;/p&gt;

&lt;h3&gt;
  
  
  Basic Struct Definition
&lt;/h3&gt;

&lt;p&gt;To define a struct, we use the &lt;code&gt;struct&lt;/code&gt; keyword followed by the struct’s name:&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="kd"&gt;struct&lt;/span&gt; &lt;span class="kt"&gt;User&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Properties and methods will go here&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let’s create a &lt;code&gt;User&lt;/code&gt; struct to represent a user profile:&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="kd"&gt;struct&lt;/span&gt; &lt;span class="kt"&gt;User&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;
    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This defines a &lt;code&gt;User&lt;/code&gt; struct with two properties: &lt;code&gt;firstName&lt;/code&gt; and &lt;code&gt;lastName&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Stored Properties
&lt;/h3&gt;

&lt;p&gt;Stored properties hold data within a struct. They act like variables inside the struct. The properties showed above are stored properties.&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="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;userLaura&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;User&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Laura"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Campbell"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Computed Properties
&lt;/h3&gt;

&lt;p&gt;Computed properties don’t store values directly. Instead, they calculate and return a value based on other properties.&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="kd"&gt;struct&lt;/span&gt; &lt;span class="kt"&gt;User&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;
    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;

    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;fullName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\(&lt;/span&gt;&lt;span class="n"&gt;firstName&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="s"&gt; &lt;/span&gt;&lt;span class="se"&gt;\(&lt;/span&gt;&lt;span class="n"&gt;lastName&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;userLaura&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;User&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Laura"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Campbell"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;userLaura&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;fullName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Output: Laura Campbell&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This &lt;code&gt;User&lt;/code&gt; struct now has a &lt;code&gt;fullName&lt;/code&gt; computed property that returns the concatenation of &lt;code&gt;firstName&lt;/code&gt; and &lt;code&gt;lastName&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Computed properties are very used on SwiftUI, mainly on views.&lt;/p&gt;

&lt;h3&gt;
  
  
  Property Observers (didSet, willSet)
&lt;/h3&gt;

&lt;p&gt;Property observers allow you to perform actions whenever a property’s value changes. We have two:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;didSet&lt;/code&gt;: This observer is called after a property’s value changes.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;willSet&lt;/code&gt;: This observer is called before a property’s value changes.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="kd"&gt;struct&lt;/span&gt; &lt;span class="kt"&gt;User&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;
    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;willSet&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"The new value is &lt;/span&gt;&lt;span class="se"&gt;\(&lt;/span&gt;&lt;span class="n"&gt;newValue&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="k"&gt;didSet&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"The old value is &lt;/span&gt;&lt;span class="se"&gt;\(&lt;/span&gt;&lt;span class="n"&gt;oldValue&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;userLaura&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;User&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Laura"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Campbell"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;userLaura&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;lastName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Johnson"&lt;/span&gt;

&lt;span class="c1"&gt;// Output:&lt;/span&gt;
&lt;span class="c1"&gt;// The new value is Johnson&lt;/span&gt;
&lt;span class="c1"&gt;// The old value is Campbell&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;newValue&lt;/code&gt; and &lt;code&gt;oldValue&lt;/code&gt; are automatically powered by Swift when using these property observers. You can use this to develop something reactive. But be careful, because your code can be slow with a lot of actions in a simple property called many times.&lt;/p&gt;

&lt;h3&gt;
  
  
  Memberwise Initializers (Default Constructor)
&lt;/h3&gt;

&lt;p&gt;Structs automatically get a memberwise initializer, which is a default initializer that allows you to create instances by providing values for all properties. As showed previously, we didn’t create any constructor for the struct, but we were capable to initialize the object and put values inside.&lt;/p&gt;

&lt;h3&gt;
  
  
  Custom Initializers
&lt;/h3&gt;

&lt;p&gt;We can create our own custom initializers for structs to control instance creation based on specific parameters.&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="kd"&gt;struct&lt;/span&gt; &lt;span class="kt"&gt;User&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;
    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;

    &lt;span class="nf"&gt;init&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;firstName&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;uppercased&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;lastName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;lastName&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;uppercased&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, we create a custom initializer that takes the same parameters as the memberwise initializer. However, we can add additional logic or validation within the initializer before assigning values to the properties. If you create a custom initializer, you need to ensure that all property will be initialized with a value.&lt;/p&gt;

&lt;h3&gt;
  
  
  Mutating Methods
&lt;/h3&gt;

&lt;p&gt;Methods that modify the properties of a struct needs the &lt;code&gt;mutating&lt;/code&gt; keyword.&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="kd"&gt;struct&lt;/span&gt; &lt;span class="kt"&gt;User&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;
    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;

    &lt;span class="k"&gt;mutating&lt;/span&gt; &lt;span class="kd"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;changeLastName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="nv"&gt;newLastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;lastName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;newLastName&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;userLaura&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;User&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Laura"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Campbell"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;userLaura&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;changeLastName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;to&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Johnson"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;userLaura&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Output: Johnson&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, &lt;code&gt;changeLastName&lt;/code&gt; modifies the &lt;code&gt;lastName&lt;/code&gt; property, so it needs to be marked as &lt;code&gt;mutating&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Structs are incredibly useful for creating custom data types, and understanding their features is crucial for building well-organized and efficient code in Swift. In the next section, we’ll dive into classes, another powerful tool for representing data and behavior in Swift.&lt;/p&gt;

&lt;h2&gt;
  
  
  Classes: Reference Types
&lt;/h2&gt;

&lt;p&gt;Classes in Swift are like blueprints for creating objects that represent real-world entities. They’re similar to structs in that they can hold properties and methods, but they have some crucial differences. Classes are &lt;strong&gt;reference types&lt;/strong&gt; , meaning that they’re passed around as references (pointers) instead of copies. This has significant implications for how they behave.&lt;/p&gt;

&lt;p&gt;Let’s explore classes in more detail to understand some differences.&lt;/p&gt;

&lt;h3&gt;
  
  
  Basic Class Definition
&lt;/h3&gt;

&lt;p&gt;To define a class, we use the &lt;code&gt;class&lt;/code&gt; keyword followed by the class name. I’ll use the same example of &lt;code&gt;User&lt;/code&gt; struct that I showed previously.&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="kd"&gt;class&lt;/span&gt; &lt;span class="kt"&gt;User&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let’s add some properties.&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="kd"&gt;class&lt;/span&gt; &lt;span class="kt"&gt;User&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;
    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;

    &lt;span class="nf"&gt;init&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;firstName&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;uppercased&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;lastName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;lastName&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;uppercased&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice now we need to specify the initializer method. Different from struct, Swift doesn’t create memberwise initialize for classes.&lt;/p&gt;

&lt;h3&gt;
  
  
  Inheritance
&lt;/h3&gt;

&lt;p&gt;Inheritance allows us to create subclasses that inherit properties and methods from superclasses. This promotes code reusability and reduces redundancy.&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="kd"&gt;class&lt;/span&gt; &lt;span class="kt"&gt;AdminUser&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;User&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;canDeleteAccount&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Bool&lt;/span&gt;

    &lt;span class="nf"&gt;init&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;canDeleteAccount&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Bool&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;canDeleteAccount&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;canDeleteAccount&lt;/span&gt;
        &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;init&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, &lt;code&gt;AdminUser&lt;/code&gt; inherits from &lt;code&gt;User&lt;/code&gt;. It has its own property (canDeleteAccount) and overrides the initializer to take an additional &lt;code&gt;canDeleteAccount&lt;/code&gt; parameter.&lt;/p&gt;

&lt;p&gt;Note we’re using an initializer for inheritance class with &lt;code&gt;super.init&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Methods
&lt;/h3&gt;

&lt;p&gt;Different from structs, classes doesn’t need to be marked with the &lt;code&gt;mutating&lt;/code&gt; keyword to change some property.&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="kd"&gt;class&lt;/span&gt; &lt;span class="kt"&gt;User&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;
    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;

    &lt;span class="nf"&gt;init&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;firstName&lt;/span&gt;
        &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;lastName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;lastName&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;changeLastName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="nv"&gt;newLastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;lastName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;newLastName&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;userLaura&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;User&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Laura"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Campbell"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;userLaura&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;changeLastName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;to&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Johnson"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;userLaura&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Output: Johnson&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Deinitializers
&lt;/h3&gt;

&lt;p&gt;Deinitializers (&lt;code&gt;deinit&lt;/code&gt;) are called when an instance of a class is about to be deallocated from memory. Some languages calling it as desctructors.&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="kd"&gt;class&lt;/span&gt; &lt;span class="kt"&gt;User&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;
    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;

    &lt;span class="nf"&gt;init&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;firstName&lt;/span&gt;
        &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;lastName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;lastName&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;deinit&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\(&lt;/span&gt;&lt;span class="n"&gt;firstName&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="s"&gt; is being deallocated."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To see it in action, try to use the playground and create this object in a loop. You’ll see when the context of class finishes, the &lt;code&gt;deinit&lt;/code&gt; will be called.&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="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;...&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;userLaura&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;User&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Laura &lt;/span&gt;&lt;span class="se"&gt;\(&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Campbell"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;userLaura&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Output:&lt;/span&gt;
&lt;span class="c1"&gt;// Campbell&lt;/span&gt;
&lt;span class="c1"&gt;// Laura 1 is being deallocated.&lt;/span&gt;
&lt;span class="c1"&gt;// Campbell&lt;/span&gt;
&lt;span class="c1"&gt;// Laura 2 is being deallocated.&lt;/span&gt;
&lt;span class="c1"&gt;// Campbell&lt;/span&gt;
&lt;span class="c1"&gt;// Laura 3 is being deallocated.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Classes are powerful tools for building complex and object-oriented applications in Swift. They allow you to model real-world entities, promote code reusability through inheritance, and manage object lifecycle. But I believe you thinking now: when I need to use a struct or a class?&lt;/p&gt;

&lt;h2&gt;
  
  
  Struct or Class?
&lt;/h2&gt;

&lt;p&gt;I’ll try to simplify: use a struct when you want to create simple data containers that are copied and remain immutable. Use a class when you want to create complex objects that are referenced and modified, and when inheritance is necessary.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;Struct (Value Type)&lt;/th&gt;
&lt;th&gt;Class (Reference Type)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Copying&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Copies are made when passed as arguments or assigned to new variables&lt;/td&gt;
&lt;td&gt;References are passed, so changes affect the original object&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Mutability&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Properties are immutable by default. &lt;code&gt;mutating&lt;/code&gt; keyword is required to modify properties within methods&lt;/td&gt;
&lt;td&gt;Properties are mutable by default. No need for &lt;code&gt;mutating&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Inheritance&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Structs cannot inherit from other structs or classes&lt;/td&gt;
&lt;td&gt;Classes can inherit from other classes (single inheritance)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Reference Counting&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;No reference counting&lt;/td&gt;
&lt;td&gt;Reference counting is used to track object instances&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Deinitializers&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Structs do not have deinitializers&lt;/td&gt;
&lt;td&gt;Classes can have deinitializers (&lt;code&gt;deinit&lt;/code&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Typical Use Cases&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Representing simple data structures, value types, where immutability is preferred, data structures passed by value&lt;/td&gt;
&lt;td&gt;Representing complex objects, reference types, where inheritance or mutability is required, data structures passed by reference&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;In the table above I show you the main differences for each one. One thing that I haven’t showed yet is about “copying”. Let’s see it.&lt;/p&gt;

&lt;p&gt;In the following code, I’ve created a &lt;code&gt;user1&lt;/code&gt; and copy it to a &lt;code&gt;user2&lt;/code&gt;. I’ve changed the &lt;code&gt;user1&lt;/code&gt; property and print both. Note that the name are different for each one because we’re using a &lt;code&gt;struct&lt;/code&gt;.&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="kd"&gt;struct&lt;/span&gt; &lt;span class="kt"&gt;User&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;

    &lt;span class="nf"&gt;init&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;firstName&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;user1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;User&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Laura"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;user2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;user1&lt;/span&gt;
&lt;span class="n"&gt;user1&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Samantha"&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user1&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Output: Samantha&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user2&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Output: Laura&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now I just changed one keyword: I replaced the &lt;code&gt;struct&lt;/code&gt; for a &lt;code&gt;class&lt;/code&gt; and the result is different now.&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="kd"&gt;class&lt;/span&gt; &lt;span class="kt"&gt;User&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;

    &lt;span class="nf"&gt;init&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;firstName&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;user1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;User&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Laura"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;user2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;user1&lt;/span&gt;
&lt;span class="n"&gt;user1&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Samantha"&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user1&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Output: Samantha&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user2&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Output: Samantha&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This occurs because the differences between these two kinds of type. When you’re using a class and pass a reference of it, any changes affect the original object, but this is not the same for structs.&lt;/p&gt;

&lt;p&gt;We already see a lot about structs and classes, right? Let’s see the next section to understand about the access control, which helps protect your code and ensure data integrity.&lt;/p&gt;

&lt;h2&gt;
  
  
  Access Control: Protecting Your Code
&lt;/h2&gt;

&lt;p&gt;Access control in Swift is a mechanism that allows you to restrict access to entities within your code, like properties, methods, and even entire types. This helps ensure data integrity, prevent accidental modifications, and improve code organization.&lt;/p&gt;

&lt;p&gt;Swift provides several access modifiers to control the visibility and accessibility of entities:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;public&lt;/code&gt;: Accessible from anywhere, including other modules or frameworks.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;private&lt;/code&gt;: Accessible only in the same scope where the entity is defined (like a class or an extensino).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;fileprivate&lt;/code&gt;: Accessible only from within the same source file wher the entity is defined.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Also, for properties we can use the &lt;code&gt;private (set)&lt;/code&gt; modifier to create properties only for public reading with private setter.&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="kd"&gt;class&lt;/span&gt; &lt;span class="kt"&gt;User&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;set&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;

    &lt;span class="nf"&gt;init&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;firstName&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;deleteAccount&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;deleteFiles&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="nf"&gt;deleteData&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;deleteFiles&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;fileprivate&lt;/span&gt; &lt;span class="kd"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;deleteData&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Access control is particularly important in SwiftUI because it helps you control the data and behavior of your views. By carefully using access modifiers, you can create more robust and well-structured UI components.&lt;/p&gt;

&lt;p&gt;This example is very simple, only to you understand what’s possible. Please, create a new playground project and explore it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Static Properties and Methods
&lt;/h2&gt;

&lt;p&gt;Static properties and methods are associated with the struct or class itself, rather than individual instances of the struct or class. This means that they can be accessed directly on the type without needing to create an instance.&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="kd"&gt;struct&lt;/span&gt; &lt;span class="kt"&gt;User&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;totalOfUsers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;

    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;

    &lt;span class="nf"&gt;init&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;firstName&lt;/span&gt;
        &lt;span class="kt"&gt;User&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;totalOfUsers&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;User&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;totalOfUsers&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Output: 0&lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;user1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;User&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Laura"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;User&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;totalOfUsers&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Output: 1&lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;user2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;User&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Samantha"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;User&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;totalOfUsers&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Output: 2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Static properties hold data that is shared among all instances of a class or struct. So, be careful. Also, methods can be static too.&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="kd"&gt;struct&lt;/span&gt; &lt;span class="kt"&gt;User&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;totalOfUsers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;

    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;

    &lt;span class="nf"&gt;init&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;firstName&lt;/span&gt;
        &lt;span class="kt"&gt;User&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;totalOfUsers&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kd"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;describeTotalOfUsers&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"There are &lt;/span&gt;&lt;span class="se"&gt;\(&lt;/span&gt;&lt;span class="n"&gt;totalOfUsers&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="s"&gt; users created."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kt"&gt;User&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;describeTotalOfUsers&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;// Output: There are 0 users created.&lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;user1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;User&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Laura"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="kt"&gt;User&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;describeTotalOfUsers&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;// Output: There are 1 users created.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Wrap up
&lt;/h2&gt;

&lt;p&gt;In this third installment of “100DaysOfSwiftUI,” we’ve delved into the world of structs and classes, the building blocks for organizing and representing data in Swift. We’ve explored their differences, learned how to define properties, methods, and initializers, and discovered about the access control.&lt;/p&gt;

&lt;p&gt;By mastering structs and classes, we unlock new levels of power and flexibility in Swift programming. We can now model complex objects, create reusable code through inheritance, and control data access for better code organization and security.&lt;/p&gt;

&lt;p&gt;As you continue your SwiftUI journey, remember that structs and classes are essential tools for building powerful and maintainable applications. They provide a structured approach to organizing your code, making it easier to manage, extend, and modify your projects. Structs are very important for SwiftUI, because they’re using massively to create views.&lt;/p&gt;

&lt;p&gt;Now it’s your time. Take a time to practice and explore all described here using the playground, and practice using them in your own projects. The more you practice, the more confident you’ll become in harnessing their power.&lt;/p&gt;

&lt;p&gt;Stay tuned for the next part of the “100DaysOfSwiftUI” series, where we’ll dive into more advanced topics, building upon the foundation we’ve laid together. Happy coding!&lt;/p&gt;

</description>
      <category>100daysofswiftui</category>
    </item>
    <item>
      <title>Swift Essentials: Loops, Closures, and More (Part 2)</title>
      <dc:creator>Ione Souza Junior</dc:creator>
      <pubDate>Fri, 12 Jul 2024 00:00:00 +0000</pubDate>
      <link>https://dev.to/ionixjunior/swift-essentials-loops-closures-and-more-part-2-1hfp</link>
      <guid>https://dev.to/ionixjunior/swift-essentials-loops-closures-and-more-part-2-1hfp</guid>
      <description>&lt;p&gt;In the first part of "100DaysOfSwiftUI," we explored the foundational building blocks of Swift — variables, data types, and more. Now, let's dive deeper into the control flow, loops, functions, and closures. These are essential concepts for building dynamic and interactive apps in SwiftUI, and they'll help us write more powerful and flexible code. Get ready to unleash the true potential of Swift and unlock new possibilities for your iOS development journey!&lt;/p&gt;

&lt;h2&gt;
  
  
  Control Flow: Making Decisions and Repeating Actions
&lt;/h2&gt;

&lt;p&gt;In the world of programming, we need to create code that can respond to different situations and repeat actions efficiently. This is where control flow comes in. It allows us to make decisions based on conditions and execute code blocks repeatedly based on specific criteria.&lt;/p&gt;

&lt;p&gt;Let’s explore some key elements of control flow in Swift:&lt;/p&gt;

&lt;h3&gt;
  
  
  If Statements and Comparisons
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;if&lt;/code&gt; statements are used to execute code only if a certain condition is true. We use comparison operators to compare values and determine if a condition is met. Common comparison operators include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;&amp;gt;&lt;/code&gt; (greater than)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;&lt;/code&gt; (less than)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;gt;=&lt;/code&gt; (greater than or equal to)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;=&lt;/code&gt; (less than or equal to)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;==&lt;/code&gt; (equal to)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;!=&lt;/code&gt; (not equal to)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here’s a simple example:&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="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;18&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"You are an adult."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code checks if the variable &lt;code&gt;age&lt;/code&gt; is greater than or equal to 18. If it is, the message “You are an adult.” is printed.&lt;/p&gt;

&lt;h3&gt;
  
  
  Else and Else If
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;else&lt;/code&gt; keyword allows us to execute a different block of code if the &lt;code&gt;if&lt;/code&gt; condition is false. The &lt;code&gt;else if&lt;/code&gt; keyword can be used to create additional conditions to check.&lt;/p&gt;

&lt;p&gt;Another simple example:&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="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;temperature&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;temperature&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"It's hot!"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;temperature&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"It's cold!"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"The temperature is pleasant."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Logical Operators (&amp;amp;&amp;amp;, ||): Combining Conditions
&lt;/h3&gt;

&lt;p&gt;Logical operators allow us to combine multiple conditions within an if statement.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; (AND): The &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; operator checks if both conditions are true.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;||&lt;/code&gt; (OR): The &lt;code&gt;||&lt;/code&gt; operator checks if at least one condition is true.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here’s an &lt;code&gt;AND&lt;/code&gt; example:&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="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;isLoggedIn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;isAdmin&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;isLoggedIn&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;isAdmin&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"You have administrative privileges."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here’s an &lt;code&gt;OR&lt;/code&gt; example:&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="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;isAdmin&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;isSimpleUserWithGrantAccess&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;isAdmin&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="n"&gt;isSimpleUserWithGrantAccess&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"You can execute the action."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Switch Statements: Evaluating Multiple Cases
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;switch&lt;/code&gt; statements provide a more concise and readable way to handle multiple conditions, especially when dealing with a limited number of cases.&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="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;trafficLight&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Red"&lt;/span&gt;

&lt;span class="k"&gt;switch&lt;/span&gt; &lt;span class="n"&gt;trafficLight&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="s"&gt;"Red"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Stop!"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="s"&gt;"Yellow"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Slow down."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="s"&gt;"Green"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Go!"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Invalid traffic light color."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code checks the value of &lt;code&gt;trafficLight&lt;/code&gt;. It matches the value against different cases and executes the corresponding code block. The &lt;code&gt;default&lt;/code&gt; case handles any values not explicitly matched.&lt;/p&gt;

&lt;p&gt;I think this way to create &lt;code&gt;switch&lt;/code&gt; and &lt;code&gt;case&lt;/code&gt; is the strangest thing in Swift, because they’re on the same indentation. But this is the pattern, that’s okay.&lt;/p&gt;

&lt;h3&gt;
  
  
  Ternary Conditional Operator
&lt;/h3&gt;

&lt;p&gt;The ternary operator is a shorthand way to write simple conditional expressions. It takes the form:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;condition ? valueIfTrue : valueIfFalse
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here’s an example:&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="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;

&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;18&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="s"&gt;"You are an adult."&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"You are not an adult."&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code checks the value of &lt;code&gt;age&lt;/code&gt;. If it’s greater than or equal to 18, the variable message is assigned “You are an adult.” Otherwise, it’s assigned “You are not an adult.”&lt;/p&gt;

&lt;p&gt;Control flow statements are fundamental building blocks of any programming language. They allow us to create code that can make decisions and repeat actions, making our programs more interactive and efficient. In the next section, we’ll explore another important aspect of Swift programming: loops.&lt;/p&gt;

&lt;h2&gt;
  
  
  Loops: Repeating Actions
&lt;/h2&gt;

&lt;p&gt;Loops are powerful tools in Swift that allow us to repeat blocks of code multiple times. They’re essential for automating tasks, iterating over collections, and handling repetitive operations. Let’s explore two common types of loops: &lt;code&gt;for&lt;/code&gt; loops and while loops.&lt;/p&gt;

&lt;h3&gt;
  
  
  For Loops
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;for&lt;/code&gt; loops are used to iterate over a sequence of values, such as a range of numbers or elements in an array.&lt;/p&gt;

&lt;p&gt;Here’s an example iterating over an array:&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="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;fruits&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"Apple"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Banana"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Orange"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;fruit&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;fruits&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fruit&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Output:&lt;/span&gt;
&lt;span class="c1"&gt;// Apple&lt;/span&gt;
&lt;span class="c1"&gt;// Banana&lt;/span&gt;
&lt;span class="c1"&gt;// Orange&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here’s an example iterating over a range:&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="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;...&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Output:&lt;/span&gt;
&lt;span class="c1"&gt;// 1&lt;/span&gt;
&lt;span class="c1"&gt;// 2&lt;/span&gt;
&lt;span class="c1"&gt;// 3&lt;/span&gt;
&lt;span class="c1"&gt;// 4&lt;/span&gt;
&lt;span class="c1"&gt;// 5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Swift provides a good way to create ranges. Very easy to use.&lt;/p&gt;

&lt;h3&gt;
  
  
  While Loops
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;while&lt;/code&gt; loops are used to repeat a block of code as long as a specific condition is true.&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="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;

&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="n"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;counter&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Output:&lt;/span&gt;
&lt;span class="c1"&gt;// 0&lt;/span&gt;
&lt;span class="c1"&gt;// 1&lt;/span&gt;
&lt;span class="c1"&gt;// 2&lt;/span&gt;
&lt;span class="c1"&gt;// 3&lt;/span&gt;
&lt;span class="c1"&gt;// 4&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This loop continues to execute as long as the value of &lt;code&gt;counter&lt;/code&gt; is less than 5. Inside the loop, the value of &lt;code&gt;counter&lt;/code&gt; is printed, and then incremented by 1.&lt;/p&gt;

&lt;p&gt;When we’re using &lt;code&gt;while&lt;/code&gt; we need to be careful to always control the variable who is deterministic to go out of the while. If we don’t increment the &lt;code&gt;counter&lt;/code&gt; in this example, the code won’t stop.&lt;/p&gt;

&lt;h3&gt;
  
  
  Break and Continue
&lt;/h3&gt;

&lt;p&gt;Sometimes, we need more control over how loops execute. &lt;code&gt;break&lt;/code&gt; and &lt;code&gt;continue&lt;/code&gt; statements provide us with this control.&lt;/p&gt;

&lt;h4&gt;
  
  
  Break
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;break&lt;/code&gt; statement immediately exits a loop, regardless of the loop’s condition.&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="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;...&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;break&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Output:&lt;/span&gt;
&lt;span class="c1"&gt;// 1&lt;/span&gt;
&lt;span class="c1"&gt;// 2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Continue
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;continue&lt;/code&gt; statement skips the current iteration of a loop and jumps to the next iteration.&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="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;...&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;continue&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Output:&lt;/span&gt;
&lt;span class="c1"&gt;// 1&lt;/span&gt;
&lt;span class="c1"&gt;// 2&lt;/span&gt;
&lt;span class="c1"&gt;// 4&lt;/span&gt;
&lt;span class="c1"&gt;// 5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Loops are powerful tools for repeating code efficiently, and &lt;code&gt;break&lt;/code&gt; and &lt;code&gt;continue&lt;/code&gt; provide additional control over loop execution. Understanding how to use loops effectively is essential for building complex and efficient algorithms in Swift. Now, let’s move on to another important aspect of Swift programming: functions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Functions: Reusable Code Blocks
&lt;/h2&gt;

&lt;p&gt;Functions are like mini-programs within your Swift code. They allow you to encapsulate a block of code that performs a specific task, making your code more organized, reusable, and easier to maintain.&lt;/p&gt;

&lt;p&gt;Let’s break down the fundamentals of functions in Swift.&lt;/p&gt;

&lt;h3&gt;
  
  
  Basic Function Definition
&lt;/h3&gt;

&lt;p&gt;To define a function, we use the &lt;code&gt;func&lt;/code&gt; keyword followed by the function’s name and parentheses &lt;code&gt;()&lt;/code&gt;. You can optionally add parameters within the parentheses. The code block that executes when the function is called is enclosed in curly braces &lt;code&gt;{}&lt;/code&gt;.&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="kd"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello, &lt;/span&gt;&lt;span class="se"&gt;\(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="s"&gt;!"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Laura"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 

&lt;span class="c1"&gt;// Output: Hello, Laura!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we define a function named &lt;code&gt;greet&lt;/code&gt; that takes a single parameter &lt;code&gt;name&lt;/code&gt; of type &lt;code&gt;String&lt;/code&gt;. The function prints a greeting message to the console. We call the function by using its name followed by parentheses and passing the argument “Laura” for the &lt;code&gt;name&lt;/code&gt; parameter.&lt;/p&gt;

&lt;h3&gt;
  
  
  Returning Values
&lt;/h3&gt;

&lt;p&gt;Functions can also return values. We use the &lt;code&gt;return&lt;/code&gt; keyword to specify the value to be returned. The return type is specified after the parentheses in the function definition.&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="kd"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;getGreet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s"&gt;"Hello, &lt;/span&gt;&lt;span class="se"&gt;\(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="s"&gt;!"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;greet&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;getGreet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Laura"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Output: Hello, Laura!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you have a function with a single-line, you can suppress the &lt;code&gt;return&lt;/code&gt; keyword.&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="kd"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;getGreet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="s"&gt;"Hello, &lt;/span&gt;&lt;span class="se"&gt;\(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="s"&gt;!"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;greet&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;getGreet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Laura"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Output: Hello, Laura!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Default Values for Parameters
&lt;/h3&gt;

&lt;p&gt;We can provide default values for function parameters, making our functions more flexible. If a value is not provided when calling the function, the default value will be used.&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="kd"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;getGreet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Hello"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\(&lt;/span&gt;&lt;span class="n"&gt;greeting&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="s"&gt;, &lt;/span&gt;&lt;span class="se"&gt;\(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="s"&gt;!"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;greetLaura&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;getGreet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Laura"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;greetLaura&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Output: Hello, Laura!&lt;/span&gt;

&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;greetAdrian&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;getGreet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Adrian"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Hi"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;greetAdrian&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Output: Hi, Adrian!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Functions That Can Throw Errors
&lt;/h3&gt;

&lt;p&gt;In Swift, we can define functions that can throw errors using the &lt;code&gt;throws&lt;/code&gt; keyword. This indicates that the function might not complete successfully and could throw an error.&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="kd"&gt;enum&lt;/span&gt; &lt;span class="kt"&gt;DivisionByZeroError&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Error&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="n"&gt;zeroDivision&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;divide&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;number1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;number2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;throws&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;Int&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;number2&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="kt"&gt;DivisionByZeroError&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;zeroDivision&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;number1&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;number2&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To use functions with &lt;code&gt;throws&lt;/code&gt; keyword you need to use the following syntax to ensure you’ll capture the exception error:&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="k"&gt;do&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="nf"&gt;divide&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;number1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;number2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="kt"&gt;DivisionByZeroError&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;zeroDivision&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Error: Division by zero."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"An error occurred."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, the &lt;code&gt;divide&lt;/code&gt; function throws a &lt;code&gt;DivisionByZeroError&lt;/code&gt; if the &lt;code&gt;number2&lt;/code&gt; is 0. We use a &lt;code&gt;do-catch&lt;/code&gt; block to handle the error: the &lt;code&gt;try&lt;/code&gt; keyword indicates that the code inside the block might throw an error, and the &lt;code&gt;catch&lt;/code&gt; block handles the thrown error.&lt;/p&gt;

&lt;p&gt;Functions are fundamental building blocks of Swift code, making our programs more modular, reusable, and efficient. Next, we’ll explore another powerful feature: closures.&lt;/p&gt;

&lt;h2&gt;
  
  
  Closures: Passing Code as Values
&lt;/h2&gt;

&lt;p&gt;Closures are blocks of code that can be passed around like variables. They’re incredibly versatile, allowing you to encapsulate behavior and reuse it in different parts of your code. Imagine closures as self-contained mini-programs that can be executed on demand. In SwiftUI is very important to understand about this concept. Let’s dive into it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Basic Closures
&lt;/h3&gt;

&lt;p&gt;The simplest way to create a closure is to use curly braces &lt;code&gt;{}&lt;/code&gt;. A closure without parameters can be defined like this:&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="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;greet&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello, world!"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;// Output: Hello, world!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We assign this closure to a constant named &lt;code&gt;greet&lt;/code&gt;. To execute the closure, we call it like a function. If you think about the type of this closure, it’s &lt;code&gt;() -&amp;gt; Void&lt;/code&gt;, because it’s a function without parameter, and without return. It can be represented this way:&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="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;Void&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello, world!"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;// Output: Hello, world!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It’s the same.&lt;/p&gt;

&lt;h3&gt;
  
  
  Closures with Parameters and the “in” Keyword
&lt;/h3&gt;

&lt;p&gt;Closures can also take parameters and have return values. We use the “in” keyword to separate the parameters and return type from the closure’s code block.&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="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;greet&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello, &lt;/span&gt;&lt;span class="se"&gt;\(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="s"&gt;!"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Laura"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 

&lt;span class="c1"&gt;// Output: Hello, Laura!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This closure has a parameter of type &lt;code&gt;String&lt;/code&gt; without return. The type can be represented as &lt;code&gt;(String) -&amp;gt; Void&lt;/code&gt;, and you can write this closure this way too:&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="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;Void&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello, &lt;/span&gt;&lt;span class="se"&gt;\(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="s"&gt;!"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Laura"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;// Output: Hello, Laura!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also, your closure can return a value.&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="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;greet&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s"&gt;"Hello, &lt;/span&gt;&lt;span class="se"&gt;\(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="s"&gt;!"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Laura"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Output: Hello, Laura!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the closure type is &lt;code&gt;(String) -&amp;gt; String&lt;/code&gt;. You can write the same closure above this way:&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="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s"&gt;"Hello, &lt;/span&gt;&lt;span class="se"&gt;\(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="s"&gt;!"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Laura"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Output: Hello, Laura!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But where can we use it? In Swift is very common you see a function with a “completion handler”. Usualy, it is a closure that is called when some operations finish, like an animation or a data load. Let’s se an example:&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="kd"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;registerNewUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;completionHandler&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;Void&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Make a long operation like call an API or change a database&lt;/span&gt;
    &lt;span class="c1"&gt;// After it, call the completion handler&lt;/span&gt;
    &lt;span class="nf"&gt;completionHandler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;greet&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello, &lt;/span&gt;&lt;span class="se"&gt;\(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="s"&gt;!"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;registerNewUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Laura"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;completionHandler&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;// Output after the long operation: Hello, Laura!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We create a function called &lt;code&gt;registerNewUser&lt;/code&gt; with two parameters. The first one is the &lt;code&gt;name&lt;/code&gt; and the second one is a &lt;code&gt;closure&lt;/code&gt; that expect a parameter of type &lt;code&gt;String&lt;/code&gt; and without return represented with &lt;code&gt;Void&lt;/code&gt; keyword.&lt;/p&gt;

&lt;h3&gt;
  
  
  Shorthand Syntax for Trailing Closures
&lt;/h3&gt;

&lt;p&gt;Swift provides a shorthand syntax for trailing closures when the closure is the last argument and it has only a single expression. We can just omit the closure parameter declaration and embed it at the trailing. I’ll consider the same &lt;code&gt;registerNewUser&lt;/code&gt; function showed previously, and I’ll embed the &lt;code&gt;greet&lt;/code&gt; closure using the shorthand syntax.&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="nf"&gt;registerNewUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Laura"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello, &lt;/span&gt;&lt;span class="se"&gt;\(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="s"&gt;!"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Very easy, and clear. You’ll see it a lot in SwiftUI.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;We’ve covered a lot of exciting ground in this second part of “100DaysOfSwiftUI”! We’ve explored control flow, loops, functions, and closures — powerful features that allow us to create more dynamic and sophisticated Swift code (closures specially).&lt;/p&gt;

&lt;p&gt;Mastering these concepts is like unlocking a new level of proficiency in Swift programming. These tools provide us with the ability to make decisions, repeat actions efficiently, and encapsulate reusable code blocks, which are crucial for building complex and interactive applications in SwiftUI.&lt;/p&gt;

&lt;p&gt;As we continue our journey through the “100 Days of SwiftUI” challenge, remember that practice is key. Experiment with these concepts, try out different examples, and don’t hesitate to ask questions. The more you practice, the more comfortable you’ll become with these essential tools.&lt;/p&gt;

&lt;p&gt;I encourage you to explore further, and remember, every line of code you write brings you closer to mastering Swift!&lt;/p&gt;

&lt;p&gt;Stay tuned for the next part of the “100DaysOfSwiftUI” series, where we’ll delve into structs and access control, expanding our knowledge of Swift programming even more.&lt;/p&gt;

</description>
      <category>100daysofswiftui</category>
    </item>
    <item>
      <title>Swift Essentials: Variables, Data Types, and More (Part 1)</title>
      <dc:creator>Ione Souza Junior</dc:creator>
      <pubDate>Fri, 05 Jul 2024 00:00:00 +0000</pubDate>
      <link>https://dev.to/ionixjunior/swift-essentials-variables-data-types-and-more-part-1-2iak</link>
      <guid>https://dev.to/ionixjunior/swift-essentials-variables-data-types-and-more-part-1-2iak</guid>
      <description>&lt;p&gt;I'm diving headfirst into the "100 Days of SwiftUI" challenge by Paul Hudson, and I'm thrilled to be on this journey of discovery. But before I can create dazzling iOS apps, I know that building a strong foundation in Swift is crucial. This blog series, which I'm calling "100DaysOfSwiftUI," is my way of sharing my learning journey with you, especially those who are new to Swift. We'll explore the fundamental building blocks of this powerful language together. In this first part, we'll tackle the core concepts of variables, data types, string interpolation, and enums. These seemingly simple elements are the pillars upon which we'll build more complex and powerful applications in SwiftUI. So buckle up, grab your coffee (or your preferred drink!), and let's embark on this journey together! We'll cover the basics in a clear and engaging way, and by the end, you'll have a solid grasp of the foundational concepts that will empower you to start crafting your own iOS apps.&lt;/p&gt;

&lt;p&gt;If you don’t know about the &lt;a href="https://www.hackingwithswift.com/100/swiftui" rel="noopener noreferrer"&gt;100 Days of SwiftUI&lt;/a&gt;, please check out this link.&lt;/p&gt;

&lt;h2&gt;
  
  
  Variables and Constants: Storing Data with Flexibility and Immutability
&lt;/h2&gt;

&lt;p&gt;In the world of programming, we often need to store data. We have two primary tools for doing this: &lt;strong&gt;variables&lt;/strong&gt; and &lt;strong&gt;constants&lt;/strong&gt;. Both act as containers for data, but they differ in their flexibility:&lt;/p&gt;

&lt;h3&gt;
  
  
  Variables: The Changeable Ones
&lt;/h3&gt;

&lt;p&gt;Variables are like labeled boxes in our code that hold data that can be modified. We use the &lt;code&gt;var&lt;/code&gt; keyword to declare a variable:&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="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Laura"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can change the value of &lt;code&gt;name&lt;/code&gt; at any point in our code:&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="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Laura Smith"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, &lt;code&gt;name&lt;/code&gt; holds the value “Laura Smith”.&lt;/p&gt;

&lt;h3&gt;
  
  
  Constants: The Immutable Ones
&lt;/h3&gt;

&lt;p&gt;Constants are like sealed containers. Once you define a constant, its value cannot be changed. We use the &lt;code&gt;let&lt;/code&gt; keyword to declare a constant:&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="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Laura"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This sets &lt;code&gt;name&lt;/code&gt; to the value “Laura”, and we cannot assign a different value to it later.&lt;/p&gt;

&lt;p&gt;Constants are good for preventing accidental changes to important values, ensuring data integrity. They also make your code clearer and more predictable, as the values they hold are fixed.&lt;/p&gt;

&lt;p&gt;So, consider this when deciding how to use variables and constants in your code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Data Types: Defining the Nature of Data
&lt;/h2&gt;

&lt;p&gt;In programming, we need a way to categorize the kinds of data our variables and constants can hold. These categories are called &lt;strong&gt;data types&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Think of data types as defining the “nature” or “essence” of the data. They tell Swift how to interpret and manipulate the information. Here are some essential data types in Swift:&lt;/p&gt;

&lt;h3&gt;
  
  
  String: For Textual Data
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;String&lt;/code&gt; data type represents textual information. It’s used to store anything that can be written or displayed, such as names, addresses, sentences, and even code.&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="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Laura"&lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Hello!"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Int: For Whole Numbers
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;Int&lt;/code&gt; data type represents whole numbers (integers), such as 1, 10, 25, 1000, and so on. Integers are commonly used in counters, calculations, and for representing quantities.&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="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;numberOfItems&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Float, Double and Decimal: Representing Numbers with Precision
&lt;/h3&gt;

&lt;p&gt;In Swift, we have three primary data types for representing numbers with decimal points: &lt;code&gt;Float&lt;/code&gt;, &lt;code&gt;Double&lt;/code&gt;, and &lt;code&gt;Decimal&lt;/code&gt;. While they all handle fractional values, they differ in their precision and memory usage:&lt;/p&gt;

&lt;h4&gt;
  
  
  Float: Lower Precision, Smaller Range
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;Float&lt;/code&gt; uses 32 bits of memory to store its value, offering a smaller range of values and less precision than &lt;code&gt;Double&lt;/code&gt;. It’s generally used when memory efficiency is a priority and lower precision is acceptable.&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="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;floatNumber&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Float&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;0.00001&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Double: High Precision, Large Range
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;Double&lt;/code&gt; is the most common choice for representing floating-point numbers in Swift. It provides a high degree of precision, making it suitable for calculations requiring a wide range of values. &lt;code&gt;Double&lt;/code&gt; uses 64 bits of memory to store its value, which is twice the size of &lt;code&gt;Float&lt;/code&gt;.&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="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;doubleNumber&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Double&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;0.00001&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Decimal: High Precision, Financial Calculations
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;Decimal&lt;/code&gt; is specialized for handling financial calculations where accuracy is paramount. It offers a high degree of precision, especially for numbers with a large number of decimal places. However, it is less computationally efficient than &lt;code&gt;Double&lt;/code&gt; or &lt;code&gt;Float&lt;/code&gt; due to its focus on accuracy. &lt;code&gt;Decimal&lt;/code&gt; is a base-10 number representation that provides high precision, allowing you to store a lot of numbers.&lt;/p&gt;

&lt;p&gt;To create a &lt;code&gt;Decimal&lt;/code&gt; value, you can use the following syntax:&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="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;decimalNumber&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Decimal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;0.00001&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Type Annotations
&lt;/h4&gt;

&lt;p&gt;As you can see in the samples above, there’s only one keyword that changed in these examples: the type. Here, the type defines what kind of numeric value you’ll store. This is called “type annotations,” and you can use it for all data types or structures.&lt;/p&gt;

&lt;p&gt;You can create a numeric value simply by creating a variable and assigning a value, but it will be created as a &lt;code&gt;Double&lt;/code&gt; type by default.&lt;/p&gt;

&lt;h3&gt;
  
  
  Bool: For Logical Values
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;Bool&lt;/code&gt; data type represents boolean values, which can be either &lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt;. Bools are fundamental for decision-making in your code, helping you create conditional statements and logical expressions.&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="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;isAdmin&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;hasError&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Arrays, Dictionaries, and Sets
&lt;/h2&gt;

&lt;p&gt;So far, we’ve explored data types for individual values: strings, numbers, booleans. But often, we need to store collections of data—multiple values related to each other. This is where arrays, dictionaries, and sets come in handy.&lt;/p&gt;

&lt;h3&gt;
  
  
  Arrays: Ordered Collections of Values
&lt;/h3&gt;

&lt;p&gt;Arrays are ordered lists of elements of the same data type. Think of them as numbered boxes where you can store a collection of related items. You access elements in an array by their index, starting from zero.&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="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;cities&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"Barcelona"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"London"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"São Paulo"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cities&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="c1"&gt;// Output: Barcelona (first element)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cities&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;span class="c1"&gt;// Output: São Paulo (third element)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Arrays are useful when you need an ordered list of elements of the same type.&lt;/p&gt;

&lt;h3&gt;
  
  
  Dictionaries: Key-Value Pairs
&lt;/h3&gt;

&lt;p&gt;Dictionaries are unordered collections of key-value pairs. Each key is unique and maps to a corresponding value. Think of dictionaries like a real-world dictionary, where each word (key) has a definition (value).&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="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;userData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Laura"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"surname"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Smith"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"city"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"London"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;userData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="c1"&gt;// Output: Optional("Laura")&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;userData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"city"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="c1"&gt;// Output: Optional("London")&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Dictionaries are useful when you need to store and retrieve data based on unique keys.&lt;/p&gt;

&lt;h3&gt;
  
  
  Sets: Unique and Unordered Collections
&lt;/h3&gt;

&lt;p&gt;Sets are unordered collections of unique elements. They don’t allow duplicates, making them useful for checking membership and removing duplicates from a collection.&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="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;uniqueNames&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;Set&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="s"&gt;"Laura"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Josh"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Laura"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Marie"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Josh"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;uniqueNames&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Output: 3 (duplicates removed)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Sets are useful when you need to work with unique values or when you want to check for membership quickly - this structure is very fast.&lt;/p&gt;

&lt;h2&gt;
  
  
  Enums: Defining Related Values
&lt;/h2&gt;

&lt;p&gt;Enums, short for enumerations, are a powerful way to define a custom type that represents a set of related values. They provide a more structured and readable way to represent choices or states within your code, compared to using raw integers.&lt;/p&gt;

&lt;p&gt;Think of enums as creating a vocabulary of specific terms related to a particular concept. For example, imagine you’re building an app that handles order status. Instead of using raw integers like 0, 1, and 2, you can create an enum to represent the order states:&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="kd"&gt;enum&lt;/span&gt; &lt;span class="kt"&gt;OrderStatus&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="n"&gt;pending&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="n"&gt;processing&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="n"&gt;shipped&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="n"&gt;delivered&lt;/span&gt; 
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="n"&gt;cancelled&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, instead of using numbers, you can directly use the enum values:&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="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;orderStatus&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;OrderStatus&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pending&lt;/span&gt; 
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;orderStatus&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Output: OrderStatus.pending&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Enums improve readability. They make your code more self-documenting and easier to understand. They also enforce type safety, preventing you from accidentally assigning incorrect values.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cool Things
&lt;/h2&gt;

&lt;h3&gt;
  
  
  String Interpolation
&lt;/h3&gt;

&lt;p&gt;An easy way to concatenate strings without using “+” is using interpolation:&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="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Laura"&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;surname&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Smith"&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"The name of the winner is &lt;/span&gt;&lt;span class="se"&gt;\(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="s"&gt; &lt;/span&gt;&lt;span class="se"&gt;\(&lt;/span&gt;&lt;span class="n"&gt;surname&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="s"&gt;!"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Multi-line Strings
&lt;/h3&gt;

&lt;p&gt;Sometimes we need to create a multi-line string, and this is very easy in Swift. You just use triple quotes and write your string inside them. Just ensure that the triple quotes are declared on a different line from the string.&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="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;multilineMessage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"""
This is the multi-line message.
You can add a lot of lines.
Don't worry about it!
"""&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Bools and the Toggle Function
&lt;/h3&gt;

&lt;p&gt;When you create a variable, you can change its value later. So, we can create a bool value and change it using the &lt;code&gt;toggle&lt;/code&gt; function.&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="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;isAdmin&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;isAdmin&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Output: false&lt;/span&gt;

&lt;span class="n"&gt;isAdmin&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toggle&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;isAdmin&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Output: true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Dictionary Default
&lt;/h3&gt;

&lt;p&gt;As you can see in the dictionary example, when we access the key, we get an optional. This occurs because Swift can’t ensure that there is a value in that key. Because of this, Swift gives us an optional. You can handle this using a property called &lt;code&gt;default&lt;/code&gt;. This way you don’t get an optional, and your code won’t break if you handle the optional without careful.&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="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;userData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Laura"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"surname"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Smith"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"city"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"London"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;userData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="c1"&gt;// Output: Optional("Laura")&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;userData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Unknown"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="c1"&gt;// Output: Laura&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;userData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"nickname"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Unknown"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="c1"&gt;// Output: Unknown&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;We’ve covered a lot of ground in this first part of “100DaysOfSwiftUI”! We’ve explored variables, constants, data types, string interpolation, enums, and some collection types. These concepts are essential for understanding how data is stored, manipulated, and used in your code.&lt;/p&gt;

&lt;p&gt;Understanding these fundamentals is like having a solid foundation upon which you can build more complex structures in your SwiftUI journey. Imagine them as the bricks and mortar that make up the walls of your iOS apps.&lt;/p&gt;

&lt;p&gt;I encourage you to practice these concepts, experiment with different examples, and don’t hesitate to ask questions. Share your thoughts and experiences in the comments below!&lt;/p&gt;

&lt;p&gt;Stay tuned for the next part, and let’s continue to build our Swift knowledge together!&lt;/p&gt;

</description>
      <category>100daysofswiftui</category>
    </item>
    <item>
      <title>My 100 Days of Swift: Cool Projects &amp; What I Learned</title>
      <dc:creator>Ione Souza Junior</dc:creator>
      <pubDate>Fri, 28 Jun 2024 00:00:00 +0000</pubDate>
      <link>https://dev.to/ionixjunior/my-100-days-of-swift-cool-projects-what-i-learned-1hhn</link>
      <guid>https://dev.to/ionixjunior/my-100-days-of-swift-cool-projects-what-i-learned-1hhn</guid>
      <description>&lt;p&gt;A while ago I completed the 100 Days of Swift challenge by Paul Hudson. It was an amazing experience where I learned a lot about Swift and iOS development. In today's post, I'll share my thoughts about this journey and highlight some of the most interesting things I encountered. Let's dive in!&lt;/p&gt;

&lt;p&gt;If you search online for “100 days of Swift,” you’ll find various resources. When I began my search, I chose Paul Hudson’s program. You can find it &lt;a href="https://www.hackingwithswift.com/100" rel="noopener noreferrer"&gt;here&lt;/a&gt;. Some people asked me why I started with UIKit instead of SwiftUI. Well, I believe both are important, so I decided to begin with UIKit.&lt;/p&gt;

&lt;p&gt;For anyone starting their iOS development journey, I highly recommend following a structured path like this. You’ll face challenges, practice consistently, and learn something new every day. The dynamic is simple: learn and practice. I’m excited to share some highlights from my experience.&lt;/p&gt;

&lt;h2&gt;
  
  
  The First 12 Days
&lt;/h2&gt;

&lt;p&gt;The first 12 days were dedicated to Swift basics, but even with seemingly simple concepts, I learned valuable things.&lt;/p&gt;

&lt;h3&gt;
  
  
  Making Large Numbers Legible
&lt;/h3&gt;

&lt;p&gt;When working with large numbers, you can use underscores as thousands separators. This doesn’t change the number’s value; it just makes it easier to read.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var balance = 10_000_000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Exiting Multiple Loops
&lt;/h3&gt;

&lt;p&gt;If you have multiple nested loops, you can name each loop to create a &lt;code&gt;break&lt;/code&gt; condition for exiting. It’s a good alternative to using &lt;code&gt;goto&lt;/code&gt; (remember those? 😅).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;outerLoop: for i in 1...5 {
    for j in 1...5 {
        print ("\ (i) - \(j)")

        if j == 3 {
            break outerLoop
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These might seem like small details, but I found them quite useful.&lt;/p&gt;

&lt;h2&gt;
  
  
  Starting iOS Projects
&lt;/h2&gt;

&lt;p&gt;After mastering Swift basics, I began working on iOS projects, which opened a world of new possibilities. Let’s revisit some of the coolest features I encountered and some things I’ve tried.&lt;/p&gt;

&lt;h3&gt;
  
  
  Environment Overrides
&lt;/h3&gt;

&lt;p&gt;Xcode provides an option called “environment overrides.” Basically, you can change settings like appearance, text, and accessibility to test your app in different scenarios. It’s incredibly easy to check your app in various environments.&lt;/p&gt;


    
    Your browser does not support video playback.


&lt;h3&gt;
  
  
  Debug Description in UI Tests
&lt;/h3&gt;

&lt;p&gt;When running UI tests, you can set a breakpoint and type &lt;code&gt;po app.debugDescription&lt;/code&gt; in the output window. This will show a “REPL” (Read-Eval-Print Loop) that helps you understand the UI elements you can interact with on the screen. This is incredibly useful for analyzing UI elements during testing.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fionixjunior.dev%2Fassets%2Fimg%2Fxcode_uitests_debug.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fionixjunior.dev%2Fassets%2Fimg%2Fxcode_uitests_debug.webp" alt="Xcode showing the UI elements on the screen in the output window." width="800" height="400"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Xcode showing the UI elements on the screen in the output window.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Unresponsiveness UI Warnings
&lt;/h3&gt;

&lt;p&gt;This is a very helpful feature. Xcode alerted me when I performed expensive operations on the UI thread, such as loading a URL from the internet. These types of issues are easy to fix, and I appreciated Xcode’s warnings that helped me improve my implementation.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fionixjunior.dev%2Fassets%2Fimg%2Fxcode_unresponsiveness_ui_warning.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fionixjunior.dev%2Fassets%2Fimg%2Fxcode_unresponsiveness_ui_warning.webp" alt="Xcode showing an unresponsiveness UI warning in a content loaded from a URL." width="800" height="400"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Xcode showing an unresponsiveness UI warning in a content loaded from a URL.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  River Raid - A Tiny Version
&lt;/h3&gt;

&lt;p&gt;In addition to UIKit, I also explored a bit of SpriteKit. This was not a challenge from Paul Hudson training, but some lessons that I’ve developed helped me to built it. I’ve made just for fun. I had an Atari, so I’ve played River Raid a lot!&lt;/p&gt;


    
    Your browser does not support video playback.


&lt;h3&gt;
  
  
  Memory Game
&lt;/h3&gt;

&lt;p&gt;I also created a simple memory game. To test it, I developed UI tests to verify that all cards could be flipped and that the game could be completed successfully. It was a rewarding project.&lt;/p&gt;


    
    Your browser does not support video playback.


&lt;h2&gt;
  
  
  100 Days of Practice == A Great Evolution
&lt;/h2&gt;

&lt;p&gt;Some chapters of this training were repetitive, but they served a purpose: solidifying knowledge. Before embarking on this journey, I felt the need to continuously develop something every day, to learn and practice consistently. The 100 Days of Swift challenge provided the perfect framework for this goal and introduced me to excellent content.&lt;/p&gt;

&lt;p&gt;If you’re interested in following my entire journey, you can check out &lt;a href="https://x.com/ionixjunior/status/1569005323314425859" rel="noopener noreferrer"&gt;this tweet&lt;/a&gt;. Also, all projects that I developed are hosted on this &lt;a href="https://github.com/ionixjunior/100DaysOfSwift" rel="noopener noreferrer"&gt;GitHub project&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I’m thinking about starting the &lt;a href="https://www.hackingwithswift.com/100/swiftui" rel="noopener noreferrer"&gt;100 Days of SwiftUI&lt;/a&gt; challenge, also by Paul Hudson. What do you think? Would you like to join me on this adventure? Remember, consistency is key! Every day counts, and with dedication, you can achieve incredible things in your coding journey. So, let’s keep learning and growing together!&lt;/p&gt;

</description>
      <category>swift</category>
    </item>
    <item>
      <title>The Power of Patience and Persistence: How to Thrive in the Ever-Evolving Tech Landscape</title>
      <dc:creator>Ione Souza Junior</dc:creator>
      <pubDate>Fri, 21 Jun 2024 00:00:00 +0000</pubDate>
      <link>https://dev.to/ionixjunior/the-power-of-patience-and-persistence-how-to-thrive-in-the-ever-evolving-tech-landscape-48dd</link>
      <guid>https://dev.to/ionixjunior/the-power-of-patience-and-persistence-how-to-thrive-in-the-ever-evolving-tech-landscape-48dd</guid>
      <description>&lt;p&gt;There's a lot to study if you choose any Software Engineering position. You can develop desktop, web, mobile, IoT applications, and each of these options have huge possibilities for you to choose or specialize in. A common question, mainly for a newbie is: when will I be a master in this technology? This is a difficult question to answer, isn't it? Technology evolves fast and all the time we face things changing. This can cause some nervousness and stress, because it's a little bit difficult to not get things under control. So, in today's post, I'll share some of my thoughts about it. Take a coffee or any drink you prefer, have a seat, and let's get started.&lt;/p&gt;

&lt;p&gt;I’ve been working with software development since 2008. I’ve already worked in six different companies, and I felt I and my colleagues were looking for the same objective: to be a master in some technology. Everybody who wants to learn, usually, wants to be a master in some subject, but how fast can we achieve this to acquire the knowledge we want?&lt;/p&gt;

&lt;p&gt;Well, all of us, IT guys, love to say: it depends! That’s the absolute truth for this question. It depends, because each of us have different ways to learn. Some people like to learn by watching videos, another one likes to learn by reading blog posts, other people like to roll up their sleeves and dive into the code. So, it depends. Do you agree with this?&lt;/p&gt;

&lt;p&gt;Another thing that I believe is very important to understand: learning is different from knowing. You can watch a bunch of videos about some specific content, and that’s okay. You learn about it. But did you really understand it? Do you really know about it? You watched some course in 2x velocity and are you prepared for the fight? If you need to get your hands dirty, can you put into practice what you’ve learned? Did you really learn the concepts?&lt;/p&gt;

&lt;p&gt;And last, but not least: the time. This is another factor in the equation. Most of us want to learn very fast, and a lot of things. There’s a lot of abilities that we can learn and practice, but what we really need to focus at first to feel comfortable? This is important to think to you understand when to stop or when to go easy on yourself.&lt;/p&gt;

&lt;h2&gt;
  
  
  My Point Of View
&lt;/h2&gt;

&lt;p&gt;When we want to learn something or want to achieve an objective, we create expectations. We want to change, to make a career transition, to learn a new technology or just to start in the field. Sometimes we know what we want, but we don’t know the path to achieve it. So, in this case, it’s very common to immerse yourself in studying everything you come across. Do you want to achieve your objective, right? How much time do you believe you’ll need to get it? Three or six months? One year? And what’s your plan B? Do you have one? It’s not difficult to start trying to learn all the things, but if you don’t have a clear path, you can get only anxiety and fear.&lt;/p&gt;

&lt;p&gt;This usually happens when you try to learn too much at once. Learning a lot of things doesn’t mean knowing these things. You need to practice, and you need time to develop the new abilities. This can cause anxiety, because if you don’t have a clear path, you can see there’s a lot of new things to learn. You start learning just one new thing, and you discover there are five or ten new concepts to look for. That’s okay! You’re not alone. If you don’t have a clear path to focus on what’s more important, you can feel a little anxious, because you won’t stop to look for new content. All you’ll see isn’t enough, and you won’t enjoy your journey. This is terrible.&lt;/p&gt;

&lt;p&gt;It can cause fear too. If you understand that there’s always a lot of things to learn, and you don’t feel confident with your knowledge, how can you work properly if you’re always concerned about your own knowledge?&lt;/p&gt;

&lt;h2&gt;
  
  
  You Can Learn With Your Mistakes
&lt;/h2&gt;

&lt;p&gt;I’ve already faced this situation in different stages of my career. The first one in 2008 when I started in the field as a Web Developer. In that year, I was almost a Webmaster, because I needed to learn about web applications, databases, manage Linux servers, and all the things that an IT guy does — including fixing printers. At the beginning of my career, I didn’t have a clear path to follow, I just learned a lot of things, fast, and practiced a lot. I learned a lot practicing, and I worked all the time. It was very tiring, but I evolved a lot.&lt;/p&gt;

&lt;p&gt;The second stage of my career that I faced a change was in 2014 when I started as a Mobile Developer working with Xamarin Forms. I had a challenge to develop a sales representative application for Android, iOS, and Windows, but as a Web Developer, I had no idea what was necessary to learn, so I started again to learn all content that I found and practice a lot. In this period, I was always worried about learning mobile development. It was a period of time that I’ve grown a lot again, but it cost my mental health. Some people may think this is bullshit, but only I know what I felt.&lt;/p&gt;

&lt;p&gt;In 2019, I made a new move, and started as a Mobile Engineer. Despite continuing to work with mobile development, there was something different: I started to work more closely to the native Android and iOS APIs. I started to work all day with the Xamarin Traditional approach. This may seem like nothing, but it was a big change for me. I felt I didn’t have enough good knowledge to stay there. Honestly, I knew that I had a good knowledge about software development, but not about mobile development, because I had been working with Xamarin Forms for a long time. So, I needed to start to learn again. Tiring, isn’t it? Well, but this time was different for me, because I was (and continue) in a good place, and it provides me to finally enjoy my learning path.&lt;/p&gt;

&lt;p&gt;I was determined to try something different in 2019. I didn’t want to repeat the same cycle.&lt;/p&gt;

&lt;h2&gt;
  
  
  Calm Down And Enjoy The Learning Path
&lt;/h2&gt;

&lt;p&gt;To keep calm and enjoy the learning path, I accept that I never will be a master of everything. This was very difficult for me, because I put a lot of pressure on myself. I want to be the best, so accepting this was not easy.&lt;/p&gt;

&lt;p&gt;What is working for me is to think about the following questions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;What knowledge do I need to develop to make myself confident and allow me to move on?&lt;/li&gt;
&lt;li&gt;Where and how can I get this new knowledge?&lt;/li&gt;
&lt;li&gt;How much time will I invest to achieve this?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Is it difficult to answer these questions? If you don’t have the habit or ability to reflect about yourself, this can be a big challenge. You need to know about yourself, what you want, and how much are you willing to sacrifice. This can be difficult, but understanding this is very important. Let’s explore these questions.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. What knowledge do I need to develop to make myself confident and allow me to move on?
&lt;/h3&gt;

&lt;p&gt;This is very particular to each one. You need to think about what knowledge you’ll focus on learning and practicing that will make you more confident and prepared for the challenges in your career. So, think: what do you want to learn?&lt;/p&gt;

&lt;p&gt;Do you want to learn about backend development? Maybe you should start learning about the basics of databases, HTTP protocol, and RESTful APIs.&lt;/p&gt;

&lt;p&gt;Do you want to learn about frontend development? Maybe you should start learning about HTML, CSS, JavaScript, and responsive design.&lt;/p&gt;

&lt;p&gt;Do you want to learn about mobile development? Maybe you should start learning about view controllers / activities / fragments, UI components, and life cycle.&lt;/p&gt;

&lt;p&gt;You need to choose what path you want to follow, and understand what knowledge you need to learn that allows you to move on without problems.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Where and how can I get this new knowledge?
&lt;/h3&gt;

&lt;p&gt;Today there are a lot of resources that you can use to learn about anything. YouTube videos, blog posts, courses at &lt;a href="https://www.linkedin.com/learning/" rel="noopener noreferrer"&gt;LinkedIn Learning&lt;/a&gt;, &lt;a href="https://www.pluralsight.com" rel="noopener noreferrer"&gt;Pluralsight&lt;/a&gt;, &lt;a href="https://www.udemy.com" rel="noopener noreferrer"&gt;Udemy&lt;/a&gt;, &lt;a href="https://www.alura.com.br" rel="noopener noreferrer"&gt;Alura&lt;/a&gt;, &lt;a href="https://backfront.com.br/backfront-plus" rel="noopener noreferrer"&gt;BackFront Plus&lt;/a&gt;, or even free content on YouTube.&lt;/p&gt;

&lt;p&gt;I think this topic is a little bit interesting, because I was born in 1987, and I grew up without the new technologies that we use today. My first computer I won when I was 15 years old, and the internet was dial-up. Today, we turn on our computers and smartphones, and all the time we’re connected, with a lot of content on the palm of our hands. But even with a lot of content to consume, I think sometimes we don’t know where to find good content or where to start. So, the most important is: just start. It’s better than do nothing.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. How much time will I invest to achieve this?
&lt;/h3&gt;

&lt;p&gt;Now you already know what knowledge you want to develop, where the resources are, and you need to think about how much time you’ll invest to achieve this. How much time? One hour per day? Two, maybe? Between three and six hours per week? You need to organize your agenda and put your learning path into your routine. Don’t you have time at the moment? No problem, but you can’t feel frustrated with this, and this situation needs to be very clear to you.&lt;/p&gt;

&lt;p&gt;It’s not a problem to not have time now. It’s a problem if you want to make a change and not dedicate on it. No pain, no gain.&lt;/p&gt;

&lt;h3&gt;
  
  
  Things to care about
&lt;/h3&gt;

&lt;p&gt;Focus means setting a target and sticking to it. So, if you plan to study a lot of things, maybe you’re starting wrong, or you won’t achieve your plans properly. I’m telling you this because it’s humanly impossible to start learning many things at the same time and be productive in all of them. There are some exceptions, but focus means starting something and ensuring you evolve it until the end. Think about it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sharing My Experiences
&lt;/h2&gt;

&lt;p&gt;I’ve dedicated this session to share my last experiences. Maybe something can help you to clear the learning path.&lt;/p&gt;

&lt;h3&gt;
  
  
  Experience 1: Start Working With iOS And Android Native APIs
&lt;/h3&gt;

&lt;p&gt;As I said previously, in 2019 I started as a Mobile Engineer to work with Xamarin Traditional, more closely to iOS and Android native APIs. This was a great challenge for me, because I was used to working only with Xamarin Forms. At that time, Xamarin Forms was very evolved, and each new application didn’t need a lot of custom renderers to work properly anymore. This meant that native knowledge was less crucial, allowing developers to focus on the shared code for most of their work.&lt;/p&gt;

&lt;p&gt;Well, my scenario changed, and I needed a plan to study. I knew I needed to study a lot of things, and I tried to answer the three questions.&lt;/p&gt;

&lt;h4&gt;
  
  
  1. What knowledge do I need to develop to make myself confident and allow me to move on?
&lt;/h4&gt;

&lt;p&gt;This is very strange, but for me, to feel comfortable, I didn’t need much:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Master how to create screens with dynamic lists and content.&lt;/li&gt;
&lt;li&gt;Master how to navigate between screens.&lt;/li&gt;
&lt;li&gt;Master how to communicate between screens.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Very simple, right? Yeah, simple, but I needed to master these things to feel more comfortable in my new job. I knew all the concepts, but I didn’t work with them until that moment. There’s a big difference between only learning about something and truly understanding it, in practice. All of this knowledge I needed to evolve on both platforms, but more on iOS.&lt;/p&gt;

&lt;h4&gt;
  
  
  2. Where and how can I get this new knowledge?
&lt;/h4&gt;

&lt;p&gt;Well, I don’t remember exactly where I studied, but I remember looking for courses at Udemy, Pluralsight, and some content on YouTube. All very practical training. On Pluralsight, I remember taking the following courses:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://app.pluralsight.com/library/courses/swift3-fundamentals/table-of-contents" rel="noopener noreferrer"&gt;Swift Fundamentals&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://app.pluralsight.com/library/courses/ios-11-fundamentals/table-of-contents" rel="noopener noreferrer"&gt;iOS 11 Fundamentals&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://app.pluralsight.com/library/courses/ios-collection-views-getting-started/table-of-contents" rel="noopener noreferrer"&gt;iOS Collection Views: Getting Started&lt;/a&gt; - very good&lt;/li&gt;
&lt;li&gt;&lt;a href="https://app.pluralsight.com/library/courses/ios-data-persistence-big-picture/table-of-contents" rel="noopener noreferrer"&gt;iOS Data Persistence: The Big Picture&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://app.pluralsight.com/library/courses/ios-networking-rest-apis/table-of-contents" rel="noopener noreferrer"&gt;iOS Networking with REST APIs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://app.pluralsight.com/library/courses/ios-auto-layout-fundamentals/table-of-contents" rel="noopener noreferrer"&gt;iOS Auto Layout Fundamentals&lt;/a&gt; - 36%&lt;/li&gt;
&lt;li&gt;&lt;a href="https://app.pluralsight.com/library/courses/android-apps-kotlin-build-first-app/table-of-contents" rel="noopener noreferrer"&gt;Developing Android Applications with Kotlin: Getting Started&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://app.pluralsight.com/library/courses/android-apps-kotlin-tools-testing/table-of-contents" rel="noopener noreferrer"&gt;Android Apps with Kotlin: Tools and Testing&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://app.pluralsight.com/library/courses/android-apps-kotlin-recyclerview-navigation-drawer/table-of-contents" rel="noopener noreferrer"&gt;Android Apps with Kotlin: RecyclerView and Navigation Drawer&lt;/a&gt; - 67%&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  3. How much time will I invest to achieve this?
&lt;/h4&gt;

&lt;p&gt;I usually dedicate many hours to studying. This is how it works for me. When I face a new challenge, I like to dive deep into it. I have the privilege of being able to find time for this. My wife supports me and helps me a lot. I usually dedicate between one and two hours a day, including weekends, because my wife loves to wake up late, and I wake up early to study more time when we stay home.&lt;/p&gt;

&lt;p&gt;I hoped to see progress in about a year, and it came. Over time, the tasks became easier. This was a sign to me that I was achieving my objective. I continue studying and evolving, but with less pressure on myself.&lt;/p&gt;

&lt;p&gt;This basic knowledge helped me to continue growing in my position. Maybe you’re thinking: why did you study iOS and Android native approaches with Swift and Kotlin instead of C# with Xamarin? Well, I believe if you master native development and understand how each platform works, you will reduce doubt when you’re facing problems on mobile development with Xamarin. Something goes wrong? What’s wrong? Is it Xamarin or is it iOS / Android? Understanding the core concepts in the native language helps me many times to not blame Xamarin when I faced problems. I’ve seen this sometimes happen when people blamed Xamarin Forms, but the real problem lied within the platforms themselves.&lt;/p&gt;

&lt;h3&gt;
  
  
  Experience 2: Start To Focus On Mastering iOS Development With Swift
&lt;/h3&gt;

&lt;p&gt;Last year I wrote about it, and you can find this post &lt;a href="https://dev.to/ionixjunior/my-journey-in-mobile-development-from-c-to-swift-3mjm"&gt;here&lt;/a&gt;. So, here I am thinking about the questions again.&lt;/p&gt;

&lt;h4&gt;
  
  
  1. What knowledge do I need to develop to make myself confident and allow me to move on?
&lt;/h4&gt;

&lt;p&gt;Over the last few years working with Xamarin Traditional, I’ve learned a lot about iOS, but now I have some specific necessities to feel comfortable to be an iOS Engineer in the future. For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Master memory management&lt;/li&gt;
&lt;li&gt;Master parallelism and concurrency&lt;/li&gt;
&lt;li&gt;Master closures in Swift&lt;/li&gt;
&lt;li&gt;Master View Code&lt;/li&gt;
&lt;li&gt;Learn how to build the same things in SwiftUI that I know how to build with UIKit&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  2. Where and how can I get this new knowledge?
&lt;/h4&gt;

&lt;p&gt;To my surprise, I found a lot of content on LinkedIn Learning, but I’ve started this journey using &lt;a href="https://backfront.com.br/backfront-plus" rel="noopener noreferrer"&gt;BackFront Plus&lt;/a&gt;. They have great paid content, and the videos about iOS development are fantastic, very well explained. If you have the opportunity, I highly recommend it to you.&lt;/p&gt;

&lt;p&gt;Also, I like the content of &lt;a href="https://www.hackingwithswift.com" rel="noopener noreferrer"&gt;Paul Hudson&lt;/a&gt;. He has a lot of great free content. The same is true for &lt;a href="https://www.youtube.com/@seanallen" rel="noopener noreferrer"&gt;Sean Allen&lt;/a&gt;, and &lt;a href="https://www.youtube.com/@CodeWithChris" rel="noopener noreferrer"&gt;CodeWithChris&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Another interesting thing that I’m trying now is to practice in a real project. I love to create a project from scratch and test concepts on it. But there’s a problem: when you’re in a “hello world” project, learning tends to be somewhat limited. So I decided to practice trying to contribute to a real open-source project. I shared about it in &lt;a href="https://dev.to/ionixjunior/you-dont-need-to-be-a-senior-to-contribute-to-open-source-projects-48k4"&gt;this post&lt;/a&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  3. How much time will I invest to achieve this?
&lt;/h4&gt;

&lt;p&gt;Today, I’m investing at least one hour from Monday to Friday, and some hours on Saturday. My intention here is to study and practice until I feel confident to contribute to open-source projects.&lt;/p&gt;

&lt;p&gt;To be confident is subjective, right? Well, in my context, feel confident means contribute and create solutions without too much difficulty. That’s it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Need Tips To Find Where Or What To Study?
&lt;/h2&gt;

&lt;p&gt;There’s a site called &lt;a href="https://roadmap.sh" rel="noopener noreferrer"&gt;roadmap.sh&lt;/a&gt;, that is a community effort to create roadmaps, guides, and other educational content to help guide developers in picking up a path and guide their learnings. Check this out!&lt;/p&gt;

&lt;p&gt;Another great resource is &lt;a href="https://medium.com/@ronanrodrigo/follow-this-path-a-study-guide-for-software-development-with-swift-180ba093a752" rel="noopener noreferrer"&gt;a study guide for software development with Swift&lt;/a&gt;. I didn’t finish it, but I found great content there.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Will You Learn Now?
&lt;/h2&gt;

&lt;p&gt;The path to mastery in tech is a journey, not a destination. It’s about finding the right balance between learning and practicing, focusing on what matters most to you, and understanding that you don’t need to know everything to make progress.&lt;/p&gt;

&lt;p&gt;Embrace the power of patience and persistence — it’s your key to conquering the ever-evolving tech landscape. Start by identifying what you want to learn, find the resources that suit your learning style, and dedicate the time you can to reach your goals.&lt;/p&gt;

&lt;p&gt;Don’t be afraid to make mistakes, learn from them, and keep moving forward. Remember, every new skill you acquire adds value to your career and empowers you to build incredible things. So, take that first step, stay curious, and enjoy the learning journey!&lt;/p&gt;

</description>
      <category>career</category>
    </item>
  </channel>
</rss>
