<?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: Fabrício Masiero</title>
    <description>The latest articles on DEV Community by Fabrício Masiero (@fabriciomasiero).</description>
    <link>https://dev.to/fabriciomasiero</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%2F380452%2Feb676111-d9ae-48cd-8bbe-8a9446ce6d66.JPG</url>
      <title>DEV Community: Fabrício Masiero</title>
      <link>https://dev.to/fabriciomasiero</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/fabriciomasiero"/>
    <language>en</language>
    <item>
      <title>UITableView with multiple kinds of cells (also works on UICollectionView)</title>
      <dc:creator>Fabrício Masiero</dc:creator>
      <pubDate>Wed, 27 May 2020 17:29:13 +0000</pubDate>
      <link>https://dev.to/fabriciomasiero/uitableview-with-multiple-kinds-of-cells-also-works-on-uicollectionview-1dch</link>
      <guid>https://dev.to/fabriciomasiero/uitableview-with-multiple-kinds-of-cells-also-works-on-uicollectionview-1dch</guid>
      <description>&lt;p&gt;Hi everyone =D  &lt;/p&gt;

&lt;p&gt;I will show in this article how to use multiple types of cells in your UITableView or UICollectionView.&lt;br&gt;
A lot of developers do that in the wrong way, using sections or rows to present another kind of cell.&lt;/p&gt;
&lt;h3&gt;
  
  
  This tutorial will be separated on 3 fronts:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;em&gt;1 - Create a model&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;2 - Register cells on your controller&lt;/em&gt; &lt;/li&gt;
&lt;li&gt;&lt;em&gt;3 - Organize it on cellForRow&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Creating a model
&lt;/h3&gt;

&lt;p&gt;First of all, I create a simple model to populate my table.&lt;/p&gt;


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


&lt;p&gt;The secret of this model is the &lt;strong&gt;enum VehicleType&lt;/strong&gt;. That changes &lt;em&gt;everything&lt;/em&gt;!&lt;/p&gt;

&lt;h3&gt;
  
  
  Creating and register cell on table
&lt;/h3&gt;

&lt;p&gt;After that, I create 3 kinds of cell:&lt;/p&gt;

&lt;p&gt;Bike Cell&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%2Fi%2F9jmh98j7g15pkcn5014r.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%2Fi%2F9jmh98j7g15pkcn5014r.png" alt="Bike Cell"&gt;&lt;/a&gt;&lt;br&gt;
Car Cell&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F8wv4aintx87x7dtwa1ka.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%2Fi%2F8wv4aintx87x7dtwa1ka.png" alt="Car Cell"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And finally, Motorbike Cell&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ffemeu42c246v2geqeyar.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%2Fi%2Ffemeu42c246v2geqeyar.png" alt="Moto Cell"&gt;&lt;/a&gt;&lt;/p&gt;


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


&lt;p&gt;And create an array of vehicles:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h3&gt;
  
  
  Set cell on cellForRow
&lt;/h3&gt;

&lt;p&gt;Ok, we are almost done! What we need to do right now is configure our &lt;code&gt;cellForRow atIndexPath&lt;/code&gt; or &lt;code&gt;itemForRow atIndexPath&lt;/code&gt;. &lt;br&gt;
Write an switch case to determine what kind of cell table will present. Like this example:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;But, if you saw, each cell has a different size. Ok, let's do the same thing on &lt;code&gt;heightForRow atIndexPath&lt;/code&gt;&lt;/p&gt;


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


&lt;p&gt;And that's it! Simple, beautiful, and very easy!&lt;/p&gt;

&lt;p&gt;I don't prepared a beautiful layout on these cells, but, take a look, we have 3 different cells on the same Table or Collection:&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%2Fi%2Fw1rhy63xxwkxjy7pkqwt.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%2Fi%2Fw1rhy63xxwkxjy7pkqwt.png" alt="View Controller"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;a href="https://github.com/fabriciomasiero/MultipleCellTableView" rel="noopener noreferrer"&gt;Download source code here =D&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;I hope I have helped everyone looking for this change. &lt;br&gt;
If you would like to extend the discussion, call me on &lt;a href="https://twitter.com/fabri_masiero" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;&lt;/p&gt;

