<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Alvar Arias</title>
    <description>The latest articles on Forem by Alvar Arias (@alvararias).</description>
    <link>https://forem.com/alvararias</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%2F596837%2F0ac80d7f-efe6-4a35-b544-0aed16092bf2.jpeg</url>
      <title>Forem: Alvar Arias</title>
      <link>https://forem.com/alvararias</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/alvararias"/>
    <language>en</language>
    <item>
      <title>How to read data from Google Sheets using Sheetson</title>
      <dc:creator>Alvar Arias</dc:creator>
      <pubDate>Fri, 30 Dec 2022 15:32:58 +0000</pubDate>
      <link>https://forem.com/alvararias/how-to-read-data-from-google-sheets-using-sheetson-3h5o</link>
      <guid>https://forem.com/alvararias/how-to-read-data-from-google-sheets-using-sheetson-3h5o</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;To read data in Google Sheets you can use the Google API &lt;a href="https://developers.google.com/sheets/api/guides/concepts" rel="noopener noreferrer"&gt;Here&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;You can also use a service that simplifies our authentication work and is ideal for testing an APP: Sheetson, this service simplifies development work, especially Google authentication, which can be complicated and take a long time, so this service It is ideal for developing prototypes and testing quickly and effectively.&lt;/p&gt;

&lt;p&gt;The service works as follows: it offers a free version that works well and a payment for 10 USD per month. I used the free version and it worked well for me.&lt;/p&gt;

&lt;h2&gt;
  
  
  Description
&lt;/h2&gt;

&lt;p&gt;To start, go to the website of the service &lt;a href="https://sheetson.com" rel="noopener noreferrer"&gt;Sheetson&lt;/a&gt; , register with your google account in the "Get Started" button under the free account.&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%2Fk9bib9mkjmeaa7r00jae.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%2Fk9bib9mkjmeaa7r00jae.png" alt="Get Started" width="800" height="924"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once you are registered, press the "go to console" button that is at the top right of the page.&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%2Fk4odb1nhvswp8hiatvwo.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%2Fk4odb1nhvswp8hiatvwo.png" alt="Console" width="800" height="344"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here you can see your name, your email and your API Key, you can also generate an API KEY for reading only.&lt;/p&gt;

&lt;p&gt;Ready now you can see the page ”Examples” there you will find detailed examples in CURL and Javascript, for example to read data you can see the page: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://docs.sheetson.com/manage-data/create-rows/" rel="noopener noreferrer"&gt;Create Rows&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0m3h3pf50y60zgfzme60.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%2F0m3h3pf50y60zgfzme60.png" alt="Doc create rows" width="800" height="409"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The examples are simple and well detailed so it won't take you long to understand the API.&lt;/p&gt;

&lt;p&gt;In my case, I used it to make a GET API call and it connects to the Google Sheets spreadsheet with the information of the new users of my APP in SwiftUI that showed me the data correctly.&lt;/p&gt;

&lt;h3&gt;
  
  
  Diagram:
&lt;/h3&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%2F1gir9iynkgold9oz8z58.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%2F1gir9iynkgold9oz8z58.png" alt="Diagram" width="681" height="224"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  In my App:
&lt;/h3&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%2Fi1t7wzcvl0t0n97d8je5.jpg" 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%2Fi1t7wzcvl0t0n97d8je5.jpg" alt="my App" width="800" height="221"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Well, I hope I have been motivated to use this service, since in my case it helped me to finish my prototype quickly and visualize the information in my app correctly. &lt;/p&gt;

</description>
      <category>career</category>
      <category>programming</category>
      <category>watercooler</category>
    </item>
    <item>
      <title>Como leer datos desde Google Sheets usando Sheetson</title>
      <dc:creator>Alvar Arias</dc:creator>
      <pubDate>Fri, 30 Dec 2022 13:20:12 +0000</pubDate>
      <link>https://forem.com/alvararias/como-leer-datos-desde-google-sheets-usando-sheetson-fom</link>
      <guid>https://forem.com/alvararias/como-leer-datos-desde-google-sheets-usando-sheetson-fom</guid>
      <description>&lt;h2&gt;
  
  
  Introducción
&lt;/h2&gt;

&lt;p&gt;Para leer datos en Google Sheets se puede utilizar la API de Google &lt;a href="https://developers.google.com/sheets/api/guides/concepts" rel="noopener noreferrer"&gt;Aqui&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;También puedes utilizar un servicio que simplifica nuestro trabajo de autentificación y es ideal para realizar testeo de una APP : Sheetson, este servicio simplifica el trabajo de desarrollo especialmente de la autenticación en Google que puede resultar complicada y tomar largo tiempo, por lo que este servicio es ideal para desarrollar prototipos y testar de forma rápida y efectiva.&lt;/p&gt;

