<?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: Silvia España Gil</title>
    <description>The latest articles on DEV Community by Silvia España Gil (@silviaespanagil).</description>
    <link>https://dev.to/silviaespanagil</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%2F662375%2Fc7950ed0-0c6c-459d-aeed-b4e8fe09e814.jpg</url>
      <title>DEV Community: Silvia España Gil</title>
      <link>https://dev.to/silviaespanagil</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/silviaespanagil"/>
    <language>en</language>
    <item>
      <title>The 5 Stages of Grief in Tech Layoffs - a story</title>
      <dc:creator>Silvia España Gil</dc:creator>
      <pubDate>Wed, 11 Dec 2024 23:00:00 +0000</pubDate>
      <link>https://dev.to/silviaespanagil/the-5-stages-of-grief-in-tech-layoffs-a-story-23c4</link>
      <guid>https://dev.to/silviaespanagil/the-5-stages-of-grief-in-tech-layoffs-a-story-23c4</guid>
      <description>&lt;p&gt;&lt;sup&gt;This is my personal journey through tech layoffs and how the classic stages of grief showed up in unexpected ways. No psychology degree, just my story&lt;/sup&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Hola Mundo!
&lt;/h2&gt;



&lt;p&gt;Theory says that when we lose something important, we go through 5 stages of grief. And yes, I know that losing my job is not equal from losing a loving one, however, I discovered that going through a layoff is surprisingly similar. &lt;/p&gt;

&lt;p&gt;So get ready for this emotional rollercoaster ride of getting laid off. 🎢&lt;/p&gt;




&lt;h3&gt;
  
  
  1. Denial: "This can't be happening to me" 🙈
&lt;/h3&gt;



&lt;p&gt;If you read &lt;a href="https://dev.to/silviaespanagil/anatomia-de-un-layoff-del-rumor-al-paro-8oo"&gt;my previous post&lt;/a&gt;, I said that the first stage of the layoff was the rumors. And this stage was really tied up with that moment.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;"These rumors must be false"&lt;/li&gt;
&lt;li&gt;"They can't get rid of &lt;em&gt;insert here your project&lt;/em&gt;"&lt;/li&gt;
&lt;li&gt;"My performance is great surely I will be saved"&lt;/li&gt;
&lt;li&gt;"Changes are normal, surely they won't layoff too many people"&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Spoiler alert: Yes, the rumors can be true. Yes, they can get rid of any project or professional if they want to. &lt;/p&gt;

&lt;h3&gt;
  
  
  2. Anger: "They can't do this" 🤬
&lt;/h3&gt;

&lt;p&gt;Sadly, yes, they can.&lt;/p&gt;

&lt;p&gt;Anger was weird to me. I was angry but I didn't want to give them the power to make me angry. &lt;/p&gt;

&lt;p&gt;In this stage I promise I thought about all the bad decisions I thought the company took. Trying to answer myself why they did what they did, and how everything developed until this situation. &lt;/p&gt;

&lt;p&gt;I'm angry at the company&lt;br&gt;
I'm angry at the C-levels&lt;br&gt;
I'm angry at my past self for not noticing before.&lt;/p&gt;

&lt;p&gt;The deal is that, it's normal to be angry. My best advice here would be to speak up to your friends, family or mental health provider and be careful with what you post on social media or in your slack channel. Screenshots are forever 🙃.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Bargaining: "If only I had" 🤔
&lt;/h3&gt;

&lt;p&gt;Here we feel like we could have done something different to avoid this. And don't get me wrong, I knew I couldn't change this for the company but yes for me.&lt;/p&gt;

&lt;p&gt;Thoughts like "If I had not be so confortable maybe I would have search another job before...". But truth is that, there are no ifs, this is sooo out of our reach.&lt;/p&gt;

&lt;p&gt;Nothing I could have done, would have changed anything. Company decisions rarely have anything to do with you or me, unless you are a C-level!&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Depression: "I won't find another job" 😔
&lt;/h3&gt;

&lt;p&gt;This stage was TOUGH. &lt;/p&gt;

&lt;p&gt;If any of my close friends or family are reading this. Thank you, I survived thanks to all the support I had.&lt;/p&gt;

&lt;p&gt;Mind you this was my first job in the industry so my thoughts were pretty much like this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;"What if I was only good here?"&lt;/li&gt;
&lt;li&gt;"What if I bomb all the interviews"&lt;/li&gt;
&lt;li&gt;"We are mid summer, I won't find anything"&lt;/li&gt;
&lt;li&gt;"I can't compete with my ex peers"&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Remember: This is ok. Is ok to feel bad, even is ok to feel that you are not enough, but remember that not all you think is true. &lt;/p&gt;

&lt;p&gt;Try to sleep, be kind to yourself and then be objective. For me it helped to try new things, to remember the things I did and excelled in the past. &lt;/p&gt;

&lt;h3&gt;
  
  
  5. Acceptance: "Finally, is official" 😌
&lt;/h3&gt;

&lt;p&gt;Acceptance for me came with at end of the process. So it was pretty much 2-3 months until I was here. &lt;/p&gt;

&lt;p&gt;And don't get me wrong, I knew the layoff was going to happen, but I was in a different stage of my grief.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;I started to do some numbers to get my financials in order&lt;/li&gt;
&lt;li&gt;Did a couple of job interviews and felt myself again&lt;/li&gt;
&lt;li&gt;Remembered that life was not only this that I was living&lt;/li&gt;
&lt;li&gt;Told myself that this was an opportunity and good things will happen&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Bonus Track: The Revival 🌱
&lt;/h3&gt;

&lt;p&gt;This was another experience. I was not alone and after some exercise I also shushed that voice that was loud during the depression stage. &lt;/p&gt;

&lt;p&gt;There are more companies and I do have good skills. So yes, is scary, and definitely a change I was not expecting, however, this is a wave I can ride. &lt;/p&gt;

&lt;p&gt;If you are going through this, it's okay not to be okay. Maybe you will go through all these stages, or maybe yours will be different. &lt;/p&gt;

&lt;p&gt;I promise you, this will pass. An while it does, here's a post to remind you that you're not alone on this emotional rollercoaster 🎢❤️.&lt;/p&gt;

&lt;p&gt;&lt;sup&gt;P.S.: If this post made you smile even a little bit or helped you in the midst of chaos, my work here is done. Share it with someone who needs it! 🙌&lt;/sup&gt;&lt;/p&gt;

</description>
      <category>career</category>
      <category>experience</category>
      <category>layoffs</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Anatomía de un Layoff: del rumor al paro</title>
      <dc:creator>Silvia España Gil</dc:creator>
      <pubDate>Mon, 09 Dec 2024 11:58:05 +0000</pubDate>
      <link>https://dev.to/silviaespanagil/anatomia-de-un-layoff-del-rumor-al-paro-8oo</link>
      <guid>https://dev.to/silviaespanagil/anatomia-de-un-layoff-del-rumor-al-paro-8oo</guid>
      <description>&lt;p&gt;&lt;sup&gt;This post deviates from my blog's usual English content as I will be addressing the specific legal framework and emotional journey of corporate layoffs in Spain. The information and procedures discussed are particular to Spanish labor law.&lt;/sup&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Hola Mundo!
&lt;/h2&gt;



&lt;p&gt;Este año, la empresa para la que trabajaba decidió hacer un layoff. Uno de entre muchos que han estado ocurriendo en distintas empresas del sector, pero algo que se veía bastante lejano para mí, me afectó.&lt;/p&gt;

&lt;p&gt;Y te voy a ser 100% honesta. No esperaba que me tocara esta carta, pero me tocó vivir la experiencia de primera mano en HD 😔. Así que para mantener la costumbre decidí reflexionar un poco sobre el caos, las emociones y las lecciones que trajo esta experiencia consigo e hice este post.&lt;/p&gt;

&lt;p&gt;&lt;sup&gt;Este post está basado en mi experiencia personal y no es en lo absoluto consejo legal. No soy abogada, por lo que te recomiendo encarecidamente que busques asesoramiento profesional si te enfrentas a un despido.&lt;/sup&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  De los rumores a la realidad👂
&lt;/h3&gt;



&lt;p&gt;Dice el dicho que cuando el río suena es porque piedras trae. Primero fue una reestructuración, luego alguno puestos redundantes, luego un CEO que cambia y se le sumó un cambio de estrategia.&lt;/p&gt;

&lt;p&gt;La realidad es que estábamos pasando por una tómbola trimestral, no sabíamos qué tocaría. &lt;/p&gt;

&lt;p&gt;Sin embargo llegó momento en el que ya se podía sentir venir, plannings con poco que planear, proyectos "on-hold" mientras se redefinía una estrategia que nadie sabía quién estaba definiendo. El amigo de Pepito se enteraba que había una lista. Los calendarios de la nada tenían reuniones con bufetes de abogados, empresas de RRHH y similares. &lt;/p&gt;

&lt;p&gt;Se sentía. &lt;/p&gt;

&lt;p&gt;En las sabias palabras de Gandalf: "Es la respiración profunda antes de la zambullida" 🧙‍♂️&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feohly27m0os4jxad74l5.png" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feohly27m0os4jxad74l5.png" alt="imagen de Gandalf en Gondor cuando dice la frase citada" width="800" height="332"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  ¿Qué hacer en esta etapa? 📋
&lt;/h4&gt;



&lt;p&gt;En lo personal, si existiese el árbol de la ansiedad, yo sería su fruta. Así que empecé a hacer lo que mejor hago cuando siento que pierdo el control: planificar para el peor de los casos&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Infórmate&lt;/strong&gt;: Lee el estatuto de trabajadores. Habla con gente que conozcas que haya pasado por este proceso La información &lt;strong&gt;es poder&lt;/strong&gt;💡. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Mira el mercado&lt;/strong&gt;: ¿Cómo está el mercado?, ¿qué están pidiendo?, ¿mi CV o mis conocimientos se amoldan a lo que se busca?.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Actualiza tu CV/LinkedIn&lt;/strong&gt;: Actualiza tus perfiles, déjale reviews a tus compis y pídeles que te dejen alguna recomendación también.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Decide qué quieres hacer&lt;/strong&gt;: Pondera si quieres esperar a que te echen o si prefieres buscar trabajo e irte si lo consigues. Para esto haz cuentas, toma una decisión racional. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Mantente activa&lt;/strong&gt;: En mi caso decidí hacer proyectos pequeños 💻, tocar cosas que no me había atrevido antes, actualizarme un poco según lo que vi que el mercado pedía. En resumen, no me estuve quieta. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  La confirmación: Bienvenido a un ERE ⚖️
&lt;/h3&gt;

&lt;p&gt;&lt;br&gt;
&lt;sup&gt;En esta parte hablaré de cosas legales, no soy abogada, busca siempre asesoría&lt;/sup&gt;&lt;/p&gt;

&lt;p&gt;En España, si nos quieren hacer un despido colectivo la empresa debe hacer un ERE. Pero cuidado que algunas empresas son listas y despiden a la gente de a poquito. Si tu empresa en 3 meses despide al 10% de su plantilla eso es un ERE, si ellos no lo dicen como tal DENUNCIEN🚨. &lt;/p&gt;

&lt;p&gt;Recuerda también que si tu empresa intenta ofrecer regalos o algún bono, a cambio de que renuncies, &lt;strong&gt;no lo hagas&lt;/strong&gt;. Si te están ofreciendo esto quiere decir que en el ERE vas a poder negociar más, esto para ellos es mas barato, les permite enmascarar el hecho de que están haciendo un despido colectivo y tu además te quedas sin paro.&lt;/p&gt;

&lt;p&gt;Pero bueno, partamos del supuesto que la empresa hace un ERE de forma abierta. El primer paso es siempre avisar a los empleados que habrá un ERE. Y ahora viene lo bueno.&lt;/p&gt;

&lt;h4&gt;
  
  
  ¿Qué hacer durante la confirmación del ERE?
&lt;/h4&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Elegir los representantes&lt;/strong&gt;: &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Una vez la empresa avisa a los empleados su intención de hacer un ERE, nosotros tenemos, por ley, 15 días para decidir los representantes.&lt;/p&gt;

&lt;p&gt;Ten en cuenta que los representantes son trabajadores, tus compis o tu. Y la cantidad depende del tamaño de la empresa, nosotros debíamos decidir tres representantes. &lt;/p&gt;

&lt;p&gt;Los representantes de los trabajadores estarán en todas las reuniones de negociación con la empresa y legalmente tienen el poder de aceptar o rechazar lo que la empresa proponga.&lt;/p&gt;

&lt;p&gt;Decidan por personas que se den a escuchar, que sean comunicativas ya que tendrán que compartir con el resto lo que se hable en estas reuniones y que tengan el tiempo y disposición de hacer esto.&lt;/p&gt;

&lt;p&gt;¿Cómo hicimos nosotros? pues se creó el grupo de WhatsApp mas loco que he visto en mi vida, la gente se postuló e hicimos una votación por Drive.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Elegir abogados&lt;/strong&gt;: &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Con los representantes de los trabajadores elegidos, el siguiente paso es buscar abogados que nos ayuden. &lt;/p&gt;

&lt;p&gt;Ten en cuenta que esto debe estar definido en los 15 días que da la ley ya que el día que empiezan las negociaciones ya deben estar presentes los abogados y representantes de ambas partes.&lt;/p&gt;

&lt;p&gt;Si tu empresa dice "no se gasten el dinero, les vamos a dar un buen acuerdo" &lt;strong&gt;no confíen&lt;/strong&gt;. Si la empresa les propone regalos o acuerdos extras para que renuncien &lt;strong&gt;no confíen&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;En este momento, &lt;strong&gt;no confíes en la empresa&lt;/strong&gt;, piensa que ellos ahora tienen que iniciar un proceso legal ante el estado, en el que deben por ley indemnizarte y ellos sí que están asesorándose con abogados para intentar ahorrar la mayor cantidad de dinero posible.&lt;/p&gt;

&lt;p&gt;Nuestro grupo decidió conversar con dos grupos, los representantes nos dijeron que nos proponían esos abogados y realizamos una votación según lo que nos dijeron.&lt;/p&gt;

&lt;p&gt;Nosotros contratamos al Colectiú Ronda, y estuvimos muy felices. En general estos abogados cobran una tarifa fija cuando inicia el proceso y luego un porcentaje por sobre lo que ellos consiguen en la negociación.&lt;/p&gt;

&lt;p&gt;¿Qué quiere decir esto?, que mientras ellos más consiguen, más cobras tu y también ellos, claro. Entonces es un ganar-ganar. &lt;/p&gt;

&lt;p&gt;Por ejemplo, si tu empresa les ofrece 1000€ de indemnización y los abogados te consiguen 2000€. Pues ellos cobran un porcentaje sobre los 1000€ extras que consiguieron. &lt;/p&gt;

&lt;p&gt;Antes de que las negociaciones empiecen, trasladaremos a nuestros abogados que es lo que desearíamos obtener. Esto es una carta a los reyes magos, un ideal. Los abogados nos dirán también qué es lo normal que se ofrezca en estos casos y luego en las negociaciones intentarán obtener nuestro ideal.&lt;/p&gt;

&lt;p&gt;Aquí hablamos de por ejemplo, incluir quedarnos los portátiles o que extiendan visas, que se tomen ciertas consideraciones con personas embarazadas o de baja, extender el seguro etc. A ver, aquí entra de todo. Podemos pedir lo que queramos, los abogados nos darán una guía e intentarán negociar todo lo que puedan.&lt;/p&gt;

&lt;p&gt;Nosotros también definimos con los abogados dos canales de comunicación. Uno era un drive de preguntas generales, que nos podían valer a todos. Nosotros dejábamos la pregunta, ellos la respondían ahí o hacíamos una reunión para responder preguntas.&lt;/p&gt;

&lt;p&gt;Y un segundo canal de comunicación para particularidades. Por ejemplo, si tienes jornada reducida quizás tienes dudas de cómo te afecta esto a ti. Al ser una pregunta muy específica usabas este canal para que ellos pudiesen darte respuesta a tus inquietudes. De esa forma si querías hablar de algo mas privado o personal, tenías también este espacio.&lt;/p&gt;




&lt;h3&gt;
  
  
  Las negociaciones 🤝
&lt;/h3&gt;



&lt;p&gt;Terminados los 15 días iniciales empieza un mes de negociaciones. En este mes no hay mucho que hacer. Los abogados hablarán entre ellos. &lt;/p&gt;

&lt;p&gt;En la primera reunión seguro la empresa dará la oferta inicial que normalmente es ABSURDAMENTE MALA. Y los abogados harán un requerimiento inicial que normalmente es ABSURDAMENTE BUENO.&lt;/p&gt;

&lt;p&gt;Este proceso es bastante frustrante😓, pero nuestros abogados nos lo advirtieron. Ellos nos dijeron que normalmente la empresa niega todo durante 3 semanas de la negociación y es en los últimos 3 días que realmente empieza la negociación.&lt;/p&gt;

&lt;p&gt;Mi experiencia fue 100% esa. La empresa negó &lt;strong&gt;TODO&lt;/strong&gt; lo que pedimos y su oferta era mala. Finalmente el acuerdo se logró el último día de negociación. &lt;/p&gt;

&lt;h4&gt;
  
  
  ¿Qué hacer durante las negociaciones?