&lt;h6&gt;
  
  
  Happy Coding :)
&lt;/h6&gt;

</description>
      <category>swift</category>
      <category>tableview</category>
      <category>cell</category>
      <category>xcode</category>
    </item>
    <item>
      <title>WWDC or AltConf?</title>
      <dc:creator>Fabrício Masiero</dc:creator>
      <pubDate>Wed, 06 May 2020 19:53:22 +0000</pubDate>
      <link>https://dev.to/fabriciomasiero/wwdc-or-altconf-ndj</link>
      <guid>https://dev.to/fabriciomasiero/wwdc-or-altconf-ndj</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Nna8yugY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/qk613e92msyfrut9ntyj.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Nna8yugY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/qk613e92msyfrut9ntyj.jpeg" alt="Moscone Center at WWDC 2016 San Francisco"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;First of all, I would like to introduce myself, I am Fabrício Masiero, I have been working with iOS for over 8 years and today I lead a team in the largest education company in Brazil.&lt;/p&gt;

&lt;p&gt;Why is presentation important? Because it can help you choose the ideal event. I will explain it throughout the text.&lt;/p&gt;

&lt;p&gt;Every iOS Developer dreams of going to one of these events and I will share my experiences in each one.&lt;br&gt;
My first event was in 2016, the last year at the Moscone Center — San Francisco. I went to AltConf alone, knowing nothing and nobody. The event itself was not as famous as it is today, the talks took place inside a cinema, they had limited space and little infrastructure. It was amazing, I learned a lot and met a lot of interesting people.&lt;/p&gt;

&lt;p&gt;The following year, I went with a friend. He went to WWDC and I went to AltConf. It was in that year that I understood what were the differences between the events, even though I had never participated in WWDC until then.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;In those years, I had autonomy and the possibility to use in practice everything I learned in the events&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;In 2018, my company sponsored WWDC. I felt the chill in my belly again when I first went to AltConf. I did everything that a first-time dub needs to do: catch queues, wake up early for the keynote and choose all the talks he was interested in advance.&lt;br&gt;
I learned a lot, I met a lot of people (including Tim) and it was totally incredible.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_ghPHyZt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/5mirhs0z9q9rkneh7w6n.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_ghPHyZt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/5mirhs0z9q9rkneh7w6n.jpeg" alt="Me and Tim Cook =D"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Okay, now I need to put what I learned into practice… But can you put it all into production? Can you use all the news I learned, day by day? Even more, referring to Brazilian users who do not always update at the same speed as Apple products are launched.&lt;/p&gt;

&lt;p&gt;No, unfortunately not. Many of the novelties depend on something. Whether iOS updated, or device or any other reason.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;WWDC is awesome!&lt;/strong&gt; Able to bring some indescribable feeling to be there, see everything I saw on Apple LiveStream and learn all these new technologies.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AltConf is awesome too!&lt;/strong&gt; Able to introduce you to great programming talents, such as the creator of Alamofire or Fastlane. The good thing about Alt’s talks is that the content is more palpable, the speakers show everyday examples, develop frameworks that make the developer’s life easier &lt;strong&gt;for today.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This year, 2019, I’m going to AltConf again. This time the company was unable to sponsor and I am going on my own at Alt. I particularly liked WWDC, because that is my profile.&lt;br&gt;
I have a great friend who was also in both and he prefers AltConf a thousand times. In 2018 he was even one of the invited speakers.&lt;/p&gt;

&lt;p&gt;The question is simple, participate in both. These are incredible events, but each one has a different focus.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lI56fIYc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/j9rabpnqo8wr6di84cib.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lI56fIYc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/j9rabpnqo8wr6di84cib.JPG" alt="Have fun with your fellas =D"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Never been to any event? Go! You don’t have to go to WWDC (if money and lottery are impediments), just go to AltConf, meet people, feel what it’s like to be with that crowd that week. Worth every penny.&lt;/p&gt;