&lt;p&gt;El servicio funciona de la siguiente manera, ofrece una versión free que funciona bien y de pago por 10 USD por mes, yo utilize la version free y me funciono bien.&lt;/p&gt;

&lt;h2&gt;
  
  
  Descripción
&lt;/h2&gt;

&lt;p&gt;Para comenzar anda a la página web del  servicio &lt;a href="https://sheetson.com" rel="noopener noreferrer"&gt;Sheetson&lt;/a&gt; , registrate con tu cuenta google en el botón “Get Started” bajo la cuenta free.&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%2Frquosaq0kmk3to80nmgt.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%2Frquosaq0kmk3to80nmgt.png" alt="Get Started" width="800" height="924"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Una vez que estés registrado presiona el botón “go to console” que está en la parte superior derecha de la página.&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%2Fkfzqndi8g2hap7hl9d94.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%2Fkfzqndi8g2hap7hl9d94.png" alt="console" width="800" height="344"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Aquí podrás ver tu nombre, tu email y tu API Key, también puedes generar una API KEY solo para lectura.&lt;/p&gt;

&lt;p&gt;Listo ahora puedes ver la página ”Examples” allí encontrarás ejemplos detallados en CURL y Javascript, por ejemplo para leer datos puedes ver la página: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://docs.sheetson.com/manage-data/create-rows/" rel="noopener noreferrer"&gt;Crear filas&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq789xesxs7n0neah1dnc.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%2Fq789xesxs7n0neah1dnc.png" alt="crear filas ejemplo" width="800" height="409"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Los ejemplos son simples y bien detallados por lo que no te tomará mucho tiempo entender la API.&lt;/p&gt;

&lt;p&gt;En mi caso lo utilicé para realizar una llamada GET API y este se conecta a la planilla Google Sheets con la información de los nuevos usuarios de my APP en SwiftUI que me mostró la data de manera correcta.&lt;/p&gt;

&lt;p&gt;Diagrama:&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%2Fvv1z7rkhifhwfdygp1qk.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%2Fvv1z7rkhifhwfdygp1qk.png" alt="App diagrama" width="681" height="224"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;En mi App&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl2jpetmcvfu179ajh4u6.jpg" 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%2Fl2jpetmcvfu179ajh4u6.jpg" alt="customer" width="800" height="221"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Bueno espero haber motivado para utilizar este servicio, ya que en mi caso me ayudó a terminar mi prototipo de manera rápida y visualizar la información en mi app de manera correcta. &lt;/p&gt;

</description>
      <category>opensource</category>
      <category>management</category>
      <category>productivity</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Core Data in SwiftUI simple example</title>
      <dc:creator>Alvar Arias</dc:creator>
      <pubDate>Mon, 12 Dec 2022 10:20:37 +0000</pubDate>
      <link>https://forem.com/alvararias/core-data-in-swiftui-simple-example-48fb</link>
      <guid>https://forem.com/alvararias/core-data-in-swiftui-simple-example-48fb</guid>
      <description>&lt;p&gt;This is a very simple example of how to add Core Data to a project in SwiftUI.&lt;/p&gt;

&lt;p&gt;To add Core Data to a project we need to follow these steps:&lt;/p&gt;

&lt;p&gt;1 Create a Data model first, we insert a Data Model type file:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4X1NdzrO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9pkluahs7sfiakyfn30s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4X1NdzrO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9pkluahs7sfiakyfn30s.png" alt="Image description" width="880" height="228"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then we assign a name to the file, in this case, “ModelApp” and by pressing the “Add Entity” button ” we create an entity (object inside the model).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tmS6Sc1m--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/41hsuprli36ts8rqd54p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tmS6Sc1m--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/41hsuprli36ts8rqd54p.png" alt="Image description" width="880" height="220"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2 We create the "DataController" class in charge of managing Core Data within our application. For this we insert the "DataController.swift" file and write the following:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HuEZjj7H--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8ie7qnbzdgee1p7wmt0q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HuEZjj7H--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8ie7qnbzdgee1p7wmt0q.png" alt="Image description" width="715" height="274"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;3 We add the data controller to our project.&lt;br&gt;
For this, we go to the initial file of our project, in this case, I open the file: "CoreDataEjemploApp.swift"&lt;/p&gt;