&lt;/h4&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Paciencia&lt;/strong&gt;: No hay nada peor de que te digan "tranquila". Pero este proceso dura &lt;strong&gt;un mes&lt;/strong&gt;. Y los avances, como comenté previamente son lentísimos. Intenta descansar, hacer cursos, lo que prefieras pero que mantenga tu mente un poco ocupada.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Confianza&lt;/strong&gt;: Contrataste abogados, ellos harán lo mejor posible porque mientras mejor lo hagan, mejor cobran. Así que confía en lo que dicen, en lo que hacen y en la información que te brindan.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Se considerada&lt;/strong&gt;: Durante este mes habrán reuniones para actualizar sobre las negociaciones. Nuestros representantes nos contarán cosas. Por favor se considerada, no les presiones, se respetuosa. Ellos están viviendo esto también y no es fácil.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Arma una red de apoyo&lt;/strong&gt;: Yo hice un grupo paralelo con mis amigas. Este proceso es largo y es una montaña rusa. Apóyales cuando estén nerviosas o se sientan mal, comparte con ellas como te sientes tu. Todos somos personas, nos sentimos de formas diferentes y poder pasar por esto en compañía y no solas es un beneficio invaluable.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  El desenlace: Aceptar - o no - el acuerdo 💭
&lt;/h3&gt;

&lt;p&gt;Como grupo teníamos mas o menos definido que era &lt;strong&gt;lo mínimo&lt;/strong&gt; que aceptaríamos. Para esto es importante escuchar y confiar en los abogados que nos mantuvieron con los pies en la tierra.&lt;/p&gt;

&lt;p&gt;Ellos nos dijeron que era lo normal en estos procesos, lo mas esperable y así también tuvimos algunos planteamientos base que eran lógicos. Y luego los extras que todos sabíamos que si los conseguíamos sería maravilloso.&lt;/p&gt;

&lt;p&gt;Cuando la negociación termina, nuestros abogados y representantes nos informaron de la oferta final de la empresa.&lt;/p&gt;

&lt;p&gt;Este día también nos enteramos de quienes estábamos en la lista de despedidos y quiénes no.  &lt;/p&gt;

&lt;p&gt;Se supone que por ley nuestros representantes podrían aceptar o no el acuerdo. Sin embargo los abogados que escogimos ponen como condición de contratación que se haga una votación, la decisión final es lo que vote la mayoría. &lt;/p&gt;

&lt;p&gt;Esto en lo particular nos gustó mucho porque de esa forma se siente un poco más transparente. Y en nuestro caso hablamos de una centena de personas que nos veíamos perjudicadas. Así que realizamos una votación en la que &lt;strong&gt;solo las personas perjudicadas&lt;/strong&gt; decidían si se tomaba o no el acuerdo final.&lt;/p&gt;

&lt;p&gt;Nosotros llegamos a un acuerdo. Si no se llega a un acuerdo el ERE igual ocurre, solo que podrás hablar con tus abogados para denunciar y llevar la decisión de la remuneración a un juzgado.&lt;/p&gt;

&lt;h4&gt;
  
  
  ¿Qué hacer durante el desenlace?
&lt;/h4&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Pregunta&lt;/strong&gt;: Si tienes dudas, aprovecha a los abogados. ¿Está bien lo que conseguimos?, ¿podemos conseguir más si vamos a juicio?, ¿se puede negociar la lista de los que se quedan?.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Prepárate&lt;/strong&gt;: Seguramente pronto pierdas accesos a tu cuenta de trabajo. Descarga toda la documentación que puedas necesitar luego, como nóminas o similares.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Recopila&lt;/strong&gt;: Recopila aquellas cosas que te puedan ayudar en el futuro: tus objetivos cumplidos o proyectos exitosos, guarda tus performance reviews, métricas que demuestran tu impacto, descarga certificados de formaciones. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Fin del ere: hora de paro 🏁
&lt;/h3&gt;

&lt;p&gt;Una vez se llega a un acuerdo la empresa enviará a cada persona su carta de despido. También deberán abonarte la indemnización acordada, las vacaciones pendientes y enviarte esta nómina final. &lt;/p&gt;

&lt;p&gt;Si decides cobrar el paro es importante que sepas que debes esperar a que terminen las vacaciones pendientes. Es decir, el despido es efectivo a final de mes, pero te quedaban pendientes 10 días de vacaciones. Podrás iniciar el proceso de paro el día 11.&lt;/p&gt;

&lt;p&gt;Esto ocurre porque la baja se hace efectiva el día que finalizan las vacaciones que ya están pagas. &lt;/p&gt;




&lt;h3&gt;
  
  
  Mi reflexión 🌱
&lt;/h3&gt;

&lt;p&gt;Este es un proceso bastante desagradable y difícil pero tenemos la suerte de tener una legislación que nos protege como trabajadores. Recuerda siempre que, las malas decisiones empresariales no son tu responsabilidad y si te ves afectada por un ERE no es tu culpa. &lt;/p&gt;

&lt;p&gt;No me cansaré de decirlo pero busca un grupo de abogados que te acompañen. Se buena persona siempre e intenta buscar una red de apoyo en medio de este caos🤗. &lt;/p&gt;

&lt;p&gt;Finalmente si este post te fue de alguna utilidad, no dudes en compartirlo con otras personas ❤️🙏.&lt;/p&gt;

</description>
      <category>career</category>
      <category>experience</category>
      <category>layoff</category>
    </item>
    <item>
      <title>Swift 101: Control flow - Loops, conditions, switch</title>
      <dc:creator>Silvia España Gil</dc:creator>
      <pubDate>Wed, 20 Nov 2024 12:50:22 +0000</pubDate>
      <link>https://dev.to/silviaespanagil/swift-101-control-flow-loops-conditions-switch-39fp</link>
      <guid>https://dev.to/silviaespanagil/swift-101-control-flow-loops-conditions-switch-39fp</guid>
      <description>&lt;h2&gt;
  
  
  Hola Mundo!
&lt;/h2&gt;



&lt;p&gt;Welcome to a new article into my &lt;a href="https://dev.to/silviaespanagil/swift-101-getting-into-ios-development-gji"&gt;Swift 101 series&lt;/a&gt; 📝. In this new chapter I'll be sharing a little bit about Control Flow.&lt;/p&gt;

&lt;p&gt;Today, we'll learn how to work with the data that we have stored in collections to use it and to make our code make decisions and repeat actions - just like we do in real life! &lt;/p&gt;

&lt;p&gt;Think of it this way: when you're following a recipe 👩🏽‍🍳, sometimes you repeat actions (like stirring), make decisions (like checking if it’s cooked enough?), or choose between different options (What if I don’t have an ingredient?). Control flow in programming helps us do just that: make decisions, repeat actions, and choose paths for our code to follow.&lt;/p&gt;

&lt;p&gt;So, let's get to it 💪​!&lt;/p&gt;






&lt;h2&gt;
  
  
  What is Control Flow?
&lt;/h2&gt;

&lt;p&gt;&lt;br&gt;
Control flow is the order in which our code's instructions will be executed. It's like being the conductor of an orchestra 🎭, telling each part when to play and under what conditions.&lt;/p&gt;

&lt;p&gt;It's our code structure and it will make decisions according to the conditions that are presented.&lt;/p&gt;

&lt;p&gt;In Swift, we have several ways to control our code's flow:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Loops&lt;/strong&gt; for repeating tasks 🔁&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Conditionals&lt;/strong&gt; for making decisions ⚖️&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Switch&lt;/strong&gt; statement for handling multiple options 🔀&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Loops: When You Need to Repeat Yourself 🔁
&lt;/h3&gt;

&lt;p&gt;Loops are Swift's way of doing something multiple times. It's like when you're doing exercises - "repeat this 10 times!" 🏋️‍♀️&lt;/p&gt;

&lt;p&gt;They are particularly powerful when working with collections. Remember those Arrays, Sets, and Dictionaries we learned about? Loops help us process each element in these collections efficiently, making it easy to perform operations on multiple pieces of data.&lt;/p&gt;

&lt;p&gt;There are many ways to do a loop in Swift: for-in, while, and repeat&lt;/p&gt;
&lt;h4&gt;
  
  
  &lt;strong&gt;- for-in loops:&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;In a &lt;code&gt;for-in&lt;/code&gt; loop, we iterate over a collection (like an array or set) and access each item one by one.&lt;/p&gt;

&lt;p&gt;The syntax in &lt;code&gt;for-in&lt;/code&gt; loops is pretty simple: &lt;code&gt;for itemName in collectionName { what will happen }&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;ingredients&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"flour"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"sugar"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"eggs"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"milk"&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;ingredient&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;ingredients&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;"Found &lt;/span&gt;&lt;span class="se"&gt;\(&lt;/span&gt;&lt;span class="n"&gt;ingredient&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="c1"&gt;// Output: &lt;/span&gt;
&lt;span class="c1"&gt;// Found flour ✓&lt;/span&gt;
&lt;span class="c1"&gt;// Found sugar ✓&lt;/span&gt;
&lt;span class="c1"&gt;// Found eggs ✓&lt;/span&gt;
&lt;span class="c1"&gt;// Found milk ✓&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;strong&gt;- while loops:&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;The while loops allow us to check a condition, so Swift will keep looping on our collection while the condition is true, and will stop once the condition fails.&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;temperature&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;
&lt;span class="k"&gt;while&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;75&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;"Still too hot! Cooling down..."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;temperature&lt;/span&gt; &lt;span class="o"&gt;-=&lt;/span&gt; &lt;span class="mi"&gt;10&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;"Ready to serve! 🍽️"&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;// Still too hot! Cooling down...&lt;/span&gt;
&lt;span class="c1"&gt;// Still too hot! Cooling down...&lt;/span&gt;
&lt;span class="c1"&gt;// Still too hot! Cooling down...&lt;/span&gt;
&lt;span class="c1"&gt;// Ready to serve! 🍽️&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example, the code inside the loop will execute while the temperature is greater than 75, when the 75 is reached then it will stop looping.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;- repeat loops:&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Not that common, &lt;code&gt;repeat&lt;/code&gt; loops work similar to &lt;code&gt;while&lt;/code&gt; loops but the condition is checked at the end.&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;tastings&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="k"&gt;repeat&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;"Tasting the sauce..."&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;"Adding seasoning"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;tastings&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="k"&gt;while&lt;/span&gt; &lt;span class="n"&gt;tastings&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;

&lt;span class="c1"&gt;// Output:&lt;/span&gt;
&lt;span class="c1"&gt;// Tasting the sauce...&lt;/span&gt;
&lt;span class="c1"&gt;// Adding seasoning&lt;/span&gt;
&lt;span class="c1"&gt;// Tasting the sauce...&lt;/span&gt;
&lt;span class="c1"&gt;// Adding seasoning&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;strong&gt;- Break and continue:&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;We may want to exit a loop during the iteration, maybe because one of many conditions are achieved. To do so we only need to write the word &lt;code&gt;break&lt;/code&gt;. This will stop the loop.&lt;/p&gt;

&lt;p&gt;On the other hand, we may want our loop to skip a specific condition, number, or value and continue iterating over the rest of the collection. And for this we may use the word &lt;code&gt;continue&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="c1"&gt;// Use of continue. Checking spoiled ingredients&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;ingredients&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"flour"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"expired_milk"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"eggs"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"sugar"&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;ingredient&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;ingredients&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;ingredient&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;contains&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"expired"&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;" &lt;/span&gt;&lt;span class="se"&gt;\(&lt;/span&gt;&lt;span class="n"&gt;ingredient&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="s"&gt; is spoiled. Skipping..."&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="s"&gt;"Adding &lt;/span&gt;&lt;span class="se"&gt;\(&lt;/span&gt;&lt;span class="n"&gt;ingredient&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="s"&gt; to mixture"&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;// Adding flour to mixture&lt;/span&gt;
&lt;span class="c1"&gt;// Milk is spoiled. Skipping...&lt;/span&gt;
&lt;span class="c1"&gt;// Adding eggs to mixture&lt;/span&gt;
&lt;span class="c1"&gt;// Adding sugar to mixture&lt;/span&gt;

&lt;span class="c1"&gt;// Use of break. Finding the first available cook&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;cooks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"busy"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"busy"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"available"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"busy"&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;status&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;cooks&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;status&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s"&gt;"available"&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;"Found available cook!"&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="p"&gt;}&lt;/span&gt;
&lt;span class="c1"&gt;// Output:&lt;/span&gt;
&lt;span class="c1"&gt;// Found available cook&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;








&lt;h3&gt;
  
  
  Conditional Statements
&lt;/h3&gt;

&lt;p&gt;As the name implies conditional statements help us to execute the code if those conditions are met or not. In Swift there are two type of conditionals: &lt;code&gt;if&lt;/code&gt; statement and &lt;code&gt;switch&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;👍 By using conditionals, we can make our code more intelligent and responsive! &lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;- if statement&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;if&lt;/code&gt; statement help us check if a condition is true, if this happens the code will get executed if not it will jump to the next condition that is true.&lt;/p&gt;

&lt;p&gt;Imagine you want to go out hiking, you may say, "if tomorrow is sunny, I will go to the mountain". Exactly like that will work on your code, if the condition is meet, then whatever you write down, will happen!&lt;/p&gt;

&lt;p&gt;🔎 When declaring &lt;code&gt;if&lt;/code&gt; statement there are a couple of rules you may need to follow &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;if&lt;/code&gt; statement must be followed by a condition which value must return a boolean.&lt;/li&gt;
&lt;li&gt;The condition must be followed by a piece of code to be executed between braces {}&lt;/li&gt;
&lt;li&gt;This code will only be executed if the returned value is true.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;else&lt;/code&gt; statement are optional and can be used to indicate a piece of code that will be executed when the &lt;code&gt;if&lt;/code&gt; condition is false.&lt;/li&gt;
&lt;li&gt;In the event that we could have many paths we can use &lt;code&gt;else if&lt;/code&gt; to check another possible condition.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Simplified will be&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;if&lt;/span&gt; &lt;span class="n"&gt;condition&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="n"&gt;this&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="k"&gt;do&lt;/span&gt; &lt;span class="n"&gt;that&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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;ovenTemperature&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;180&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;ovenTemperature&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;200&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;"Temperature too high! Lower it"&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;ovenTemperature&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;150&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;"Temperature too low! Increase it"&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;"Temperature is perfect!"&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;// Temperature is perfect!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example we have a piece of code that checks on the oven temperature. &lt;code&gt;if&lt;/code&gt; the temperature is over 200, will print that is too high, if is down 150 will say is too cold, if none of those conditions are meet that means that the temperature is perfect.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;else&lt;/code&gt; statement is optional, so you may only want something to happen and if the condition is not meet you don't want the code to do anything.&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;bakingTime&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;if&lt;/span&gt; &lt;span class="n"&gt;bakingTime&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;30&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;"Open the oven"&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;// Open the oven&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;strong&gt;- Multiple conditions for an &lt;code&gt;if&lt;/code&gt;&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;There's the possibility that we may need to check multiple conditions for something to happen. In this case we could use &lt;a href="https://dev.to/silviaespanagil/swift-101-basic-operators-a59"&gt;logical operators&lt;/a&gt; like &amp;amp;&amp;amp; (AND) and || (OR) to combine conditions in our &lt;code&gt;if&lt;/code&gt; 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;let&lt;/span&gt; &lt;span class="nv"&gt;hasIngredients&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;hasRecipe&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;hasIngredients&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;hasRecipe&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;"Let's start cooking!"&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;"We need to prepare better"&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;// Let's start cooking!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example we want to check if both conditions are meet. So &lt;code&gt;if&lt;/code&gt; we have both ingredients and recipe, we can start cooking. Otherwise we can't.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;- Ternary operators&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Ternary operators are &lt;code&gt;if&lt;/code&gt; statements but with a one line syntax. The syntax is &lt;code&gt;A ? B : C&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;✨​ Where ✨​&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A is the condition we want to check&lt;/li&gt;
&lt;li&gt;B is the code to execute if A is true (the if)&lt;/li&gt;
&lt;li&gt;C is the code to execute if A is false (the else)
&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="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;kitchenIsClean&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="n"&gt;kitchenIsClean&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;"Ready to cook!"&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;"Clean kitchen first!"&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;// Ready to cook!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;








&lt;h3&gt;
  
  
  Switch
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;switch&lt;/code&gt; statements allow us to compare the value of a condition with many cases until it finds one that matches.&lt;/p&gt;