&lt;h4&gt;
  
  
  PS *: Join the parties and have fun
&lt;/h4&gt;

&lt;p&gt;A hug&lt;/p&gt;

&lt;p&gt;Fabrício Masiero&lt;/p&gt;

</description>
      <category>wwdc</category>
      <category>altconf</category>
      <category>events</category>
      <category>ios</category>
    </item>
    <item>
      <title>How to turn your old app into dark theme based on iOS 13+?</title>
      <dc:creator>Fabrício Masiero</dc:creator>
      <pubDate>Wed, 06 May 2020 19:47:37 +0000</pubDate>
      <link>https://dev.to/fabriciomasiero/how-to-turn-your-old-app-into-dark-theme-based-on-ios-13-1p2i</link>
      <guid>https://dev.to/fabriciomasiero/how-to-turn-your-old-app-into-dark-theme-based-on-ios-13-1p2i</guid>
      <description>&lt;p&gt;My app supports iOS 9 to the latest released by Apple (13) and I would like it to be dark theme and light theme. It's possible?&lt;br&gt;
Searching for WWDC articles I noticed that the way Apple does is using&lt;/p&gt;

&lt;h3&gt;
  
  
  Colors.assets ###
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;PRETTY!&lt;/strong&gt; I created a color asset in the app and started setting it up. But… what I feared came true. Support only for the. iOS 11+. Great Scott!&lt;/p&gt;

&lt;h2&gt;
  
  
  Color Document ##
&lt;/h2&gt;

&lt;p&gt;I had to think of other ways to do something sustainable and work.&lt;br&gt;
Starting with creating an extension called&lt;/p&gt;

&lt;h5&gt;
  
  
  Color.swift
&lt;/h5&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--H3C91vYk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/bhzj0md43s1wtysicue5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--H3C91vYk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/bhzj0md43s1wtysicue5.png" alt="My Color Extension"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Use Color Literal for fuller and more native viewing. All app colors should be there, organized, and standardized 👌. Say goodbye to colorWithHex() 😎 💁&lt;/p&gt;

&lt;p&gt;Wonderful, but how would this work as dark mode? Simple, separate the colors that are dark themed and those that are not. For example, Plurall is my app name and purple is its color, it should not necessarily be dark themed.&lt;/p&gt;

&lt;p&gt;The following is an example of colors that contemplate both theme types (can be scaled for more than that 👨‍💻)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2ppqfTfi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/0t4k4gcyoh0zkyqku4p1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2ppqfTfi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/0t4k4gcyoh0zkyqku4p1.png" alt="Dark Themed Colors"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  But...Why this Colors?
&lt;/h3&gt;

&lt;p&gt;I keep these variables above to the same extent and they are color changeable. The system understands perfectly when to use each one. But where did I get in those dark colors? Why them?&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Well, I'm not officially a designer, I don't have this skill but I venture anyway ☺️.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;But then, what about the dark colors? I used the Inverted Color technique (here a site that will help you invert the color - &lt;a href="https://pinetools.com/invert-color"&gt;Invert Colors&lt;/a&gt;), so I can maintain the same contrast and visualization usability that my app had before Dark Mode, using colors that still talk to each other.&lt;br&gt;
And why does Apple use full-black in its native apps? The high-end iPhones (iPhone X, iPhone XS, and iPhone 11 Pro) contain OLED screen and black is faithful, these screens can uses less battery in black pixels.&lt;/p&gt;

&lt;p&gt;So, this is how I developed this feature for the app that can work from iOS 9. As seen in the code, it still does not work in the past iOS, this is a decision we still have to talk internally, but it is easy to implement this change.&lt;/p&gt;