&lt;p&gt;First I create a variable of type @StateObject, called "dataController" which is of type "DataController()" (the class we had defined above)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IM4n59Kb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jzkyffkrf2hbavztwtxa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IM4n59Kb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jzkyffkrf2hbavztwtxa.png" alt="Image description" width="752" height="267"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then we add to the initial View in this case “ContentView” the variable “dataController” as a variable of type “environment” and this will be available to our View and the remaining Views through the viewContext() method.&lt;/p&gt;

&lt;p&gt;We already have Data Core configured in our project, now we are going to read and add data that we will save persistently using our model.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reading and writing data to Core Data&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;4.1 To read data to Core Data in the ContentView.Swift file, we write the following line:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Fv4lAxR1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tjjhi6qbip64ttk7eo25.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Fv4lAxR1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tjjhi6qbip64ttk7eo25.png" alt="Image description" width="625" height="45"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Where @Fetch request is the property that allows us to create a variable called “products” that is the result of fetch data from the entity "Product" under a certain criterion in this case we request all the data using "sortDescriptors: []".&lt;/p&gt;

&lt;p&gt;4.2.To write data to Core Data in the ContentView.Swift file, we write the following line:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IeWYPvfk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xxupbldmmqppocv9tbdg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IeWYPvfk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xxupbldmmqppocv9tbdg.png" alt="Image description" width="525" height="49"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then we create a listView to display the data we have read from Core Data.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xVx640Z_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cuphw65l2ae7ebsm6dzw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xVx640Z_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cuphw65l2ae7ebsm6dzw.png" alt="Image description" width="408" height="87"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In addition to an "Add" button that adds data to our container.&lt;/p&gt;

&lt;p&gt;Finally, we use try to save the information we have generated:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qEk7EVeg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/30jvu3talx4qruvt46xy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qEk7EVeg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/30jvu3talx4qruvt46xy.png" alt="Image description" width="384" height="49"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The final file looks like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--M_GWN4ob--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2c10qlrns51zda59892k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--M_GWN4ob--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2c10qlrns51zda59892k.png" alt="Image description" width="662" height="672"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We try clicking the "Add" button and we will randomly fill data with different names for our products.&lt;/p&gt;

&lt;p&gt;You can stop the app and reload it and you will see that the data has been permanently recorded.&lt;/p&gt;

&lt;p&gt;Conclusion:&lt;/p&gt;

&lt;p&gt;This is a very simple project to see how Core Data works in SwiftUI, I hope I have motivated you to investigate more and use this excellent tool that we have to permanently save data in our applications, with the great advantage of not having to add external libraries and not grow the size of our App excessively.&lt;/p&gt;

&lt;p&gt;You can download the project &lt;a href="https://github.com/AlvarArias/CoreDataEjemplo.git"&gt;here&lt;/a&gt;&lt;/p&gt;

</description>
      <category>swiftu</category>
      <category>beginners</category>
      <category>swift</category>
    </item>
    <item>
      <title>Core Data en SwiftUI Simple Ejemplo</title>
      <dc:creator>Alvar Arias</dc:creator>
      <pubDate>Thu, 28 Jul 2022 10:59:00 +0000</pubDate>
      <link>https://forem.com/alvararias/core-data-en-swiftui-simple-ejemplo-13bn</link>
      <guid>https://forem.com/alvararias/core-data-en-swiftui-simple-ejemplo-13bn</guid>
      <description>&lt;p&gt;Este es un ejemplo muy simple de cómo agregar Core Data a un proyecto en SwiftUI.&lt;/p&gt;

&lt;p&gt;Para agregar Core Data a un proyecto necesitamos seguir los siguientes pasos:&lt;/p&gt;

&lt;p&gt;1 Crear un Data model, primero insertamos un archivo tipo Data Model :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LMFJNFxO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fiw8iavpfg1xr2cjumkz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LMFJNFxO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fiw8iavpfg1xr2cjumkz.png" alt="Create Core Data Model" width="811" height="604"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Luego le asignamos un nombre al archivo, en esta caso “ModelApp”  y presionando el botón “Add Entity” creamos una entidad (objeto dentro del modelo). &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--AYRrQbnh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q1u78yrysabnsncc08a7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AYRrQbnh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q1u78yrysabnsncc08a7.png" alt="Add Entity" width="340" height="153"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Asignamos un nombre a nuestra entidad, en este caso “Productos” y propiedades de la entidad con su nombre y tipo de data:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--v7qjjy2j--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cbt8gazmnl08cqsopz9m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--v7qjjy2j--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cbt8gazmnl08cqsopz9m.png" alt="Productos" width="880" height="220"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2 Creamos la clase “DataController” encargada de administrar Core Data dentro de nuestra aplicación. Para esto insertamos el archivo “DataController.swift” y escribimos lo siguiente: &lt;/p&gt;