&lt;p&gt;To use a &lt;code&gt;switch&lt;/code&gt; statement there are some things to take into consideration:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The conditional must be initiated with the &lt;code&gt;switch&lt;/code&gt; word&lt;/li&gt;
&lt;li&gt;Each case we want to evaluate goes with a name and two points to be executed &lt;code&gt;case caseName:&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;When the condition matches a case the code will be executed and the &lt;code&gt;switch&lt;/code&gt; will end. This means that no other conditions will be checked&lt;/li&gt;
&lt;li&gt;Similar to an &lt;code&gt;else&lt;/code&gt; statement, the &lt;code&gt;default&lt;/code&gt; code will be executed if no case matches.
&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="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;mealType&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"dessert"&lt;/span&gt;
&lt;span class="k"&gt;switch&lt;/span&gt; &lt;span class="n"&gt;mealType&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;"breakfast"&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;"Serving from 7-11 AM"&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;"lunch"&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;"Serving from 12-3 PM"&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;"dinner"&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;"Serving from 6-10 PM"&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;"dessert"&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;"Available all day!"&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;"Kitchen closed"&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;// Available all day!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example, Swift will check each case until it finds the one that matches the condition and will execute the code, in this case, a print.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;- Switch with Interval Matching&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;One of the &lt;code&gt;switch&lt;/code&gt; characteristics is that it allows us to check inside intervals for a match.&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;175&lt;/span&gt;
&lt;span class="k"&gt;switch&lt;/span&gt; &lt;span class="n"&gt;temperature&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;case&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;100&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;"Too cold!"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="mi"&gt;101&lt;/span&gt;&lt;span class="o"&gt;...&lt;/span&gt;&lt;span class="mi"&gt;160&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;"Getting there..."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="mi"&gt;161&lt;/span&gt;&lt;span class="o"&gt;...&lt;/span&gt;&lt;span class="mi"&gt;180&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;"Perfect temperature!"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="mi"&gt;181&lt;/span&gt;&lt;span class="o"&gt;...&lt;/span&gt;&lt;span class="mi"&gt;300&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;"Too hot!"&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;"Check thermometer!"&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;// Perfect temperature!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This demonstrates how you can use switch statements in Swift to match ranges of values, which is a very powerful way to handle different conditions that fall within specific intervals.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;- Compound cases&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Just as the interval matching allows us to check a range, compound cases allow us to add many values to a same case.&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;cookingMethod&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"baking"&lt;/span&gt;
&lt;span class="k"&gt;switch&lt;/span&gt; &lt;span class="n"&gt;cookingMethod&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;"baking"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"roasting"&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;"Use the oven"&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;"frying"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"sautéing"&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;"Use the stove"&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;"steaming"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"boiling"&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;"Use a pot with water"&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;"Check recipe for method"&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;// Use the oven&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;strong&gt;- Switch with Enums&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Remember the &lt;a href="https://dev.to/silviaespanagil/swift-101-enumerations-5h19"&gt;Enums&lt;/a&gt; we learned in the previous article? &lt;code&gt;switch&lt;/code&gt; statements work great with them! In fact, when using switch with enums, Swift requires us to handle all possible cases or include a default case this gives an extra layer of security, knowing that you are handling all cases in your enum.&lt;/p&gt;

&lt;p&gt;This combination of enum and switch is one of the most powerful features in Swift. Since enums have a finite set of cases, and &lt;code&gt;switch&lt;/code&gt; must be exhaustive, Swift can guarantee at compile time that we're handling all possible scenarios - making our code safer and more maintainable.&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;CookingStatus&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;preparing&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="n"&gt;cooking&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="n"&gt;ready&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="n"&gt;burned&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;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;CookingStatus&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;cooking&lt;/span&gt;
&lt;span class="k"&gt;switch&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;preparing&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;"Getting ingredients ready"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;cooking&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;"Keep an eye on the temperature!"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;ready&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;"Time to serve!"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;burned&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;"Order takeout..."&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;// Keep an eye on the temperature!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When using switch with enums🕵🏽‍♀️:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You don't need to specify the enum type in each case (writing .cooking)&lt;/li&gt;
&lt;li&gt;Swift will verify that you covered all possible cases&lt;/li&gt;
&lt;li&gt;If you don't want to handle all cases, you must include a default&lt;/li&gt;
&lt;li&gt;The compiler will give you an error if you miss a case and don't have a default &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;br&gt;
__&lt;/p&gt;

&lt;p&gt;By using control flow statements, we can enhance the logic and functionality of our code. They provide a clear way to handle different scenarios and repetitive tasks, making your code more organized and expressive.&lt;/p&gt;

&lt;p&gt;I hope this overview helps you appreciate the power of control flow in Swift and inspires you to continue learning this amazing language! 🤍&lt;/p&gt;






&lt;h3&gt;
  
  
  Want to keep learning about Swift?
&lt;/h3&gt;

&lt;p&gt;This a full series on &lt;a href="https://dev.to/silviaespanagil/swift-101-getting-into-ios-development-gji"&gt;Swift 101&lt;/a&gt;, the next chapter will be Functions and closures, so I hope to see you there!&lt;/p&gt;

&lt;p&gt;Remember that you can always go further into this information by checking the official documentation and courses &lt;a href="https://developer.apple.com/learn/" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you enjoyed this, please share, like, and comment. I hope this can be useful to someone and that it will inspire more people to learn and code with Swift&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>learning</category>
      <category>swift</category>
      <category>mobile</category>
    </item>
    <item>
      <title>How to Easily Use Feature Flags in Swift with Firebase</title>
      <dc:creator>Silvia España Gil</dc:creator>
      <pubDate>Mon, 16 Sep 2024 10:36:42 +0000</pubDate>
      <link>https://dev.to/silviaespanagil/how-to-easily-use-feature-flags-in-swift-with-firebase-1g4</link>
      <guid>https://dev.to/silviaespanagil/how-to-easily-use-feature-flags-in-swift-with-firebase-1g4</guid>
      <description>&lt;h2&gt;
  
  
  Hola mundo!
&lt;/h2&gt;



&lt;p&gt;I always like to start my posts by explaining why I’m writing an article, but feel free to skip this part if you’re in a hurry🏃🏽‍♀️.&lt;/p&gt;

&lt;p&gt;Back at my first job, there were these refinement sessions  where they’d say, "Should we protect this with a Feature Flag?" At that time, I had no idea what a Feature Flag was. When I finally asked a team member and learned about it, my mind was blown🤯. It felt like magic ​🔮 – a way to safely roll out changes without fear of breaking the app.  If something went wrong, you could just flip the Feature Flag. Simple as that!&lt;/p&gt;

&lt;p&gt;In that project, we used LaunchDarkly for managing Feature Flags. However, I recently discovered that Firebase has a feature for setting Feature Flags too, and the setup is ✨ SO EASY and user-friendly ✨ that I immediately fell in love with it. I couldn’t wait to share this with you!&lt;/p&gt;

&lt;p&gt;Today, I’m excited to show you &lt;strong&gt;how to implement Feature Flags in an iOS app using SwiftUI and Firebase Remote Config&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;If you’ve never used Feature Flags before, you’re in for a treat. This powerful tool lets you control your app’s features in real-time, &lt;strong&gt;without pushing updates to the App Store 🙌!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So, let's get to it 💪!&lt;/p&gt;






&lt;h2&gt;
  
  
  &lt;strong&gt;What’s a Feature Flag?&lt;/strong&gt;​.
&lt;/h2&gt;



&lt;p&gt;Before getting into the code, let’s quickly cover what a Feature Flag is. Imagine you’re working on an awesome new feature for your app, but you’re unsure whether to roll it out to all users or just a select few.&lt;/p&gt;

&lt;p&gt;Or perhaps the feature is quite big, and you want to start with the UI first, then add the business logic in stages.&lt;/p&gt;

&lt;p&gt;Feature Flags are your best friends here! They’re like switches you can toggle to turn functionalities on or off in real-time. No need to create new app versions and submit them to the Store.&lt;/p&gt;

&lt;p&gt;They’re fantastic for A/B testing, gradual rollouts, or controlling features during special events. Sounds amazing, right? &lt;/p&gt;

&lt;p&gt;Let’s get it set up!💻​&lt;/p&gt;

&lt;p&gt;📢​For the complete code used in this tutorial, be sure to check out &lt;a href="https://github.com/silviaespanagil/FirebaseFeatureFlagsWithSwift" rel="noopener noreferrer"&gt;my GitHub repository&lt;/a&gt;📢&lt;/p&gt;






&lt;h3&gt;
  
  
  &lt;strong&gt;👉🏽​ Step 1: Set Up Firebase in your iOS Project​.&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;br&gt;
First, you need to add Firebase to your project. Here’s how:&lt;/p&gt;

&lt;p&gt;1) &lt;strong&gt;Add Firebase to Your Xcode Project:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open your project in Xcode.&lt;/li&gt;
&lt;li&gt;Go to "File" &amp;gt; "Add Packages..." and enter the Firebase repository URL: &lt;code&gt;https://github.com/firebase/firebase-ios-sdk&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Choose the Firebase Remote Config package and add it to your project.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;2) &lt;strong&gt;Configure Firebase in Your App:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Go to the Firebase Console and create a new project.&lt;/li&gt;
&lt;li&gt;Follow the instructions to add an iOS app to your Firebase project (the guide is pretty straightforward).&lt;/li&gt;
&lt;li&gt;Download the &lt;code&gt;GoogleService-Info.plist&lt;/code&gt; file provided and add it to your Xcode project.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;👉🏽​Step 2: Initialise Firebase​.&lt;/strong&gt;
&lt;/h3&gt;



&lt;p&gt;Now that Firebase is set up we have to initialise it and use it. Let’s create a simple Proof of Concept (PoC) to see the power of Feature Flags in action.&lt;/p&gt;

&lt;p&gt;1) &lt;strong&gt;Initialise Firebase in your app&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Add this code to your &lt;code&gt;AppDelegate&lt;/code&gt;. You can check the official Firebase documentation if you need more details.&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;AppDelegate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;NSObject&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;UIApplicationDelegate&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;application&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="nv"&gt;application&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;UIApplication&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;didFinishLaunchingWithOptions&lt;/span&gt; &lt;span class="nv"&gt;launchOptions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;UIApplication&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;LaunchOptionsKey&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Any&lt;/span&gt;&lt;span class="p"&gt;]?&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;nil&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;Bool&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="kt"&gt;FirebaseApp&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;configure&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;true&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 in your app entry point, use &lt;code&gt;UIApplicationDelegateAdaptor&lt;/code&gt; to link your &lt;code&gt;AppDelegate&lt;/code&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;@main&lt;/span&gt;
&lt;span class="kd"&gt;struct&lt;/span&gt; &lt;span class="kt"&gt;FirebaseFeatureFlagsApp&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="kd"&gt;@UIApplicationDelegateAdaptor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;AppDelegate&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="k"&gt;self&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;delegate&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;h3&gt;
  
  
  &lt;strong&gt;👉🏽​Step 3: Configure Remote Config in Firebase&lt;/strong&gt;
&lt;/h3&gt;



&lt;p&gt;Now, let’s set up the Feature Flags in the Firebase Remote Config Console:&lt;/p&gt;

&lt;p&gt;1) &lt;strong&gt;Add parameters in Firebase Console:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Go to your Firebase Console and select the Remote Config option. &lt;/li&gt;
&lt;li&gt;Once in Remote Config, select the button &lt;code&gt;Add parameter&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;Choose the parameter name and the data type for the param&lt;/li&gt;
&lt;li&gt;Optional you can add a description, this is always a good idea&lt;/li&gt;
&lt;li&gt;Now set the default value that you want.&lt;/li&gt;
&lt;li&gt;Publish the changes&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwso17kuykof74ivj4xii.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwso17kuykof74ivj4xii.png" alt="Shows how the add parameter view looks in the firebase console"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;👉🏽​Step 4: Create a view that will use the Feature Flag&lt;/strong&gt;
&lt;/h3&gt;



&lt;p&gt;To visualize it, let’s create a simple view where the background colour changes based on the Feature Flag. As you may see in the code there's a boolean value &lt;code&gt;isBlueBackgroundEnabled&lt;/code&gt; that changes certain things including the background and the text colour.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;This value is my Feature Flag.&lt;/u&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;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="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;isBlueBackgroundEnabled&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;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;ZStack&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;isBlueBackgroundEnabled&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="kt"&gt;Color&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;blue&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;opacity&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Color&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pink&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;opacity&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
                &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;edgesIgnoringSafeArea&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;all&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

            &lt;span class="kt"&gt;HStack&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, Feature Flags!"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;font&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;foregroundColor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;isBlueBackgroundEnabled&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;white&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;black&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;"heart"&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;foregroundColor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;isBlueBackgroundEnabled&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;white&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;black&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;onTapGesture&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                        &lt;span class="nf"&gt;fetchRemoteConfig&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="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;onAppear&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nf"&gt;fetchRemoteConfig&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;h3&gt;
  
  
  &lt;strong&gt;👉🏽​Step 5: Fetch the Feature Flag value from Firebase&lt;/strong&gt;
&lt;/h3&gt;



&lt;p&gt;🔎​​​Please note the &lt;code&gt;.onAppear&lt;/code&gt; method in the previous example 🔎​&lt;/p&gt;

&lt;p&gt;As you see in our view I've called &lt;code&gt;fetchRemoteConfig()&lt;/code&gt; this method retrieves the current Feature Flag configuration from Firebase.&lt;/p&gt;

&lt;p&gt;Here’s how it works:&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;extension&lt;/span&gt; &lt;span class="kt"&gt;ContentView&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;configureRemoteConfig&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="nv"&gt;remoteConfig&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;RemoteConfig&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;settings&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;RemoteConfigSettings&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="n"&gt;settings&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;minimumFetchInterval&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; 
        &lt;span class="n"&gt;remoteConfig&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;configSettings&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;settings&lt;/span&gt;
        &lt;span class="n"&gt;remoteConfig&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setDefaults&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
            &lt;span class="s"&gt;"isBlueBackgroundEnabled"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;NSNumber&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
            &lt;span class="s"&gt;"isNewFeatureEnabled"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;NSNumber&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;value&lt;/span&gt;&lt;span class="p"&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;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;fetchRemoteConfig&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;remoteConfig&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;RemoteConfig&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;remoteConfig&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="nf"&gt;configureRemoteConfig&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;remoteConfig&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="n"&gt;remoteConfig&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;fetch&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;success&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;remoteConfig&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;activate&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt;
                    &lt;span class="c1"&gt;// Access your Feature Flags here&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;isBlueBackgroundEnabled&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;remoteConfig&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"isBlueBackgroundEnabled"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;boolValue&lt;/span&gt;
                    &lt;span class="c1"&gt;// Add all your Feature Flags&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;"Error fetching remote config: &lt;/span&gt;&lt;span class="se"&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;describing&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&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="p"&gt;}&lt;/span&gt;


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

&lt;/div&gt;
&lt;p&gt;🤔Curious about how these methods work? Let me break it down a bit for you🤔&lt;/p&gt;

&lt;p&gt;1) &lt;code&gt;configureRemoteConfig(_:)&lt;/code&gt;: This method sets up the Remote Config instance with settings. The &lt;code&gt;minimumFetchInterval&lt;/code&gt; of 0 is for development purposes, meaning you can fetch data from Firebase without waiting. &lt;br&gt;
&lt;code&gt;setDefaults&lt;/code&gt; sets a default value for the Feature Flag, which is used if there’s no configuration fetched.&lt;/p&gt;

&lt;p&gt;2) &lt;code&gt;fetchRemoteConfig()&lt;/code&gt;: This method is where the magic happens. It starts by fetching the latest configuration from Firebase. If the fetch is successful, it activates the new configuration and updates the Feature Flag state based on the fetched value. If something goes wrong, it prints an error message.&lt;/p&gt;

&lt;p&gt;📢​For the complete code used in this tutorial, be sure to check out &lt;a href="https://github.com/silviaespanagil/FirebaseFeatureFlagsWithSwift" rel="noopener noreferrer"&gt;my GitHub repository&lt;/a&gt;📢&lt;br&gt;
&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;🎉​Check what you did&lt;/strong&gt;
&lt;/h3&gt;



&lt;p&gt;Now for the fun part. 🏗️​Build your code.&lt;/p&gt;

&lt;p&gt;If you set your Feature Flag to &lt;code&gt;false&lt;/code&gt;, you should see a lovely pink background. Change the value to &lt;code&gt;true&lt;/code&gt; in the Remote Config Console, and voila 🪄 your background colour will change!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe0mleq729muc9vci2dhl.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe0mleq729muc9vci2dhl.gif" alt="Gif of the view changing colour depending on the value of the feature flag"&gt;&lt;/a&gt;&lt;/p&gt;






&lt;p&gt;And there you have it! Implementing Feature Flags with Firebase Remote Config is straightforward and incredibly powerful🔥. You can toggle features in real-time without needing to update the app, which makes your development process more flexible and efficient.&lt;/p&gt;

&lt;p&gt;I hope this guide helps you make your apps more dynamic and lets you experiment with new features with confidence🚀.&lt;br&gt;
&lt;/p&gt;




&lt;p&gt;If you enjoyed this, please share, like, and comment. I hope this can be useful to someone and that it will inspire more people to learn and code with Swift 💻✨&lt;/p&gt;

</description>
      <category>firebase</category>
      <category>tutorial</category>
      <category>swift</category>
      <category>development</category>
    </item>
    <item>
      <title>Swift 101: Enumerations</title>
      <dc:creator>Silvia España Gil</dc:creator>
      <pubDate>Thu, 05 Sep 2024 10:35:17 +0000</pubDate>
      <link>https://dev.to/silviaespanagil/swift-101-enumerations-5h19</link>
      <guid>https://dev.to/silviaespanagil/swift-101-enumerations-5h19</guid>
      <description>&lt;h1&gt;
  
  
  Hola Mundo!
&lt;/h1&gt;



&lt;p&gt;Welcome to a new article in a series of &lt;a href="https://dev.to/silviaespanagil/swift-101-getting-into-ios-development-gji"&gt;Swift 101 notes&lt;/a&gt; 📝  I created these notes while learning the language and decided to share them because why not?&lt;/p&gt;