&lt;p&gt;I think it's time to show how the app is doing, right?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7w2iRjDL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/i1pefgeaufse3bxd472n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7w2iRjDL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/i1pefgeaufse3bxd472n.png" alt="Login Screen(Plurall only works on Brazil, sorry)"&gt;&lt;/a&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WBTjnprK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/7c9hcpchknv98vta5dfi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WBTjnprK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/7c9hcpchknv98vta5dfi.png" alt="Login Screen(Plurall only works on Brazil, sorry)"&gt;&lt;/a&gt;&lt;br&gt;
Login Screen(Plurall only works on Brazil, sorry)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_K4ObFIU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/jdyzycmtr5p3q7c50hsd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_K4ObFIU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/jdyzycmtr5p3q7c50hsd.png" alt="Side menu, I know, need to update this 😑"&gt;&lt;/a&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1AripMqx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/nhn52izcdlrfrd597sfe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1AripMqx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/nhn52izcdlrfrd597sfe.png" alt="Side menu, I know, need to update this 😑"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Side menu, I know, need to update this 😑&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ErgvNqGV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/eaw7yfp9tyiuptidubrz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ErgvNqGV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/eaw7yfp9tyiuptidubrz.png" alt="A Task Workflow(app for students)"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5qMIjaHd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/p0n1gm31y25mrell0fth.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5qMIjaHd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/p0n1gm31y25mrell0fth.png" alt="A Task Workflow(app for students)"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A Task Workflow(app for students)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wewHJDSH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/1phr8u7ub02ubpaaulua.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wewHJDSH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/1phr8u7ub02ubpaaulua.png" alt="Works also in WKWebKit 😎"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--h-XMx_op--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/f76fsd8yft3ntu3pbdy9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--h-XMx_op--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/f76fsd8yft3ntu3pbdy9.png" alt="Works also in WKWebKit 😎"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Works also in WKWebKit 😎&lt;/p&gt;

&lt;p&gt;There is only one "bad" side to this whole story, setting the colors manually 😒.&lt;/p&gt;

&lt;p&gt;If you use XIB or Storyboard (like me) it will be more work, but nothing too painful. If you're one of those who does the whole layout via code, nothing changes for you, champion! Either way, you'll find a lot of it out there!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--C522yoK6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/f72e4zd8g8rnq2q9akxn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--C522yoK6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/f72e4zd8g8rnq2q9akxn.png" alt="Setting colors programmatically"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;From this, I will talk with the design team and see what changes we can make for a better view, I can see some display failures, not respecting the &lt;strong&gt;21: 1&lt;/strong&gt; or even &lt;strong&gt;4.5: 1&lt;/strong&gt; &lt;strong&gt;contrast&lt;/strong&gt;.&lt;br&gt;
Apart from this visual change, what has changed?&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Well, I revisited all the code (it's an old app, a lot of legacy stuff) and put it in my head: - Don't refactor complex things, fix force unwraps and other easy-to-maintain silly things.&lt;br&gt;
So, I tweaked all the app colors (which were a mess,), tweaked small errors from XIBs and Storyboards, removed countless classes that weren't relevant, and again, the app colors are completely organized and visual.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;I hope I have helped everyone looking for this change. &lt;br&gt;
If you would like to extend the discussion, call me on &lt;a href="https://twitter.com/fabri_masiero"&gt;Twitter&lt;/a&gt;&lt;/p&gt;

&lt;h6&gt;
  
  
  Happy Coding :)
&lt;/h6&gt;

</description>
      <category>ios</category>
      <category>darktheme</category>
      <category>swift</category>
      <category>design</category>
    </item>
    <item>
      <title>How to add UIKit component on your SwiftUI project</title>
      <dc:creator>Fabrício Masiero</dc:creator>
      <pubDate>Wed, 06 May 2020 19:32:30 +0000</pubDate>
      <link>https://dev.to/fabriciomasiero/how-to-add-uikit-component-on-your-swiftui-project-257a</link>
      <guid>https://dev.to/fabriciomasiero/how-to-add-uikit-component-on-your-swiftui-project-257a</guid>
      <description>&lt;p&gt;A brief to how to add WKWebView on your SwiftUI view&lt;br&gt;