&lt;p&gt;Primero importamos CoreData al archivo &lt;br&gt;
Luego definimos una clase “Data Controller” del tipo “ObservableObject”, esto es muy importante ya que así lo podremos insertar dentro del proyecto.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Cimu_gJr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jqrq78n2xp0jh1y6a6fo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Cimu_gJr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jqrq78n2xp0jh1y6a6fo.png" alt="clase Data Controller" width="642" height="284"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;3 Agregamos el data controller a nuestro proyecto.&lt;br&gt;
Para esto nos vamos al archivo inicial de nuestro proyecto en este caso abro el archivo: “CoreDataEjemploApp.swift”&lt;/p&gt;

&lt;p&gt;Primero Creo una variable del tipo  @StateObject, llamada “dataController” que es del tipo “DataController()” (la  clase que habíamos definido anteriormente)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zjvQ-ye4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sj4576kx1rvg3q83fbfi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zjvQ-ye4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sj4576kx1rvg3q83fbfi.png" alt="Insert Data Controller" width="782" height="278"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Luego agregamos a la View inicial en este caso “ContentView” la variable “dataController” como una variable del tipo “environment” es y esta estará disponible para nuestra View y las restantes Views a través del método viewContext() .&lt;/p&gt;

&lt;p&gt;Ya tenemos configurado Data Core en nuestro proyecto, ahora vamos a leer y agregar datos que guardaremos en forma persistente usando nuestro modelo.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Leer y grabar datos en Core Data
4.1 Para leer datos a Core Data en el archivo ContentView.Swift ,  escribimos la siguiente línea:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZZGMq-LM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u14jqjem1cjjjdlrxdhg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZZGMq-LM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u14jqjem1cjjjdlrxdhg.png" alt="Fetch Data" width="625" height="45"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Donde @Fetch request es la propiedad que nos permite crear una variable llamada  “products” que es el resultado de traer data desde la entidad “Producto” bajo un cierto criterio en este caso pedimos toda la data al usar "sortDescriptors: []".&lt;/p&gt;

&lt;p&gt;4.2.Para grabar datos a Core Data en el archivo ContentView.Swift ,  escribimos la siguiente línea:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RCo6Ya5P--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kexer117i7zuda87z21v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RCo6Ya5P--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kexer117i7zuda87z21v.png" alt="Write data" width="525" height="49"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Luego creamos un listView para mostrar los datos que hemos leído desde Core Data.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--X33lxS58--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kpatmbec3qfgot5av630.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--X33lxS58--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kpatmbec3qfgot5av630.png" alt="List View" width="408" height="87"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;además de un botón “Add” que agrega data a nuestro container. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fuaCLHcu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0m1p0bipwrt6s0k1dlhz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fuaCLHcu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0m1p0bipwrt6s0k1dlhz.png" alt="Button Add" width="617" height="279"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finalmente usamos try para grabar la información que hemos generado: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sokGQlwg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6ttu9p1d2arpvprhl8di.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sokGQlwg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6ttu9p1d2arpvprhl8di.png" alt="Try for save" width="384" height="49"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;El archivo final quedó así:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GlPxsGex--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rms82v27pv7gy462t80m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GlPxsGex--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rms82v27pv7gy462t80m.png" alt="Archivo final" width="662" height="672"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Probamos hacer click al botón “Add” y llenaremos de data de forma aleatoria con diferentes nombres para nuestros productos, obtendremos una pantalla así: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GlBww0-R--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/neib3rwhdqqrt3w2klb3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GlBww0-R--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/neib3rwhdqqrt3w2klb3.png" alt="Pantalla simulador" width="750" height="1334"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Puedes detener la aplicación y volverla a cargar y verás que la data ha sido grabada en forma permanente.&lt;/p&gt;

&lt;p&gt;Conclusión:&lt;/p&gt;

&lt;p&gt;Este es un proyecto muy simple para visualizar cómo funciona Core Data en SwiftUI, espero haberte motivado a investigar más y utilizar esta excelente herramienta de que disponemos para guardar data en forma permanente en nuestras aplicaciones, con la gran ventaja de no tener que agregar librerías externas y no hacer crecer el tamaño de nuestra App en forma excesiva. &lt;/p&gt;

&lt;p&gt;Este es mi primer tutorial, espero seguir compartiendo proyectos para ilustrar y hacer más simple la comprensión de SwiftUI. &lt;/p&gt;

&lt;p&gt;El proyecto lo puedes descargar &lt;a href="https://github.com/AlvarArias/CoreDataEjemplo.git"&gt;aqui&lt;/a&gt; &lt;/p&gt;

</description>
      <category>swifui</category>
      <category>beginners</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