&lt;p&gt;If you're new to Swift or interested in learning more about this language, I invite you to follow my series! 🙊&lt;/p&gt;

&lt;p&gt;In my last post, I shared &lt;a href="https://dev.to/silviaespanagil/swift-101-collections-part-iii-tuples-and-dictionaries-42p0"&gt;the third part of collections which was Tuples and Dictionaries&lt;/a&gt;. And this week is the time for Enumerations, one of my favourites collection types.&lt;/p&gt;

&lt;p&gt;So, let's get to it 💪​!&lt;/p&gt;




&lt;p&gt;As a quick refresher, "Collections" are types that store multiple values of the same type in an organized structure. These include Arrays, Sets, Tuples, and Dictionaries, which we have discussed in previous articles. &lt;/p&gt;

&lt;p&gt;Today, we'll focus on &lt;strong&gt;Enumerations&lt;/strong&gt;. While not a collection in the traditional sense, enums group related values together in a type-safe manner, making them a powerful tool for modelling sets of options or states in your code.&lt;/p&gt;

&lt;p&gt;Think of it like a fruit basket with many fruits in it. Similarly, arrays in Swift store multiple values of the same type in an ordered list, like a line of apples, oranges, and bananas neatly arranged in your basket 🍎​🍊​🍌​&lt;/p&gt;

&lt;p&gt;There are many types of Collections, like Arrays, Sets, Tuples and Dictionaries which we already discussed. Today, let's talk about ​​✨&lt;strong&gt;Enumerations​&lt;/strong&gt;✨​.&lt;/p&gt;






&lt;h3&gt;
  
  
  Enumerations
&lt;/h3&gt;

&lt;p&gt;&lt;br&gt;
Enums (short for enumerations) in Swift are a powerful type that allows you to group related values together in a type-safe way. They are commonly used to model a set of related choices or states in your code.&lt;/p&gt;

&lt;p&gt;By default, Swift will assume that our enum is a String unless we indicate otherwise.&lt;/p&gt;

&lt;p&gt;Here are some important characteristics and rules about Enums in Swift:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Fixed Set of Values:&lt;/strong&gt; Enums define a finite set of possible values (called cases). Once an enum is defined, you cannot add or remove cases, unless you change the Enum.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Type Safety:&lt;/strong&gt; Enums provide type safety by ensuring that any value associated with an enum is one of the predefined cases. This makes your code safer and easier to read.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;h4&gt;
  
  
  How to declare an Enum
&lt;/h4&gt;

&lt;p&gt;To declare an Enum you will have to use the &lt;code&gt;enum&lt;/code&gt; keyword followed by the enum's name and define the possible cases inside curly braces. Each case is introduced with the &lt;code&gt;case&lt;/code&gt; keyword.&lt;/p&gt;

&lt;p&gt;By default, Swift will assume that our enum is a String unless we indicate otherwise.&lt;/p&gt;

&lt;p&gt;Here's an example of how to declare and use an enum:&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;Movement&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;forward&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;back&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;left&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;right&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;enum&lt;/span&gt; &lt;span class="kt"&gt;Movement&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;forward&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="n"&gt;back&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="k"&gt;left&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="k"&gt;right&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔎​​​Please note that you can declare it in one or many lines. 🔎​&lt;/p&gt;






&lt;h4&gt;
  
  
  Enum RawValue
&lt;/h4&gt;

&lt;p&gt;When declaring an enum, we can decide to initialise it with an initial value. This allows the enum to work with these raw values and gives us the possibility to either use the enum case or map the values itself.&lt;/p&gt;

&lt;p&gt;Here’s how to define and use an enum with raw 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="kd"&gt;enum&lt;/span&gt; &lt;span class="kt"&gt;Movement&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;case&lt;/span&gt; &lt;span class="n"&gt;forward&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Move Forward"&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="n"&gt;back&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Go Back"&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="k"&gt;left&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Turn Left"&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="k"&gt;right&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Turn Right"&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;action&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;Movement&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="k"&gt;right&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;action&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;rawValue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;// Output: Turn Right&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When setting a type for the RawValue we can use any of the types that we have available in Swift.&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;StatusCode&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;case&lt;/span&gt; &lt;span class="n"&gt;success&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="n"&gt;notFound&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;404&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="n"&gt;serverError&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;500&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;code&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;StatusCode&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;notFound&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;code&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;rawValue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Output: 404&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;








&lt;h3&gt;
  
  
  Enums Managing: Using Enums Effectively
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Modifying Enum
&lt;/h4&gt;

&lt;p&gt;Enums in Swift are immutable by definition, meaning once they are declared with a case, &lt;strong&gt;they cannot change&lt;/strong&gt;. However, you can assign a different case to the enum type.&lt;/p&gt;

&lt;p&gt;For 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;enum&lt;/span&gt; &lt;span class="kt"&gt;Movement&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;forward&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="n"&gt;back&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="k"&gt;left&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="k"&gt;right&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Assign to a variable an initial case&lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;currentMovement&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;Movement&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;forward&lt;/span&gt;
&lt;span class="c1"&gt;// Change the variable value to another case&lt;/span&gt;
&lt;span class="n"&gt;currentMovement&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="k"&gt;left&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example, we never change the value of the enum itself, but we do change the variable's value to use another declared case.&lt;/p&gt;

&lt;p&gt;Attempting to assign a non-existent case or trying to set a new value to an existing case results in 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="err"&gt;❌&lt;/span&gt; &lt;span class="n"&gt;currentMovement&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;up&lt;/span&gt;  
&lt;span class="c1"&gt;//  error: type 'Movement' has no member 'up'&lt;/span&gt;
&lt;span class="c1"&gt;// This error occurs because 'Movement' does not define a case named 'up'.&lt;/span&gt;

&lt;span class="err"&gt;❌&lt;/span&gt; &lt;span class="kt"&gt;Movement&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;forward&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;up&lt;/span&gt;
&lt;span class="c1"&gt;// error: cannot assign to property: 'forward' is not settable&lt;/span&gt;
&lt;span class="c1"&gt;// This error occurs because enum cases are constants and cannot be reassigned.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;h5&gt;
  
  
  &lt;strong&gt;Accessing and using Enums&lt;/strong&gt;
&lt;/h5&gt;

&lt;p&gt;To access a specific case of an enum, you simply use the variable and the enum case as shown before. Enums in Swift are type-safe and provide a clear way to handle different states or 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;currentMovement&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;Movement&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;forward&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;currentMovement&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;// Output: forward&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Enums can be also used to execute a code depending on each case. This brings a lot of flexibility and allows us to create more complex interfaces.&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;switch&lt;/span&gt; &lt;span class="n"&gt;currentMovement&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;forward&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;"Moving forward"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;back&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;"Moving back"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;left&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;"Turning left"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;right&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;"Turning right"&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: Moving forward&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;








&lt;h4&gt;
  
  
  Enum methods
&lt;/h4&gt;

&lt;p&gt;Enums in Swift can also have methods associated with them, which allows you to define behaviours based on the enum cases. Methods inside an enum can provide additional functionality related to the enum's state.&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;AccountState&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;active&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="n"&gt;onHold&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="n"&gt;inactive&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="n"&gt;deleted&lt;/span&gt;

    &lt;span class="kd"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;description&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;switch&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;active&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;"Active account"&lt;/span&gt;
        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;onHold&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;"Pending approval"&lt;/span&gt;
        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;inactive&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;"Inactive account"&lt;/span&gt;
        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;deleted&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;"Deleted account"&lt;/span&gt;
        &lt;span class="p"&gt;}&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;color&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;UIColor&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;switch&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;active&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;green&lt;/span&gt;
        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;onHold&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;yellow&lt;/span&gt;
        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;inactive&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;gray&lt;/span&gt;
        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;deleted&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;red&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="c1"&gt;// Example of using the methods&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;AccountState&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;active&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;state&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;description&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;  &lt;span class="c1"&gt;// Output: Active account&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;state&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;color&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;        &lt;span class="c1"&gt;// Output: green&lt;/span&gt;

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Methods in Enums:&lt;/strong&gt; We can define methods within an enum to encapsulate specific behaviour to the cases. The methods can use the switch statement to handle each case and provide different functionalities based on the current case.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Multiple Methods:&lt;/strong&gt; We can create as many methods as needed within an enum. Each method should cover all possible cases of the enum or provide a default case to handle any unforeseen cases.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👍​By defining methods in enums, you can make your code more organized and expressive, as the enum can encapsulate both its data and behaviour cohesively.👍​&lt;/p&gt;

&lt;p&gt;&lt;br&gt;
__&lt;/p&gt;

&lt;p&gt;By using enums, we can enhance the safety and readability of our code. They provide a clear way to handle different states or values, making your code more organised and expressive. &lt;/p&gt;

&lt;p&gt;Enums encapsulate both data and behaviour, allowing us to define methods that operate based on the enum's cases. This results in more maintainable and understandable code. &lt;/p&gt;

&lt;p&gt;I hope this overview helps you appreciate the power of enums in Swift and helps you keep learning this amazing language!🤍​&lt;/p&gt;






&lt;h3&gt;
  
  
  Want to keep learning about Swift?
&lt;/h3&gt;

&lt;p&gt;This a full series on &lt;a href="https://dev.to/silviaespanagil/swift-101-getting-into-ios-development-gji"&gt;Swift 101&lt;/a&gt;, the next chapter will be Control Flow: Loops, Conditionals and Switch in Swift, so I hope to see you there!&lt;/p&gt;

&lt;p&gt;Remember that you can always go further into this information by checking the official documentation and courses &lt;a href="https://developer.apple.com/learn/" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you enjoyed this, please share, like, and comment. I hope this can be useful to someone and that it will inspire more people to learn and code with Swift&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>development</category>
      <category>ios</category>
      <category>swift</category>
    </item>
    <item>
      <title>Swift 101: Collections part III - Tuples and Dictionaries</title>
      <dc:creator>Silvia España Gil</dc:creator>
      <pubDate>Mon, 17 Jun 2024 13:38:39 +0000</pubDate>
      <link>https://dev.to/silviaespanagil/swift-101-collections-part-iii-tuples-and-dictionaries-42p0</link>
      <guid>https://dev.to/silviaespanagil/swift-101-collections-part-iii-tuples-and-dictionaries-42p0</guid>
      <description>&lt;h1&gt;
  
  
  Hola Mundo!
&lt;/h1&gt;



&lt;p&gt;Welcome to a new article in a series of &lt;a href="https://dev.to/silviaespanagil/swift-101-getting-into-ios-development-gji"&gt;Swift 101 notes&lt;/a&gt; 📝  I created these notes while learning the language and decided to share them because why not?&lt;/p&gt;

&lt;p&gt;If you're new to Swift or interested in learning more about this language, I invite you to follow my series! 🙊&lt;/p&gt;

&lt;p&gt;Last week I shared a post with &lt;a href="https://dev.to/silviaespanagil/swift-101-collections-part-ii-sets-3i41"&gt;the second part of collections which was sets&lt;/a&gt;. Next week, I'll share the last part of collections with Enums! &lt;/p&gt;

&lt;p&gt;So, let's get to it 💪​!&lt;/p&gt;




&lt;p&gt;As a quick refresher, "Collections" are types that store multiple values. They arrange all those values in certain ways so we can access them in the future.&lt;/p&gt;

&lt;p&gt;Think of it like a fruit basket with many fruits in it. Similarly, arrays in Swift store multiple values of the same type in an ordered list, like a line of apples, oranges, and bananas neatly arranged in your basket 🍎​🍊​🍌​&lt;/p&gt;

&lt;p&gt;There are many types of Collections, like Arrays and Sets which we already discussed. Today, let's talk about ​​✨&lt;strong&gt;Tuples and Dictionaries​&lt;/strong&gt;✨​.&lt;/p&gt;






&lt;h3&gt;
  
  
  Tuples
&lt;/h3&gt;

&lt;p&gt;&lt;br&gt;
Tuples are a collection type that allows us to group multiple values into a single compound value. These values can be of different types, making tuples a flexible way to group related values together.&lt;/p&gt;

&lt;p&gt;Here are some important characteristics and rules about tuples in Swift:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Fixed Size:&lt;/strong&gt; The number of elements in a tuple is fixed when you create it. You cannot add or remove elements after the tuple is created.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Immutable Types:&lt;/strong&gt; While you can change the values within a tuple, you cannot change the types of the elements. The types of the elements are defined when the tuple is created and must remain the same.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;h4&gt;
  
  
  How to declare a Tuple
&lt;/h4&gt;

&lt;p&gt;Declaring a tuple in Swift is really easy. You simply enclose the elements in parentheses and separate them by commas. You can also name the elements for easier access.&lt;/p&gt;

&lt;p&gt;Here's an example of how to declare and use a tuple:&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;character&lt;/span&gt; &lt;span class="o"&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="s"&gt;"Aragorn"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;nickname&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Strider"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;ageOfDeath&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;219&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;character&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="c1"&gt;// Output: (name: "Aragorn", nickname: "Strider", ageOfDeath: 219)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;❌​​ You can't declare an empty tuple, because of the characteristics previously explained. Doing so will show an error in Xcode❌​&lt;/p&gt;






&lt;h3&gt;
  
  
  Tuples Managing: Accessing Values
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Modifying Tuples
&lt;/h4&gt;

&lt;p&gt;As with any variable, we can change the values of our Tuple. However, one of the main characteristics of the Tuples is that we cannot change their elements or types.&lt;/p&gt;

&lt;p&gt;To update a Tuple, we can do:&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="err"&gt;✅&lt;/span&gt; &lt;span class="n"&gt;character&lt;/span&gt; &lt;span class="o"&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="s"&gt;"Arwen"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;nickname&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Undomiel"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;ageOfDeath&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2901&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Attempting to assign values differently will result in 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="err"&gt;❌&lt;/span&gt; &lt;span class="n"&gt;character&lt;/span&gt; &lt;span class="o"&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="s"&gt;"Frodo"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;// Error: cannot assign value of type '(name: String)' to type '(name: String, nickname: String, ageOfDeath: Int)'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;h5&gt;
  
  
  &lt;strong&gt;Accessing Tuples&lt;/strong&gt;
&lt;/h5&gt;

&lt;p&gt;To access a tuple value, we must only take the name of the variable and reference the element we want to access.&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;character&lt;/span&gt; &lt;span class="o"&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="s"&gt;"Aragorn"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;nickname&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Strider"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;ageOfDeath&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;219&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;character&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;// Output: Aragorn&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can also access one element of our Tuple and then change its value, while the rest of the elements remain with the old 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;var&lt;/span&gt; &lt;span class="nv"&gt;character&lt;/span&gt; &lt;span class="o"&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="s"&gt;"Aragorn"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;nickname&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Strider"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;ageOfDeath&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;219&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;character&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Aragorn, son of Arathorn"&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;character&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;// Output: Aragorn, son of Arathorn&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;character&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;// Output: (name: "Aragorn, son of Arathorn", nickname: "Strider", ageOfDeath: 219)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;








&lt;h4&gt;
  
  
  Tuples methods and properties
&lt;/h4&gt;

&lt;p&gt;Tuples in Swift do not have any properties or methods.  They are a value type that only groups values. However, there are a couple of operations possible with tuples:&lt;/p&gt;



&lt;h4&gt;
  
  
  Access to elements
&lt;/h4&gt;

&lt;p&gt;We already showed that we can access an element using its name, but we can also do so using the index&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;character&lt;/span&gt; &lt;span class="o"&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="s"&gt;"Aragorn"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;nickname&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Strider"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;ageOfDeath&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;219&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;character&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;// Output: Aragorn&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;character&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: Aragorn&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Decomposition
&lt;/h4&gt;

&lt;p&gt;You can decompose the tuple into separated variables&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="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="nv"&gt;nickname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;ageOfDeath&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;character&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;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Output: Aragorn&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;nickname&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Output: Strider&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;ageOfDeath&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Output: 219&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;h4&gt;
  
  
  Comparison
&lt;/h4&gt;

&lt;p&gt;You can compare tuples if the elements are comparable.&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;character&lt;/span&gt; &lt;span class="o"&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="s"&gt;"Aragorn"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Married"&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;anotherCharacter&lt;/span&gt; &lt;span class="o"&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="s"&gt;"Arwen Undomiel"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Married"&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;character&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;anotherCharacter&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Output: 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;character&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;anotherCharacter&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status&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;
  
  
  Dictionaries
&lt;/h3&gt;



&lt;p&gt;Dictionaries are another collection type available in Swift. Dictionaries are stored not in a numeric position (index) but with a key.&lt;/p&gt;

&lt;h4&gt;
  
  
  How to declare a Dictionary
&lt;/h4&gt;

&lt;p&gt;To &lt;strong&gt;declare&lt;/strong&gt; a dictionary, we must specify the key type inside brackets [ ] and the value using a colon.&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;emptyDictionary&lt;/span&gt; &lt;span class="o"&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="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[:]&lt;/span&gt;
&lt;span class="n"&gt;emptyDictionary&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"keyName"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Value"&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;emptyDictionary&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//Output:["keyName": "Value"]&lt;/span&gt;

&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;characterDetails&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
&lt;span class="s"&gt;"Aragorn"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Son of Arathorn, also known as Strider"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="s"&gt;"Frodo"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Bearer of the One Ring"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="s"&gt;"Gandalf"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"The Grey, later known as Gandalf the White"&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;characterDetails&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"Aragorn"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;span class="c1"&gt;// Output: Son of Arathorn, also known as Strider&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;