First of all, there is no WebView component write in SwiftUI, so, how I add this component?&lt;/p&gt;

&lt;p&gt;Yes, we need to add an UIKit component to a SwiftUI view 🤔&lt;br&gt;
Ok, let's build a simple app in SwiftUI.&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%2Fi%2F6ajcdpys2aajfpnn894h.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%2Fi%2F6ajcdpys2aajfpnn894h.png" alt="Creating Project on Xcode"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Xcode auto-generate a Hello World project, it's awesome, because it pretty easy to add WebView now!&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%2Fi%2F60uojemd0wmvhxwkvy1m.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%2Fi%2F60uojemd0wmvhxwkvy1m.png" alt="Initial State"&gt;&lt;/a&gt;&lt;br&gt;
Ok, finally lets work on some code&lt;/p&gt;

&lt;p&gt;We need to create a ViewModel to treat the webview statement.&lt;br&gt;
&lt;/p&gt;

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

public class WebViewViewModel: NSObject {

    private let stringUrl: String
    public let webView: WKWebView

    init(stringUrl: String) {
        self.stringUrl = stringUrl
        self.webView = WKWebView()
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We create a ViewModel called &lt;em&gt;WebViewViewModel&lt;/em&gt; with &lt;strong&gt;url&lt;/strong&gt; and &lt;strong&gt;webview&lt;/strong&gt; initializers. But, why?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;url&lt;/strong&gt; — is a string URL to you web site e.g google.com&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;webview&lt;/strong&gt; — is a WKWebView object to store and control your component&lt;/p&gt;

&lt;p&gt;and after this we need to perform a webview request to load the website, so add this on your ViewModel&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public func request() {
    guard let url = URL(string: stringUrl) else {
        return
    }
    let urlRequest = URLRequest(url: url)
    webView.load(urlRequest)
    if webView.navigationDelegate == nil {
        webView.navigationDelegate = self
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And last but not least add WKNavigationDelegate to your ViewModel&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;extension WebViewViewModel: WKNavigationDelegate {
    public func webView(_ webView: WKWebView, didCommit navigation: WKNavigation!) {

    }
    public func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {

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

&lt;/div&gt;



&lt;p&gt;Our ViewModel is completed! Now we need to add this webview on our SwiftUI view, back to ContentView class and add this &lt;strong&gt;UIViewRepresentable&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;struct WebView: UIViewRepresentable {

    let viewModel: WebViewViewModel

    func makeUIView(context: Context) -&amp;gt; WKWebView {
        return viewModel.webView
    }
    func updateUIView(_ uiView: WKWebView, context: Context) {
        viewModel.request()
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But… Whats is &lt;strong&gt;UIViewRepresentable?&lt;/strong&gt; Basically is a instance to create and menage UIKit components, you can read more &lt;a href="https://developer.apple.com/documentation/swiftui/uiviewrepresentable" rel="noopener noreferrer"&gt;here&lt;/a&gt; and &lt;a href="https://developer.apple.com/documentation/swiftui/uiviewrepresentable/3278050-updateuiview" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Let's understand what that code does. &lt;/p&gt;

&lt;p&gt;The function &lt;strong&gt;makeUIView&lt;/strong&gt; is responsable to return your component.&lt;/p&gt;

&lt;p&gt;The function &lt;strong&gt;updateUIView&lt;/strong&gt; is responsable to tells your app state change.&lt;/p&gt;

&lt;p&gt;Finally, the last thing we need to do is add our webview to our main view, like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;struct ContentView: View {
    var body: some View {
        WebView(viewModel: WebViewViewModel(stringUrl: "https://tinyurl.com/w498z2l"))
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Yes, is simple like that!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/fabriciomasiero/WebViewSwiftUI/tree/master" rel="noopener noreferrer"&gt;You can download the source code here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I hope you enjoyed.&lt;br&gt;
Bye bye =D&lt;/p&gt;

</description>
      <category>swift</category>
      <category>ios</category>
      <category>xcode</category>
      <category>uikit</category>
    </item>
  </channel>
</rss>