&lt;h3&gt;
  
  
  Dictionaries Managing: Accessing Values
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Accessing values with iterations
&lt;/h4&gt;

&lt;p&gt;We can access dictionary values by iterating on their values. When iterating through a dictionary, both keys and values can be accessed if needed.&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;characterDetails&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
&lt;span class="s"&gt;"Aragorn"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Son of Arathorn, also known as Strider"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="s"&gt;"Frodo"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Bearer of the One Ring"&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;characterDetails&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;key&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="s"&gt; also known as &lt;/span&gt;&lt;span class="se"&gt;\(&lt;/span&gt;&lt;span class="n"&gt;value&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="cm"&gt;/* Possible output:
Aragorn also known as Son of Arathorn, also known as Strider
Frodo also known as Bearer of the One Ring*/&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;💢​Note that when iterating over Dictionaries in Swift, the elements may be returned in an unordered manner for efficiency reasons.💢&lt;/p&gt;



&lt;h4&gt;
  
  
  Accessing values using the key
&lt;/h4&gt;

&lt;p&gt;We may access a dictionary using the key name if we know it in advance.&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;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;characterDetails&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"Aragorn"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;span class="c1"&gt;//Output: Son of Arathorn, also known as Strider&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We may also store all the keys or all the values in a new collection to use.&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;characterNames&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;characterDetails&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;key&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;characterNames&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;//Output: ["Frodo", "Aragorn"]&lt;/span&gt;

&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;characterDescription&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;characterDetails&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;values&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;characterDescription&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;//Output: ["Son of Arathorn, also known as Strider", "Bearer of the One Ring"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;h4&gt;
  
  
  Adding new values to an existing dictionary
&lt;/h4&gt;

&lt;p&gt;To add a new value to an existing dictionary we should follow the next syntax &lt;code&gt;dictionaryName[NewKey] = NewValue&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;var&lt;/span&gt; &lt;span class="nv"&gt;characterDetails&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
&lt;span class="s"&gt;"Aragorn"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Son of Arathorn, also known as Strider"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="s"&gt;"Frodo"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Bearer of the One Ring"&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="c1"&gt;//New value&lt;/span&gt;
&lt;span class="n"&gt;characterDetails&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"Galadriel"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Lady of Lothlórien, Nenya bearer"&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;characterDetails&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;//Output: ["Frodo": "Bearer of the One Ring", "Galadriel": "Lady of Lothlórien, Nenya bearer", "Aragorn": "Son of Arathorn, also known as Strider"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;








&lt;h3&gt;
  
  
  Dictionaries methods and properties
&lt;/h3&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;&lt;code&gt;.updateValue()&lt;/code&gt;:&lt;/strong&gt; Allows us to update the value of an existing key
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="n"&gt;characterDetails&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;updateValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Just a hobbit"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;forKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Frodo"&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;characterDetails&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"Frodo"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;span class="c1"&gt;//Output: "Just a hobbit"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;h4&gt;
  
  
  &lt;strong&gt;&lt;code&gt;.remove()&lt;/code&gt;:&lt;/strong&gt; Allows us to remove a value completely from our dictionary.
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="n"&gt;characterDetails&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;removeValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;forKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Frodo"&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;characterDetails&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;//Output: ["Aragorn": "Son of Arathorn, also known as Strider", "Galadriel": "Lady of Lothlórien, Nenya bearer"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;h4&gt;
  
  
  &lt;strong&gt;&lt;code&gt;.removeAll()&lt;/code&gt;:&lt;/strong&gt; Allow us to remove all the values in the dictionary.
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="n"&gt;characterDetails&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;removeAll&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;characterDetails&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;//Output: [:]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;h4&gt;
  
  
  &lt;strong&gt;&lt;code&gt;.isEmpty()&lt;/code&gt;:&lt;/strong&gt; Returns a boolean reflecting if the dictionary is empty or not
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;characterDetails&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;isEmpty&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;h4&gt;
  
  
  &lt;strong&gt;&lt;code&gt;.count()&lt;/code&gt;:&lt;/strong&gt; Count all the elements inside the dictionary
&lt;/h4&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;characterDetails&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
&lt;span class="s"&gt;"Aragorn"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Son of Arathorn, also known as Strider"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="s"&gt;"Frodo"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Bearer of the One Ring"&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;characterDetails&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: 2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;








&lt;h3&gt;
  
  
  Want to keep learning about Swift?
&lt;/h3&gt;

&lt;p&gt;This a full series on &lt;a href="https://dev.to/silviaespanagil/swift-101-getting-into-ios-development-gji"&gt;Swift 101&lt;/a&gt;, next chapter will be the final part of Collections where I will share about Enums, so I hope to see you there!&lt;/p&gt;

&lt;p&gt;Remember that you can always go further into this information by checking the official documentation and courses &lt;a href="https://developer.apple.com/learn/" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you enjoyed this, please share, like, and comment. I hope this can be useful to someone and that it will inspire more people to learn and code with Swift&lt;/p&gt;

</description>
      <category>swift</category>
      <category>beginners</category>
      <category>learning</category>
      <category>mobile</category>
    </item>
    <item>
      <title>Peerstiquette: Good Manners for Remote Collaboration</title>
      <dc:creator>Silvia España Gil</dc:creator>
      <pubDate>Wed, 12 Jun 2024 09:44:48 +0000</pubDate>
      <link>https://dev.to/silviaespanagil/peerstiquette-good-manners-for-remote-collaboration-23g9</link>
      <guid>https://dev.to/silviaespanagil/peerstiquette-good-manners-for-remote-collaboration-23g9</guid>
      <description>&lt;h1&gt;
  
  
  &lt;h1&gt; Hola Mundo! &lt;/h1&gt;
&lt;/h1&gt;



&lt;p&gt;You might not know this, but before becoming an iOS Developer, I worked and taught Communication and Marketing for about 12 years📆​!&lt;/p&gt;

&lt;p&gt;And why is this important, you may ask yourself. Well, in my course I loved to talk about Netiquette because well, being behind a screen, people sometimes forget their manners. &lt;/p&gt;

&lt;p&gt;Then, last year, when preparing my talk for Software Crafters Barcelona, I decided to twist the concept and adapt it for communication between peers. This is extendable to any communication between mentors and mentees and, well...basically everyone.&lt;/p&gt;




&lt;h3&gt;
  
  
  What is Netiquette
&lt;/h3&gt;

&lt;p&gt;Before diving into Peerstiquette, I want to talk about Netiquette because this has significantly changed how we communicate online.&lt;/p&gt;

&lt;p&gt;In 1994, Virginia Shea wrote &lt;a href="http://www.albion.com/netiquette/book/0963702513p3.html" rel="noopener noreferrer"&gt;Netiquette&lt;/a&gt;, a whole book with rules to communicate better in the emerging online world💾​.&lt;/p&gt;

&lt;p&gt;Virginia's rules may sound like common sense. However, a quick look at any social media platform reveals that a lot of people just skipping them all!😈​ These rules are also quite general and apply to all forms of online communication.&lt;/p&gt;

&lt;p&gt;But then in 1995, Sally Hambridge, who at that moment worked at Intel wrote the &lt;a href="https://www.ietf.org/rfc/rfc1855.txt" rel="noopener noreferrer"&gt;Request For Comments: 1855&lt;/a&gt;. As Intel began using emails for daily communication💻​, the goal was to provide guidelines for effective communication in a corporate environment.&lt;/p&gt;




&lt;h3&gt;
  
  
  What is Peerstiquette
&lt;/h3&gt;

&lt;p&gt;When I learned about Netiquette, I became obsessed🫶​. I think it's an amazing concept that, sadly, most people forget.  And then when I started in tech I noticed how much Netiquette helped me in my relationships with mentors.&lt;/p&gt;

&lt;p&gt;Time passed by and I adapted Virginia's and Sally's to my day-to-day communications and then thought, maybe I could create my own Peerstiquette. So, ✨​here we are✨​&lt;/p&gt;

&lt;p&gt;Peerstiquette is a decalogue of what I believe are 🎯​ten essential rules for communicating with peers, mentors, and mentees in online environments🎯​, especially when working fully remotely.&lt;/p&gt;

&lt;p&gt;Each "rule" is quite self-explanatory but I'll add some context for clarity if you want to check it out!&lt;/p&gt;




&lt;p&gt;Please notice that I have done this design and you can download it or use it if you want it. But please🙏​, I really ask for respect so if you use it don't delete my name from it and if you create your own version I would love to have some credit&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdmdea5f26opdi62qf4mp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdmdea5f26opdi62qf4mp.png" alt="Peerstiquette decalogue image: 1. Respect the other person's time 2. Do not call without notice or demand immediate response 3. Communicate clearly, preferably in a single message 4. Do not ask questions you haven't attempted to solve 5. Do not judge 6. Use appropriate, respectful language 7. Accept constructive feedback and a no as an answer 8. Share your progress and setbacks 9. Respect the privacy of image and information when applicable 10. Do not expect others to solve your problems" width="800" height="2000"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h4&gt;
  
  
  1. &lt;strong&gt;Respect the other person's time&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Be mindful of your colleagues' schedules and time zones. Avoid contacting them outside of their working hours and be considerate of their time when scheduling meetings or expecting responses. &lt;/p&gt;

&lt;p&gt;If you set a time to chat or call someone be punctual, be there. Try to not surpass the time set for the call, if you need to extend it, ask if is ok or schedule a new slot.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;strong&gt;2. Do not call without notice or demand immediate response&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Respect your peers' focus and workflow by avoiding unscheduled calls. Instead, send a message first to arrange a suitable time for a call. If possible let the person know with anticipation what the call is for, and give them context so they can go prepared if necessary.&lt;/p&gt;

&lt;p&gt;Be patient and do not expect immediate responses to your messages or emails. Understand that if the person is busy, maybe they will see the message in a while.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;strong&gt;3. Communicate clearly, preferably in a single message&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;We have all seen a chat like this...and is not nice. We don't want to hear 100 times the message sound of slack&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F685ujl30wd0dtc04u1ek.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F685ujl30wd0dtc04u1ek.png" alt="Chat image with lots of different messages of not many lines" width="282" height="317"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ensure your communication is clear and concise. Try to include all relevant information in a single message to avoid back-and-forth exchanges and to also avoid the other person receiving lots of notifications that may be interrupting. &lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;strong&gt;4. Do not ask questions you haven't attempted to solve&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Before asking for help, make sure you have tried to find a solution on your own. This shows initiative and respect for your colleagues' time. &lt;/p&gt;

&lt;p&gt;If you still need some help, you could explain what you have tried so far to provide context and then work together toward solving the issue. &lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;strong&gt;5. Do Not Judge&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Maintain a non-judgmental attitude towards your colleagues. Everyone has different strengths, weaknesses, and ways of working. If they ask for your help, or they fail to help you with an issue try to keep a supportive and understanding environment.&lt;/p&gt;

&lt;p&gt;This is extendable to personal decisions, never by no reason, judge anyone for their looks, religious beliefs, background, ethnicity, origin, sexuality, etc &lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;strong&gt;6. Use appropriate, respectful language&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Always use respectful and professional language in your communications. Avoid slang, jargon, or any language that could be misunderstood or deemed inappropriate. &lt;/p&gt;

&lt;p&gt;Remember to use the person preferable pronouns, do not use nicknames unless are widely accepted by the other person and of course, leave out any sexist, racial, or diminishing comment. &lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;strong&gt;7. Accept constructive feedback and a no as an answer&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Be open to receiving constructive feedback and use it as an opportunity for growth.&lt;/p&gt;

&lt;p&gt;Similarly, respect your colleagues' boundaries and understand that they may sometimes need to say no to a call, meeting, or request. &lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;strong&gt;8. Share Your Progress and Setbacks&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;We love to ask for help but sometimes after we receive that help we never go back to the person to say thank you or to let the other know how was everything solved in the end.&lt;/p&gt;

&lt;p&gt;When needed keep others informed about your progress and any setbacks you encounter. &lt;/p&gt;

&lt;p&gt;Transparency helps in building trust and allows the team to support each other effectively. Regular updates can also prevent miscommunication and misalignment.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;strong&gt;9. Respect the privacy of image and information when applicable&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Be mindful of privacy concerns. Do not share images or sensitive information without permission. &lt;/p&gt;

&lt;p&gt;If you take a screenshot where the other person's face is shown, or want to record a session, ask for permission. Also if you later want to publicly share that image let the other implicated know that so they can decide if they set their cams on or off.&lt;/p&gt;

&lt;p&gt;When working with corporate information ensure that any shared data complies with privacy regulations and the company's policies.&lt;/p&gt;




&lt;h4&gt;
  
  
  &lt;strong&gt;10. Do not expect others to solve your problems&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Take responsibility for your tasks and challenges. While seeking help is fine, do not rely on others to solve your problems entirely. Show initiative in addressing issues and finding solutions.&lt;/p&gt;

&lt;p&gt;When asking for help, if the other person does not have the knowledge or tools to help you, be thankful and seek solutions in other ways.&lt;/p&gt;




&lt;p&gt;I hope you find this decalogue interesting and that it might be helpful. Would you add another rule to it? Let me know!&lt;/p&gt;

&lt;p&gt;And if you liked my post, please feel free to give me credit, like it or share it 🫶&lt;/p&gt;

</description>
      <category>programming</category>
      <category>productivity</category>
      <category>career</category>
    </item>
    <item>
      <title>Swift 101: Collections Part II - Sets</title>
      <dc:creator>Silvia España Gil</dc:creator>
      <pubDate>Mon, 10 Jun 2024 16:46:53 +0000</pubDate>
      <link>https://dev.to/silviaespanagil/swift-101-collections-part-ii-sets-3i41</link>
      <guid>https://dev.to/silviaespanagil/swift-101-collections-part-ii-sets-3i41</guid>
      <description>&lt;h1&gt;
  
  
  &lt;h1&gt; Hola Mundo! &lt;/h1&gt;
&lt;/h1&gt;



&lt;p&gt;Welcome to a new article in a series of &lt;a href="https://dev.to/silviaespanagil/swift-101-getting-into-ios-development-gji"&gt;Swift 101 notes&lt;/a&gt; 📝  I created these notes while learning the language and decided to share them because, why not?&lt;/p&gt;

&lt;p&gt;If you're new to Swift or interested in learning more about this language, I invite you to follow my series! 🙊&lt;/p&gt;

&lt;p&gt;Last week I shared a post with &lt;a href="https://dev.to/silviaespanagil/swift-101-collections-part-i-arrays-2a52"&gt;the first part of collections which was arrays&lt;/a&gt;. Initially, I thought I would cover collections in two parts, but who wants to read that much in one go 🙅🏽‍♀️? So, this will be the second part of what will likely be four parts. Next week, I'll share and try to cover Tuples and Dictionaries.&lt;/p&gt;

&lt;p&gt;So, let's get to it 💪​!&lt;/p&gt;




&lt;p&gt;As a quick refresher &lt;a href="https://dev.to/silviaespanagil/swift-101-collections-part-i-arrays-2a52"&gt;from last week's chapter&lt;/a&gt;, "Collections" are types that store multiple values. They arrange all those values in certain ways so we can access them in the future.&lt;/p&gt;

&lt;p&gt;Think of it like a fruit basket with many fruits in it. Similarly, arrays in Swift store multiple values of the same type in an ordered list, like a line of apples, oranges, and bananas neatly arranged in your basket 🍎​🍊​🍌​&lt;/p&gt;

&lt;p&gt;There are many types of Collections, like Arrays which we already discussed. Today I want to share about ✨​&lt;strong&gt;Sets&lt;/strong&gt;✨​.&lt;/p&gt;






&lt;h3&gt;
  
  
  Sets
&lt;/h3&gt;

&lt;p&gt;&lt;br&gt;
Sets, like arrays and other collections, allow us to store many elements &lt;strong&gt;of the same type&lt;/strong&gt; in a variable. However, sets store the values without any particular order.&lt;/p&gt;

&lt;p&gt;The main characteristics of sets are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Order:&lt;/strong&gt; Sets &lt;strong&gt;do not have a defined order&lt;/strong&gt;; they store values in the way that Swift thinks is most effective.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Elements can’t repeat itself&lt;/strong&gt;: On sets all element values must be unique. If there’s a duplicated one it will be ignored.

&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;swift

let colors = Set(["red", "green", "blue"])
print(colors)
// Output: ["red", "blue", "green"]

let colors2 = Set(["red", "green", "blue", "green"])
print(colors2)
// Output: ["green", "red", "blue"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;To declare an empty set you specify the type of elements it will hold using the Set keyword followed by the type in angle brackets:&lt;br&gt;
&lt;code&gt;var mySet = Set&amp;lt;Int&amp;gt;()&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You can also declare a set with initial values. Swift will infer the type of the set based on the type of the initial values:&lt;br&gt;
&lt;code&gt;var mySet: Set = [1, 2, 3, 4, 5]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;or, specifying the type explicitly:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;var mySet: Set&amp;lt;Int&amp;gt; = [1, 2, 3, 4, 5]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;🔥​ Remember that Sets do not maintain the order of elements and that repeated elements will be ignored 🔥&lt;/p&gt;




&lt;h3&gt;
  
  
  Sets managing: accessing values and methods
&lt;/h3&gt;
&lt;h4&gt;
  
  
  Accessing sets values
&lt;/h4&gt;

&lt;p&gt;Since sets have no specific order, we must access their elements using loops or by using their methods and properties.&lt;/p&gt;
&lt;h5&gt;
  
  
  &lt;strong&gt;Iterations on sets&lt;/strong&gt;
&lt;/h5&gt;

&lt;p&gt;To iterate over a set, we can use the &lt;code&gt;for-in&lt;/code&gt; loop. This allows us to access each element in the set one by one.&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;fellowshipMembers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Set&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"Frodo"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Aragorn"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Gandalf"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Legolas"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Gimli"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Merry"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Pippin"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Boromir"&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;member&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;fellowshipMembers&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;member&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: This will print all the members&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🧐 Remember that Sets do not maintain the order of elements 🧐&lt;/p&gt;




&lt;h4&gt;
  
  
  Set methods and properties
&lt;/h4&gt;

&lt;p&gt;Swift also provides us with some methods and properties that we may use and that can be useful for different operations. &lt;/p&gt;

&lt;p&gt;Let's see the most used:&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;code&gt;.count&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;This property counts how many elements are inside our Set.&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;letter&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Set&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"w"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"e"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"f"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"o"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"x"&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;letter&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: 5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;code&gt;.insert()&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;This method allows us to add new elements to our Set.&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;groceryList&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Set&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"Onions"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Apples"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Pasta"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;groceryList&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;insert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Bread"&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;groceryList&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="c1"&gt;// Possible output: ["Pasta", "Onions", "Bread", "Apples"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;code&gt;.remove()&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;Allows us to remove an element from the set&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;groceryList&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Set&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"Onions"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Apples"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Pasta"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;groceryList&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;remove&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Pasta"&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;groceryList&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="c1"&gt;// Possible output: ["Onions", "Apples"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;code&gt;.removeAll()&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;This method empties the Set of all its 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;groceryList&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Set&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"Onions"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Apples"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Pasta"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;groceryList&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;removeAll&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;groceryList&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="c1"&gt;// Output: []&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;code&gt;.contains(_:)&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;This method checks if the Set contains a specific element.&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;numbers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Set&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;63&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;27&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;containsTwentySeven&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;contains&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;27&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;containsTwentySeven&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;h4&gt;
  
  
  &lt;code&gt;.isEmpty&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;This property checks if the Set is empty and returns a boolean result.&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;numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;63&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;27&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;numbers&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;isEmpty&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Output: false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Sets operations
&lt;/h3&gt;

&lt;h4&gt;
  
  
  &lt;code&gt;.union(_:)&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;This method returns a new set containing all elements from both sets. Since sets cannot have duplicate values, any value that appears in both sets will only appear once in the union.&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;fellowshipOfTheRing&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Set&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"Frodo"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Sam"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Merry"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Pippin"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Aragorn"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Legolas"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Gimli"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Boromir"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Gandalf"&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;charactersInRohan&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Set&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"Aragorn"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Legolas"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Gimli"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Gandalf"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Eomer"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Eowyn"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Theoden"&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;allCharacters&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;fellowshipOfTheRing&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;union&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;charactersInRohan&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;allCharacters&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="c1"&gt;// Possible output: ["Sam", "Merry", "Pippin", "Legolas", "Aragorn", "Gimli", "Eowyn", "Frodo", "Theoden", "Eomer", "Boromir", "Gandalf"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;code&gt;.intersection(_:)&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;This method returns a new set with only the elements common to both sets.&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;fellowshipOfTheRing&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Set&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"Frodo"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Sam"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Merry"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Pippin"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Aragorn"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Legolas"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Gimli"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Boromir"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Gandalf"&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;charactersInRohan&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Set&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"Aragorn"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Legolas"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Gimli"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Gandalf"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Eomer"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Eowyn"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Theoden"&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;commonCharacters&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;fellowshipOfTheRing&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;intersection&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;charactersInRohan&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;commonCharacters&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="c1"&gt;// Possible output: ["Aragorn", "Legolas", "Gandalf", "Gimli"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;code&gt;.subtracting(_:)&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;This method returns a new set with the elements of the first set that &lt;strong&gt;are not&lt;/strong&gt; in the second set.&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;fellowshipOfTheRing&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Set&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"Frodo"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Sam"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Merry"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Pippin"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Aragorn"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Legolas"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Gimli"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Boromir"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Gandalf"&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;charactersInRohan&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Set&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"Aragorn"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Legolas"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Gimli"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Gandalf"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Eomer"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Eowyn"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Theoden"&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;uniqueToFellowship&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;fellowshipOfTheRing&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;subtracting&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;charactersInRohan&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;uniqueToFellowship&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="c1"&gt;// Possible output:["Boromir", "Frodo", "Pippin", "Sam", "Merry"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;code&gt;.symmetricDifference(_:)&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;This method returns a new set with elements that are in either of the sets &lt;strong&gt;but not in both.&lt;/strong&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;fellowshipOfTheRing&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Set&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"Frodo"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Sam"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Merry"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Pippin"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Aragorn"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Legolas"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Gimli"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Boromir"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Gandalf"&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;charactersInRohan&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Set&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"Aragorn"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Legolas"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Gimli"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Gandalf"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Eomer"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Eowyn"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Theoden"&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;differentCharacters&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;fellowshipOfTheRing&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;symmetricDifference&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;charactersInRohan&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;differentCharacters&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;// Possible output:["Pippin", "Boromir", "Eomer", "Merry", "Sam", "Frodo", "Eowyn", "Theoden"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Resources
&lt;/h3&gt;

&lt;p&gt;If you want a Cheat Sheet with some of these methods and properties, feel free to save or download this image. If you share it please do not delete or hide my name 🫶🏻​&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnj1somt6jysgyhptjawt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnj1somt6jysgyhptjawt.png" alt="Cheat sheet with some of the methods and properties of setss" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Also if you want to keep learning more about this I highly recommend checking the official documentation and courses &lt;a href="https://developer.apple.com/learn/" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  Want to keep learning about Swift?
&lt;/h3&gt;

&lt;p&gt;This a full series on &lt;a href="https://dev.to/silviaespanagil/swift-101-getting-into-ios-development-gji"&gt;Swift 101&lt;/a&gt;, next chapter will be the third part of Collections where I will share about Tuples and Dictionaries, so I hope to see you there!&lt;/p&gt;

&lt;p&gt;If you enjoyed this, please share, like, and comment. I hope this can be useful to someone and that it will inspire more people to learn and code with Swift&lt;/p&gt;

</description>
      <category>swift</category>
      <category>beginners</category>
      <category>learning</category>
      <category>mobile</category>
    </item>
    <item>
      <title>Swift 101: Collections Part I - Arrays</title>
      <dc:creator>Silvia España Gil</dc:creator>
      <pubDate>Wed, 29 May 2024 15:19:41 +0000</pubDate>
      <link>https://dev.to/silviaespanagil/swift-101-collections-part-i-arrays-2a52</link>
      <guid>https://dev.to/silviaespanagil/swift-101-collections-part-i-arrays-2a52</guid>
      <description>&lt;h1&gt;
  
  
  &lt;h1&gt; Hola Mundo! &lt;/h1&gt;
&lt;/h1&gt;



&lt;p&gt;Welcome to a new article in a series of &lt;a href="https://dev.to/silviaespanagil/swift-101-getting-into-ios-development-gji"&gt;Swift 101 notes&lt;/a&gt; 📝 I did while learning the language and I decided to share them because why not?.&lt;/p&gt;

&lt;p&gt;If you're new to Swift or interested in learning more about this language, I invite you to follow my series! 🙊&lt;/p&gt;

&lt;p&gt;In this chapter, I'll share Part I of Collections and Collection Types, where we'll dive into Arrays.&lt;/p&gt;




&lt;p&gt;&lt;a href="https://dev.to/silviaespanagil/swift-101-understanding-types-variables-and-constants-l9h"&gt;A couple of weeks ago&lt;/a&gt;, we discussed constants and variables, which store values for us to use in our code and some simple types. However, there are some other complex types that we will find across our apps📱​.&lt;/p&gt;

&lt;p&gt;As you may already guess, "Collections" are types that store many values. They arrange all those values in certain ways so we can access them in the future.&lt;/p&gt;

&lt;p&gt;Think of it like a fruit basket with many fruits in it. Similarly, arrays in Swift store multiple values of the same type in an ordered list, like a line of apples, oranges, and bananas neatly arranged in your basket 🍎​🍊​🍌​&lt;/p&gt;






&lt;h3&gt;
  
  
  Arrays
&lt;/h3&gt;

&lt;p&gt;&lt;br&gt;
Arrays are &lt;strong&gt;an ordered collection of values&lt;/strong&gt; and are the most common collection type. Inside an array, we may store any kind of elements of the same type.&lt;/p&gt;

&lt;p&gt;Arrays are one of the most commonly used collection types in Swift due to their simplicity and efficiency. Arrays maintain an ordered list of elements. This makes them ideal for scenarios where the order of elements matters, such as lists of items or sequences of tasks.&lt;/p&gt;

&lt;p&gt;To create an array, we separate elements with commas and enclose them in square brackets.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let intArray = [1, 2, 3]
let stringArray = ["Mónica", "Rachel", "Phoebe"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;








&lt;h4&gt;
  
  
  Typing our arrays
&lt;/h4&gt;

&lt;p&gt;As with everything in Swift, arrays are also typed. If we don’t indicate it explicitly, Swift will infer the type for us. &lt;/p&gt;

&lt;p&gt;However, for Swift to be able to infer the type, the values inside the array must be homogeneous, meaning all values must be of the same type. This is called &lt;strong&gt;array literals&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;If we don't type our array, and the values are heterogeneous, we will get an error ❌​, and Swift will ask us to add an explicit type to ensure the mixed types are intentional.&lt;/p&gt;

&lt;p&gt;To set a type to an array we must indicate it after the naming just as we do in simple variables and constants. &lt;/p&gt;

&lt;p&gt;If we want to create a heterogenous array or we don’t know which kind of values we will hold in that variable we can set the &lt;code&gt;Any&lt;/code&gt; type -&lt;em&gt;not recommendable&lt;/em&gt;-&lt;/p&gt;

&lt;p&gt;Strong typing in Swift ensures that each array can only contain elements of a specific type. &lt;/p&gt;

&lt;p&gt;This could prevent many common programming errors and make your code more predictable and easier to debug. By specifying the type of elements Swift can also optimize performance and provide better compile-time checks.&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="c1"&gt;// All values are the same type&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;homogenousArray&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;Double&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mf"&gt;1.4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;2.6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;3.7&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;alsoHomogenousArray&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;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"Pippin"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Merry"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Frodo"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Sam"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;
&lt;span class="c1"&gt;// Values types may be different so type is Any&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;heterogenousArray&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;Any&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Kobe Bryant"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;24.8&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;








&lt;h4&gt;
  
  
  Classes and structs as types
&lt;/h4&gt;

&lt;p&gt;Until now we have been using the most common types to type all of our values. However, while dealing with our apps, especially if they interact with APIs or complex data, we may need to manage arrays with heterogeneous types. &lt;/p&gt;

&lt;p&gt;If you scroll back, I said that we can use &lt;code&gt;Any&lt;/code&gt; as a type, but I also said that is not a really good idea🙅🏽‍♀️​. But if Swift gives us that option, why is it not a good idea?&lt;/p&gt;

&lt;p&gt;Typing makes our code more reliable, and safer🛟​. We know always what kind of value we are going to find in that variable. With &lt;code&gt;Any&lt;/code&gt; we lose that advantage. We may also cause compilation issues, overcomplicate our code, etc.&lt;/p&gt;

&lt;p&gt;But we can overcome this by using classes or structs as types. &lt;/p&gt;

&lt;p&gt;Let’s imagine that we have a newsletter and we need an array with the user name, email, and confirmation that it wants to receive an email. And we are going to store that in an Array. So first we could create a struct and then assign it as a type.&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="kt"&gt;Identifiable&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;Hashable&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;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Int&lt;/span&gt;
    &lt;span class="k"&gt;let&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="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;email&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;let&lt;/span&gt; &lt;span class="nv"&gt;permission&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;var&lt;/span&gt; &lt;span class="nv"&gt;registeredUsers&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="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Swift, structs and classes are both used to create complex data types, but they have some key differences. Structs are value types, which means they are copied when assigned to a new variable or constant, or when passed to a function. &lt;/p&gt;

&lt;p&gt;Classes, on the other hand, are reference types, so they are passed by reference and can have inheritance. &lt;/p&gt;

&lt;p&gt;Generally, is a better idea to use structs for simpler data types that do not require inheritance and classes for more complex types that benefit from inheritance.&lt;/p&gt;

&lt;p&gt;✨​Further details on classes and structs will come later on in the series, so don't forget to follow me and keep an eye on new updates.✨​&lt;/p&gt;






&lt;h3&gt;
  
  
  Array managing: accessing values and methods
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Accessing array values
&lt;/h4&gt;

&lt;p&gt;We now know that an array, as a collection, can store one or many values, but to use them we will probably need them separated and to do so we need to access those values.&lt;/p&gt;

&lt;h5&gt;
  
  
  &lt;strong&gt;Using the value index&lt;/strong&gt;
&lt;/h5&gt;

&lt;p&gt;One way of accessing our array values is by calling the index. As arrays are &lt;strong&gt;ordered collections&lt;/strong&gt; if nothing explicitly changes, the value in a certain position will always be the same.&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;hatchNumbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;23&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;42&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;thirdHatchNumber&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;hatchNumbers&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="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;thirdHatchNumber&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// 15&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🧐 Remember that the array index starts at 0. So the first value is index 0 and so on. 🧐&lt;/p&gt;

&lt;h5&gt;
  
  
  &lt;strong&gt;Iterations or loops: For-in and while&lt;/strong&gt;
&lt;/h5&gt;

&lt;p&gt;There are two ways to iterate an array. One you may use while using SwiftUI in the views and the other one the rest of the time, but don't worry, they are pretty similar. &lt;/p&gt;

&lt;p&gt;If you want to know more about this, keep an eye on this series because I'll be writing about Control Flow however, in the meanwhile, we will hammer the most common here: For-in loops&lt;/p&gt;

&lt;p&gt;Loops can be imagined as a spiral, each loop of the spiral is an item. So, when we iterate an array, we circle the array over and over.&lt;/p&gt;

&lt;p&gt;Imagine we have an array with the Fellowship of the Rings names and I want to access the name of each one of them. We could check the array using a &lt;code&gt;for in&lt;/code&gt; loop and print the 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;let&lt;/span&gt; &lt;span class="nv"&gt;fellowshipMembers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"Frodo"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Sam"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Gandalf"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Aragorn"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Legolas"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Gimli"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Boromir"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Merry"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Pippin"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="c1"&gt;// Access elements&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;member&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;fellowshipMembers&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;member&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;What is going to happen is that Swift is going to check each member inside the &lt;code&gt;fellowshipMembers&lt;/code&gt; array and will print the nine 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="kt"&gt;Frodo&lt;/span&gt;
&lt;span class="kt"&gt;Sam&lt;/span&gt;
&lt;span class="kt"&gt;Gandalf&lt;/span&gt;
&lt;span class="kt"&gt;Aragorn&lt;/span&gt;
&lt;span class="kt"&gt;Legolas&lt;/span&gt;
&lt;span class="kt"&gt;Gimli&lt;/span&gt;
&lt;span class="kt"&gt;Boromir&lt;/span&gt;
&lt;span class="kt"&gt;Merry&lt;/span&gt;
&lt;span class="kt"&gt;Pippin&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can also do the iteration but add a clause in it. For doing so we will have to add a &lt;strong&gt;where&lt;/strong&gt; in the loops.&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="c1"&gt;// Leave Frodo out&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;fellowshipMembers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"Frodo"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Sam"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Gandalf"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Aragorn"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Legolas"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Gimli"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Boromir"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Merry"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Pippin"&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;member&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;fellowshipMembers&lt;/span&gt; &lt;span class="k"&gt;where&lt;/span&gt; &lt;span class="n"&gt;member&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="s"&gt;"Frodo"&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;member&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 will print all the Fellowship members but will skip Frodo.&lt;/p&gt;

&lt;p&gt;There’s another way to do a loop by evaluating a condition, and that is using while. Basically, we ask Swift that while a condition happens, do something.&lt;/p&gt;

&lt;p&gt;Think of it as when you are cooking, &lt;code&gt;while&lt;/code&gt; you see flour, whisk the mix. Then you understand that if the flour is not visible anymore you can stop whisking.&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;while&lt;/span&gt; &lt;span class="n"&gt;condition&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="n"&gt;this&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 imagine that we want to allow Frodo to gather 3 things&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;itemsToCollect&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"Ring"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Lembas Bread"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Elven Cloak"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Light of Eärendil"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Mithril Coat"&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;thingsCollected&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;thingsCollected&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;3&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;"Frodo has collected: &lt;/span&gt;&lt;span class="se"&gt;\(&lt;/span&gt;&lt;span class="n"&gt;itemsToCollect&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;thingsCollected&lt;/span&gt;&lt;span class="p"&gt;]&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="n"&gt;thingsCollected&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will print us 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="kt"&gt;Frodo&lt;/span&gt; &lt;span class="n"&gt;has&lt;/span&gt; &lt;span class="nv"&gt;collected&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Ring&lt;/span&gt;
&lt;span class="kt"&gt;Frodo&lt;/span&gt; &lt;span class="n"&gt;has&lt;/span&gt; &lt;span class="nv"&gt;collected&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Lembas&lt;/span&gt; &lt;span class="kt"&gt;Bread&lt;/span&gt;
&lt;span class="kt"&gt;Frodo&lt;/span&gt; &lt;span class="n"&gt;has&lt;/span&gt; &lt;span class="nv"&gt;collected&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Elven&lt;/span&gt; &lt;span class="kt"&gt;Cloak&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While we are looping an array we may want to access to the index value of the element and call the &lt;code&gt;enumerated()&lt;/code&gt; method with the array. For doing so we may call the index in the loop.&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="c1"&gt;// Print with index&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;fellowshipMembers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"Frodo"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Sam"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Gandalf"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Aragorn"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Legolas"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Gimli"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Boromir"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Merry"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Pippin"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;member&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;fellowshipMembers&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;enumerated&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;"Member number &lt;/span&gt;&lt;span class="se"&gt;\(&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&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;member&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;This will print&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="kt"&gt;Member&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Frodo&lt;/span&gt;
&lt;span class="kt"&gt;Member&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Sam&lt;/span&gt;
&lt;span class="kt"&gt;Member&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Gandalf&lt;/span&gt;
&lt;span class="kt"&gt;Member&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Aragorn&lt;/span&gt;
&lt;span class="kt"&gt;Member&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Legolas&lt;/span&gt;
&lt;span class="kt"&gt;Member&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Gimli&lt;/span&gt;
&lt;span class="kt"&gt;Member&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Boromir&lt;/span&gt;
&lt;span class="kt"&gt;Member&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Merry&lt;/span&gt;
&lt;span class="kt"&gt;Member&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Pippin&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🧐 Remember that the array index starts at 0. So the first value is index 0 and so on. 🧐&lt;/p&gt;




&lt;h3&gt;
  
  
  Array methods and properties
&lt;/h3&gt;

&lt;p&gt;We already know how fundamental are Arrays, they allow us to store multiple values in a single variable, making it easier to manage collections of data. &lt;/p&gt;

&lt;p&gt;But to truly harness the 💪​power of arrays💪​, it's essential to understand the various methods and properties that Swift provides for working with them. And that also makes it so much easier to work with them.&lt;/p&gt;

&lt;h4&gt;
  
  
  What are Array Methods and Properties?
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Properties&lt;/strong&gt; are characteristics of an array that provide information about the array itself. For instance, properties can tell you the number of elements in an array or whether the array is empty.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Methods&lt;/strong&gt; are functions that perform actions on the array. They can help you add, remove, or find elements within the array, and perform other useful operations.&lt;/p&gt;

&lt;p&gt;By learning these methods and properties, you can effectively manipulate arrays and make your code more efficient and readable.&lt;/p&gt;

&lt;p&gt;Let's see the most used:&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;code&gt;.count&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;This property counts how many elements are inside 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;var&lt;/span&gt; &lt;span class="nv"&gt;numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&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="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&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;numbers&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: 4&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;code&gt;.append()&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;This method allows us to add new elements to &lt;strong&gt;the end&lt;/strong&gt; of the 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;var&lt;/span&gt; &lt;span class="nv"&gt;groceryList&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"Onions"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Apples"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Pasta"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;groceryList&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Bread"&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;groceryList&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="c1"&gt;// Output: ["Onions", "Apples", "Pasta", "Bread"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;code&gt;.insert()&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;This method allows us to add new values to the array at a specific index.&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;groceryList&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"Onions"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Apples"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Pasta"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;groceryList&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;insert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Bread"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;at&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&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;groceryList&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="c1"&gt;// Output: ["Onions", "Bread", "Apples", "Pasta"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;code&gt;.remove(at:)&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;This method removes the element at a specific index in the 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;var&lt;/span&gt; &lt;span class="nv"&gt;groceryList&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"Onions"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Apples"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Pasta"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;groceryList&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;remove&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;at&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;groceryList&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="c1"&gt;// Output: ["Apples", "Pasta"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;code&gt;.removeAll()&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;This method empties the array of all its 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;groceryList&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"Onions"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Apples"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Pasta"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;groceryList&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;removeAll&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;groceryList&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="c1"&gt;// Output: []&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;code&gt;.filter()&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;This method, filters our array. It creates a new array with the values that satisfy a condition.&lt;br&gt;
For example, let's filter our array to create a new one with all the values that are less than 3.&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;numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&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="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&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;filtered&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;filter&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nv"&gt;$0&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;3&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;filtered&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="c1"&gt;// Output: [1, 2]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;code&gt;.map()&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;This method transforms each value of the array and returns a new array with the transformed 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;numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&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="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&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;mappedNumbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;map&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nv"&gt;$0&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&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;mappedNumbers&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="c1"&gt;// Output: [2, 4, 6, 8]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;code&gt;.forEach()&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;This method performs an action for each value in the 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;var&lt;/span&gt; &lt;span class="nv"&gt;groceryList&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"Onions"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Apples"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Pasta"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;groceryList&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;forEach&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="nv"&gt;$0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="cm"&gt;/* Output: 
   Onions
   Apples
   Pasta
*/&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;code&gt;.sort(by:)&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;This method sorts or rearrange the values inside the array according to a condition.&lt;/p&gt;

&lt;p&gt;For example here we can sort them from smaller to higher.&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;numbers&lt;/span&gt; &lt;span class="o"&gt;=&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="mi"&gt;24&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;73&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;by&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nv"&gt;$0&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nv"&gt;$1&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;numbers&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="c1"&gt;// Output: [3, 5, 10, 24, 73]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;code&gt;.first&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;This property returns the first element of our 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;var&lt;/span&gt; &lt;span class="nv"&gt;numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;63&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;27&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;numbers&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;first&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="c1"&gt;// Output: 3&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;code&gt;.last&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;This property returns the last element of the 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;var&lt;/span&gt; &lt;span class="nv"&gt;numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;63&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;27&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;numbers&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;last&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="c1"&gt;// Output: 27&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;code&gt;.removeFirst()&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;This method removes the first element of the 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;var&lt;/span&gt; &lt;span class="nv"&gt;groceryList&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"Onions"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Apples"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Pasta"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;groceryList&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;removeFirst&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;groceryList&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="c1"&gt;// Output: ["Apples", "Pasta"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;code&gt;.removeLast()&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;This method removes the last element of the 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;var&lt;/span&gt; &lt;span class="nv"&gt;groceryList&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"Onions"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Apples"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Pasta"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;groceryList&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;removeLast&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;groceryList&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="c1"&gt;// Output: ["Onions", "Apples"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;code&gt;.firstIndex(where:)&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;This method returns the index of the first value that satisfies a 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;var&lt;/span&gt; &lt;span class="nv"&gt;numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;63&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;27&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;firstIndex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;firstIndex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;where&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nv"&gt;$0&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;10&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;firstIndex&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Output: 1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;code&gt;.shuffled()&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;This method returns a new array with the elements shuffled.&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;numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;63&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;27&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;shuffled&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;shuffled&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;shuffled&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="c1"&gt;// Output: [27, 3, 63] (order will vary)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;code&gt;.reverse()&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;This method reverses the order of the elements in the 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;var&lt;/span&gt; &lt;span class="nv"&gt;groceryList&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"Onions"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Apples"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Pasta"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;groceryList&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reverse&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;groceryList&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="c1"&gt;// Output: ["Pasta", "Apples", "Onions"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;code&gt;.allSatisfy(_:)&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;This method returns true if &lt;strong&gt;all&lt;/strong&gt; elements satisfy a condition, otherwise false.&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;numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;63&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;27&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;allGreaterThanTen&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;allSatisfy&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nv"&gt;$0&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;10&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;allGreaterThanTen&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Output: false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;code&gt;.contains(_:)&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;This method checks if the array contains a specific element.&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;numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;63&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;27&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;containsTwentySeven&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;contains&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;27&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;containsTwentySeven&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;h4&gt;
  
  
  &lt;code&gt;.isEmpty&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;This property checks if the array is empty and returns a boolean result.&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;numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;63&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;27&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;numbers&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;isEmpty&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Output: false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Resources
&lt;/h3&gt;

&lt;p&gt;If you want a Cheat Sheet with some of this methods and properties, feel free to save or download this image. If you share it please do not delete or hide my name 🫶🏻​&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa1026redo3m4v4pwbthq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa1026redo3m4v4pwbthq.png" alt="Cheat sheet with some of the methods and properties of arrays" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Also if you want to keep learning more about this I highly recommend checking the official documentation and courses &lt;a href="https://developer.apple.com/learn/" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  Want to keep learning about Swift?
&lt;/h3&gt;

&lt;p&gt;This a full series on &lt;a href="https://dev.to/silviaespanagil/swift-101-getting-into-ios-development-gji"&gt;Swift 101&lt;/a&gt;, next chapter will be the second part of Collections where I will share about Sets, Tuples and Dictionaries, so I hope to see you there!&lt;/p&gt;

&lt;p&gt;If you enjoyed this, please share, like, and comment. I hope this can be useful to someone and that it will inspire more people to learn and code with Swift&lt;/p&gt;

</description>
      <category>learning</category>
      <category>swift</category>
      <category>mobile</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Swift 101: Basic Operators</title>
      <dc:creator>Silvia España Gil</dc:creator>
      <pubDate>Thu, 23 May 2024 13:48:07 +0000</pubDate>
      <link>https://dev.to/silviaespanagil/swift-101-basic-operators-a59</link>
      <guid>https://dev.to/silviaespanagil/swift-101-basic-operators-a59</guid>
      <description>&lt;h1&gt;
  
  
  &lt;h1&gt; Hola Mundo! &lt;/h1&gt;
&lt;/h1&gt;



&lt;p&gt;Welcome to a new article in a series of &lt;a href="https://dev.to/silviaespanagil/swift-101-getting-into-ios-development-gji"&gt;Swift 101 notes&lt;/a&gt; 📝 I did while learning the language and I decided to share them because why not?.&lt;/p&gt;

&lt;p&gt;If you're new to Swift or interested in learning more about this language, I invite you to follow my series!🙊&lt;/p&gt;

&lt;p&gt;In this chapter, I'll be sharing a little bit about &lt;code&gt;Basic Operators in Swift&lt;/code&gt;.&lt;/p&gt;




&lt;p&gt;In the &lt;a href="https://dev.to/silviaespanagil/swift-101-understanding-types-variables-and-constants-l9h"&gt;last chapter&lt;/a&gt;, we discussed constants and variables, which store values for us to use in our code.&lt;/p&gt;

&lt;p&gt;When working with these values, we often need them to interact with each other. So, how do we accomplish this? &lt;br&gt;
✨​ Enter operators✨​ &lt;/p&gt;

&lt;p&gt;Operators are special symbols that enable us to perform various operations on our variables. These operations can assign or change the value of a variable, allow us to compare one variable with another, or apply logic in our code.&lt;/p&gt;


&lt;h3&gt;
  
  
  Arithmetic operators ➕​
&lt;/h3&gt;

&lt;p&gt;Even if the "Arithmetic" name sound kinda scary, these operators are pretty simple and easy to understand. &lt;/p&gt;

&lt;p&gt;Arithmetic operators are basically symbols that allow us to create mathematical calculations, additions, subtractions, multiplications, and divisions.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Operation&lt;/th&gt;
&lt;th&gt;Action&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;th&gt;Result&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Addition +&lt;/td&gt;
&lt;td&gt;Addition between two values&lt;/td&gt;
&lt;td&gt;var addition = 34 + 4&lt;/td&gt;
&lt;td&gt;print(addition) Output: 38&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Subtraction -&lt;/td&gt;
&lt;td&gt;Subtract operation between values&lt;/td&gt;
&lt;td&gt;var subtraction = 34 - 4&lt;/td&gt;
&lt;td&gt;print(subtraction) Output: 30&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Multiplication *&lt;/td&gt;
&lt;td&gt;Multiplication of values&lt;/td&gt;
&lt;td&gt;var multiplication = 30 * 2&lt;/td&gt;
&lt;td&gt;print(multiplication) Output: 60&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Division /&lt;/td&gt;
&lt;td&gt;Division calculation&lt;/td&gt;
&lt;td&gt;var division = 30 / 2&lt;/td&gt;
&lt;td&gt;print(division) Output: 15&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;And yes, the logic says that this kind of operator only works with numeric types. However, Swift also allows us to do an addition operation with String-type variables. This is called &lt;strong&gt;string concatenation&lt;/strong&gt; and it will put together in order different strings.&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;magicSpell&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Accio 🪄 "&lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;object&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Nimbus 2000"&lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;completeSpell&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;magicSpell&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;object&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;completeSpell&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="c1"&gt;// Output: "Accio 🪄  Nimbus 2000"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Please notice that ✨this is not the only way✨ to put two strings together but as this is a &lt;code&gt;Basic Operators&lt;/code&gt; article we will not get in-depth with other ways to do so.&lt;/p&gt;




&lt;h3&gt;
  
  
  Modulo operator
&lt;/h3&gt;

&lt;p&gt;Modulo or remainder operator &lt;code&gt;%&lt;/code&gt; returns the value that is left after you divide two numbers.&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;moduleA&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;moduleB&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;5&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;moduleA&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// 1&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;moduleB&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// 0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Understanding modulo. If we divide &lt;code&gt;10 / 3&lt;/code&gt; the quotient is &lt;code&gt;3&lt;/code&gt; with a remainder of &lt;code&gt;1&lt;/code&gt;. This means that if we do &lt;code&gt;10 % 3&lt;/code&gt;, the result is &lt;code&gt;1&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Similarly, if we divide &lt;code&gt;10 / 5&lt;/code&gt; the quotient is &lt;code&gt;2&lt;/code&gt; which is already a whole number, meaning that there is no remainder from the operation. Therefore, 10 % 5 results in 0.&lt;/p&gt;

&lt;p&gt;For me, this was one of the hardest operators to understand🤦🏽‍♀️, so I wrote down an example that helped me:&lt;/p&gt;

&lt;p&gt;Imagine we have ten apples 🍎​🍎​🍎​🍎​🍎​🍎​🍎​🍎​🍎​🍎​ and there are three very hungry people, so we want to share the apples between all of us. &lt;br&gt;
​🧑‍🎤​ - 🍎​🍎​🍎&lt;br&gt;
👨‍🎤 - 🍎​🍎​🍎&lt;br&gt;
​👩‍🎤​ - 🍎​🍎​🍎&lt;br&gt;
If we want all of us to have the same amount of apples, we will each eat three apples. And there will be an extra apple 🍎 all lonely without a human to eat it. Well, that apple is the module of the first ten! Is the remainder of &lt;code&gt;10 % 3&lt;/code&gt;&lt;/p&gt;


&lt;h3&gt;
  
  
  Assignment and compound operators
&lt;/h3&gt;

&lt;p&gt;This kind of operator will assign a value to a variable or constant.&lt;/p&gt;

&lt;p&gt;The mother of the assignment operators is the &lt;strong&gt;equal operator&lt;/strong&gt; 🟰​. We have already used it in the previous chapter and is the one that says to Swift this value should be assigned to this variable or 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;var&lt;/span&gt; &lt;span class="nv"&gt;variableName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;Variable&lt;/span&gt; &lt;span class="k"&gt;Type&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;Initial&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;anotherVariable&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;Variable&lt;/span&gt; &lt;span class="k"&gt;Type&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, the equal operator can be mixed with the arithmetic operators so it does a mathematical calculation and assign the value at the same time.&lt;/p&gt;

&lt;h4&gt;
  
  
  Equal &lt;code&gt;=&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;The value from the right will be assigned to the one on the left.&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;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;
&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;b&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;a&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;Output&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Addition &lt;code&gt;+=&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;The value from the right will be added and assigned to the one on the left.&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;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;
&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;b&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;a&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;Output&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Subtraction &lt;code&gt;-=&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;The value from the right will be subtracted and assigned to the one on the left.&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;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;
&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;-=&lt;/span&gt; &lt;span class="n"&gt;b&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;a&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;Output&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Multiplication &lt;code&gt;*=&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;The value from the right will be multiplied and assigned to the one on the left.&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;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;
&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;*=&lt;/span&gt; &lt;span class="n"&gt;b&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;a&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;Output&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Division &lt;code&gt;/=&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;The value from the right will be divided and assigned to the one on the left.&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;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;
&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;/=&lt;/span&gt; &lt;span class="n"&gt;b&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;a&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;Output&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Modulo &lt;code&gt;%=&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;It will calculate the modulo and assign it to the variable on the left.&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;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;
&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;%=&lt;/span&gt; &lt;span class="n"&gt;b&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;a&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;Output&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Comparison operators
&lt;/h3&gt;

&lt;p&gt;These operators allow us, as the name states, to compare the value from the left side to the one on the right to check if the condition is true or false.&lt;/p&gt;

&lt;h4&gt;
  
  
  Equal to &lt;code&gt;==&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;The value on the right is equal to the one on the left.&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;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;b&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;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="kt"&gt;Output&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Not equal to &lt;code&gt;!=&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;The value on the right is &lt;strong&gt;not equal&lt;/strong&gt; to the one on the left.&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;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;b&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;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="kt"&gt;Output&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Greater than &lt;code&gt;&amp;gt;&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;The value on the left is &lt;strong&gt;greater&lt;/strong&gt; than the one on the right.&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;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;b&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;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;Output&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Less than &lt;code&gt;&amp;lt;&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;The value on the left is &lt;strong&gt;smaller&lt;/strong&gt; than the one on the right.&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;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;b&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;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="kt"&gt;Output&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Greater or equal to &lt;code&gt;&amp;gt;=&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;The value on the left is &lt;strong&gt;greater than or equal to&lt;/strong&gt; the one on the right.&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;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;b&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;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="kt"&gt;Output&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Less or equal to &lt;code&gt;&amp;lt;=&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;The value on the left is &lt;strong&gt;smaller than or equal to&lt;/strong&gt; the one on the right.&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;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;b&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;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="kt"&gt;Output&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Logical operators
&lt;/h3&gt;

&lt;p&gt;Logical operators allow us to check or set some rules based on logic. They compare &lt;strong&gt;two different conditions&lt;/strong&gt; and tell us if the comparison between them is true or false. &lt;br&gt;
Logical operators are particularly useful for making decisions in our code, as they enable more complex condition checking.&lt;/p&gt;

&lt;p&gt;There are three Logical Operators:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;And &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt;&lt;/strong&gt;: Check if both conditions are true → This &lt;strong&gt;and&lt;/strong&gt; that are true
&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="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;b&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;c&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;p&gt;In the example, we check if &lt;code&gt;a&lt;/code&gt;(10) is less or equal than &lt;code&gt;b&lt;/code&gt;(10) &lt;strong&gt;and&lt;/strong&gt; if &lt;code&gt;a&lt;/code&gt;(10) is the same as &lt;code&gt;b&lt;/code&gt;(10). As both of the conditions are true, then the output would be &lt;code&gt;true&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Or &lt;code&gt;||&lt;/code&gt;&lt;/strong&gt;: Check if at least one of the conditions are true  → This &lt;strong&gt;or&lt;/strong&gt; that are true
&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="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;b&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;c&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;p&gt;In the example, we check if &lt;code&gt;a&lt;/code&gt;(10) is less or equal than &lt;code&gt;b&lt;/code&gt;(100) &lt;strong&gt;or&lt;/strong&gt; if &lt;code&gt;a&lt;/code&gt;(100) is the same as &lt;code&gt;b&lt;/code&gt;(10). In this case, the first condition is true, but the second is false. As we want to know if one or the other is true, effectively, one of them is true so the output will also be &lt;code&gt;true&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Not &lt;code&gt;!&lt;/code&gt;&lt;/strong&gt;: Returns true if the operand is false and vice versa
&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="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Output: false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example, we print the negation of true which is false&lt;/p&gt;




&lt;h3&gt;
  
  
  Want to keep learning about Swift?
&lt;/h3&gt;

&lt;p&gt;So far, we've looked at what Swift is, explored types, variables, and constants, and now we've seen how basic operators can help us perform calculations, compare values, and make decisions in our code. But... there's more to come! 👩🏽‍💻&lt;/p&gt;

&lt;p&gt;This is a full series on &lt;a href="https://dev.to/silviaespanagil/swift-101-getting-into-ios-development-gji"&gt;Swift 101&lt;/a&gt;. The next chapter will be the first part of Collections and Collection Types, so I hope to see you there 🫶!&lt;/p&gt;

&lt;p&gt;If you enjoyed this, please share, like, and comment. I hope this can be useful to someone and that it will inspire more people to learn and code with Swift.&lt;/p&gt;

</description>
      <category>learning</category>
      <category>swift</category>
      <category>mobile</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Swift 101: Understanding Types, Variables, and Constants</title>
      <dc:creator>Silvia España Gil</dc:creator>
      <pubDate>Tue, 14 May 2024 14:37:30 +0000</pubDate>
      <link>https://dev.to/silviaespanagil/swift-101-understanding-types-variables-and-constants-l9h</link>
      <guid>https://dev.to/silviaespanagil/swift-101-understanding-types-variables-and-constants-l9h</guid>
      <description>&lt;h1&gt;
  
  
  &lt;h1&gt; Hola Mundo! &lt;/h1&gt;
&lt;/h1&gt;



&lt;p&gt;This is the second article in a series of &lt;a href="https://dev.to/silviaespanagil/swift-101-getting-into-ios-development-gji"&gt;Swift 101 notes&lt;/a&gt; 📝 I did while learning the language and I decided to share them because why not?.&lt;/p&gt;

&lt;p&gt;So if you don't know what Swift is or you would like to know more about this language, I invite you to follow my series!🙊&lt;/p&gt;

&lt;p&gt;In this chapter I'll be sharing a little bit about &lt;code&gt;Types, Variables and Constants&lt;/code&gt; and how they work and behave in Swift.&lt;/p&gt;




&lt;p&gt;Swift is a strongly typed language, but what does that mean? It means that at the moment that the code compiles &lt;strong&gt;all&lt;/strong&gt; variables and constants types are known and they &lt;strong&gt;cannot be changed after declaring it.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To know so, Swift will first check the variable or constant and check if we have declared the type. If we haven’t Swift will take the first value assigned and set it.&lt;/p&gt;

&lt;p&gt;If you have worked with other heavily typed languages like for example Java, C#, or C++ then you must know that Swift works similarly. &lt;/p&gt;

&lt;p&gt;However, if you have no experience in coding, or have more experience in languages such as Javascript, ✨​that is what happened to me when I learned Swift✨​, this might be new for you.&lt;/p&gt;




&lt;h3&gt;
  
  
  Variables and constants
&lt;/h3&gt;

&lt;p&gt;Variables and constants are a sort of storage location that we create and associate with a certain name so we can use it along our code. Is a container for a value📦​.&lt;/p&gt;

&lt;p&gt;As their name state  &lt;strong&gt;variables&lt;/strong&gt; are flexible in the sense that after declaring it, their value can change. However, constants can’t, their value is set and it cannot be changed.&lt;/p&gt;

&lt;p&gt;To use these containers and their value we must first declare them. To do so we must use &lt;code&gt;var&lt;/code&gt; or &lt;code&gt;let&lt;/code&gt; followed by a keyword that will work as a name.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

var variableName = &amp;lt;Initial value&amp;gt;
let constantName = &amp;lt;Initial value&amp;gt;


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

&lt;/div&gt;

&lt;p&gt;So for example, let's think of a variable. We could have the userPhone that they can change later on. So we store the userPhone in a variable, and later, in a method we change it for the new one.&lt;/p&gt;

&lt;p&gt;In the case of constants is the contrary, we have information that the user can't change. For example, delicate data like an ID number might be not editable because it's inherent to that user. So that kind of data will be stored in a constant.&lt;/p&gt;




&lt;h4&gt;
  
  
  Variable and constant naming
&lt;/h4&gt;

&lt;p&gt;Naming a variable or constant can be tricky sometimes. The names can be composed of letters, numbers, and underscore. However, depending on the team conventions sometimes the underscore is not used and we use camelCase, which means that each time a word starts we put it in capital letters, it would look like this: &lt;code&gt;thisIsTheNewVariable&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Variables and constants names should also be self-explanatory, which means that is not a good practice to use namings such as &lt;code&gt;var password&lt;/code&gt; and &lt;code&gt;var password2&lt;/code&gt;. Because what does &lt;code&gt;password2&lt;/code&gt; mean, what does it do🤔​? &lt;/p&gt;

&lt;p&gt;Is better to set names as &lt;code&gt;var currentPassword&lt;/code&gt; and &lt;code&gt;var newPassword&lt;/code&gt;. This way, as soon as you see the naming you already know what is stored. &lt;/p&gt;

&lt;p&gt;If at a certain point, you find yourself not knowing how to name something just ask yourself, what does this storage? what does it do? And go in that direction.&lt;/p&gt;




&lt;h3&gt;
  
  
  Basic Swift Types
&lt;/h3&gt;

&lt;p&gt;As stated before when we create either a variable or constant we should set its type or Swift will set it for us 🎯​. &lt;/p&gt;

&lt;p&gt;For declaring a type we will create our variable or constant followed by &lt;code&gt;:&lt;/code&gt; and the type name. If it already has a value we will follow the type with the &lt;code&gt;=&lt;/code&gt; and the initial value but this last part is not necessary.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

var variableName: &amp;lt;Variable Type&amp;gt; = &amp;lt;Initial value&amp;gt;
var anotherVariable: &amp;lt;Variable Type&amp;gt;


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

&lt;/div&gt;

&lt;p&gt;There are many types in Swift, however, the most basic ones may be separated into two categories: individual data types and collection types.&lt;/p&gt;

&lt;h4&gt;
  
  
  Individual data types
&lt;/h4&gt;

&lt;p&gt;As the name states these types tell the system that the value that we are storing is a single value. There are six main individual data types, three of them for different kinds of numbers, two of them with words, and the last one for booleans. &lt;/p&gt;

&lt;p&gt;Let's have a look at them​ 👀&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Type name&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Int&lt;/td&gt;
&lt;td&gt;It reads as integers. This type is used for &lt;strong&gt;whole numbers&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;var integer: Int = 2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Double&lt;/td&gt;
&lt;td&gt;Is another number-related type that represents 64-bit floating numbers (&lt;strong&gt;with decimals&lt;/strong&gt;). Double range is set to 15 digits ≈&lt;/td&gt;
&lt;td&gt;let pi: Double = 3.14159265358979323&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Float&lt;/td&gt;
&lt;td&gt;Is used to represent 32-bit floating numbers. Float range is set to 7 digits ≈&lt;/td&gt;
&lt;td&gt;let shorterPi: Float = 3.1415926&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;String&lt;/td&gt;
&lt;td&gt;To represent text, it may be words or sentences. The name comes from a string of characters.&lt;/td&gt;
&lt;td&gt;var greetings: String = "Welcome"&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Character&lt;/td&gt;
&lt;td&gt;This is for a single character, such as a letter, digit, and even punctuation mark or symbols.&lt;/td&gt;
&lt;td&gt;var initial: Character = "W"&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Bool&lt;/td&gt;
&lt;td&gt;Represents one of two possible values: true  or false&lt;/td&gt;
&lt;td&gt;var isThisABool: Bool = true&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;As I said before, Swift is a strong typed language, so, if we don’t set the type, our variable or constant will be assigned by the system. &lt;/p&gt;

&lt;p&gt;How does Swift automatically assign types? It checks the variable value and sets it. &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

// Will be typed as a "String"
var variableA = "It's me a Mario"
// Will be typed as a Bool
var isYoshiAvailable = false


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

&lt;/div&gt;




&lt;h4&gt;
  
  
  Collection data types
&lt;/h4&gt;

&lt;p&gt;On the other hand, we have collection data types. Collections are types that contain multiple values. This means that one variable or constant can store many values in it.&lt;br&gt;
There are many collection types in Swift but we are going to talk about them in another chapter of Swift 101. &lt;/p&gt;

&lt;p&gt;So keep an eye on the next posts of this series🤓!&lt;/p&gt;




&lt;h3&gt;
  
  
  Resources
&lt;/h3&gt;

&lt;p&gt;If you want a Cheat Sheet with the individual data types information, feel free to save or download this image. If you share it please do not delete or hide my name 🫶🏻​&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0elxnxaavopagzv6a1sy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0elxnxaavopagzv6a1sy.png" alt="Cheat sheet with all the information in the table"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Also if you want to keep learning more about this I highly recommend checking the official documentation and courses &lt;a href="https://developer.apple.com/learn/" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  Want to keep learning about Swift?
&lt;/h3&gt;

&lt;p&gt;This a full series on &lt;a href="https://dev.to/silviaespanagil/swift-101-getting-into-ios-development-gji"&gt;Swift 101&lt;/a&gt;, next chapter will be about Basic Operators in Swift, so I hope to see you there!&lt;/p&gt;

&lt;p&gt;If you enjoyed this, please share, like, and comment. I hope this can be useful to someone and that it will inspire more people to learn and code with Swift&lt;/p&gt;

</description>
      <category>learning</category>
      <category>swift</category>
      <category>mobile</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Swift 101: What's Swift?</title>
      <dc:creator>Silvia España Gil</dc:creator>
      <pubDate>Sat, 04 May 2024 09:52:16 +0000</pubDate>
      <link>https://dev.to/silviaespanagil/swift-101-whats-swift-1p10</link>
      <guid>https://dev.to/silviaespanagil/swift-101-whats-swift-1p10</guid>
      <description>&lt;h1&gt;
  
  
  &lt;h1&gt; Hola Mundo! &lt;/h1&gt;
&lt;/h1&gt;



&lt;p&gt;Ready for some Swift?&lt;/p&gt;

&lt;p&gt;This is my first article in a series of &lt;a href="https://dev.to/silviaespanagil/swift-101-getting-into-ios-development-gji"&gt;Swift 101 notes&lt;/a&gt; 📝 I did while learning the language and I decided to share them because why not?.&lt;/p&gt;

&lt;p&gt;Well and also because I received so many nice and encouraging comments on my Twitter account that made me super happy 💖.&lt;/p&gt;

&lt;p&gt;When I first started mobile development and read about Swift I was quite confused because the only Swift I knew was the bank code 🙈​! &lt;/p&gt;

&lt;p&gt;So, let's get to it.&lt;/p&gt;




&lt;h3&gt;
  
  
  What is Swift?
&lt;/h3&gt;

&lt;p&gt;Swift is an open-source programming language specifically designed by Apple Inc. for development across the entire Apple ecosystem. While it's primarily associated with iOS development for iPhones and iPads, Swift is also utilized for macOS, watchOS, visionOS, and tvOS applications.&lt;/p&gt;

&lt;p&gt;So whether you're building a mobile app, a desktop application, or software for wearable devices or home entertainment systems, Swift provides a unified language and toolset.&lt;/p&gt;

&lt;p&gt;On its creation, Apple wanted to move away from C and ended up with an original object-oriented language that, in their words, aims to be new, modern, faster, and easier, allowing developers to produce expressive code.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxuo9jrj9ersq4820cn49.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxuo9jrj9ersq4820cn49.png" alt="Screenshot showing how code was written with Objective C vs Swift. In Objective C we have NSString *message = @" width="800" height="540"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“was inspired by drawing ideas from Ruby, Python, C#, CLU, and far too many others to list”&lt;/p&gt;

&lt;p&gt;Chris Lattner&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h3&gt;
  
  
  What is SwiftUI?
&lt;/h3&gt;

&lt;p&gt;On the other hand, we have SwiftUI. SwiftUI is a Swift framework that allows us to describe and control the user interface. So basically it helps us build, what the user sees.&lt;/p&gt;

&lt;p&gt;However, SwiftUI is quite new, and you may encounter some challenges building some things that you could solve with UIKit. UiKit was the former framework used to design the interface but that has been updated to SwiftUI. However I heavily recommend you to try and find SwiftUI solutions, even if they look harder, I've found that doing so is a great exercise to learn&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fob289guaju78mvxgm597.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fob289guaju78mvxgm597.png" alt="WWDC 2022 - Platform State of the Union Screenshot that shows the phrase " width="800" height="484"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  Swift vs. SwiftUI
&lt;/h3&gt;

&lt;p&gt;I know you could be thinking, aren't both the same thing? But no, they are not, Swift and SwiftUI are not the same but they are complementary ones for each other.&lt;/p&gt;

&lt;p&gt;Swift is the programming language, the one that says our app what our program should do. SwiftUI is a Swift framework,  interface-oriented that controls the aspect of our application.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Building an app is the process of writing Swift code to control SwiftUI"&lt;/p&gt;

&lt;p&gt;Paul Hudson&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h3&gt;
  
  
  How to code with Swift? -
&lt;/h3&gt;

&lt;h4&gt;
  
  
  IDE
&lt;/h4&gt;

&lt;p&gt;As with all languages, to code we need an IDE. An IDE is an Integrated Development Environment, in simpler words is a code editor in which developers can write and build code. &lt;/p&gt;

&lt;p&gt;If you want to build iOS apps with Swift you will need XCode. This IDE is available in the App Mac Store and on the Developer's Resources page, &lt;a href="https://developer.apple.com/xcode/resources/" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;XCode is only intended to run on Mac and it allows us to create full-on projects for mobile, wearables, and tv.&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1quaboinjdxlf2qv9cs6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1quaboinjdxlf2qv9cs6.png" alt="Screenshot of XCode Tab" width="800" height="505"&gt;&lt;/a&gt;&lt;br&gt;
If you don't have a Mac but still want to try some Swift you may download Swift Playgrounds on iPad or use an online tool like &lt;a href="https://online.swiftplayground.run" rel="noopener noreferrer"&gt;Online Swift Playground&lt;/a&gt;  &lt;/p&gt;




&lt;h3&gt;
  
  
  Want to keep learning about Swift?
&lt;/h3&gt;

&lt;p&gt;This a full series on &lt;a href="https://dev.to/silviaespanagil/swift-101-getting-into-ios-development-gji"&gt;Swift 101&lt;/a&gt;, next chapter will be about Types, variables, and constants in Swift, so I hope to see you there!&lt;/p&gt;

&lt;p&gt;If you enjoyed this, please share, like, and comment. I hope this can be useful to someone and that it will inspire more people to learn and code with Swift&lt;/p&gt;

</description>
      <category>swift</category>
      <category>mobile</category>
      <category>learning</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
