<?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: João Matheus</title>
    <description>The latest articles on DEV Community by João Matheus (@joaomatheus).</description>
    <link>https://dev.to/joaomatheus</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%2F1229035%2F06034956-223e-4691-b0ff-5e037a576ed2.png</url>
      <title>DEV Community: João Matheus</title>
      <link>https://dev.to/joaomatheus</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/joaomatheus"/>
    <language>en</language>
    <item>
      <title>Advanced Encryption Standard with Swift</title>
      <dc:creator>João Matheus</dc:creator>
      <pubDate>Sun, 24 Dec 2023 13:43:08 +0000</pubDate>
      <link>https://dev.to/joaomatheus/advanced-encryption-standard-with-swift-26l9</link>
      <guid>https://dev.to/joaomatheus/advanced-encryption-standard-with-swift-26l9</guid>
      <description>&lt;p&gt;This blog I show my way of how to Advanced Encryption Standard with Swift Language.&lt;/p&gt;

&lt;p&gt;I will use framework &lt;strong&gt;CryptoKit&lt;/strong&gt; and your resource AES.&lt;/p&gt;

&lt;p&gt;To perform the cryptography is necessary a key and message.&lt;/p&gt;

&lt;p&gt;I use message "AES Cryptography" and aleatory key that received by &lt;strong&gt;SymmetricKey&lt;/strong&gt; of bits 256.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2X98K_ht--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/05v3dhi74wmtkxjkh9pe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2X98K_ht--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/05v3dhi74wmtkxjkh9pe.png" alt='let key = SymmetricKey(size: .bits256)&amp;lt;br&amp;gt;
let message = "AES Cryptography".data(using: .utf8)!&amp;lt;br&amp;gt;
let sealedBox = try! AES.GCM.seal(message, using: key)&amp;lt;br&amp;gt;
print(sealedBox.combined?.base64EncodedString() ?? "")&amp;lt;br&amp;gt;
let decryptedData = try? AES.GCM.open(sealedBox, using: key)&amp;lt;br&amp;gt;
print(String(data: decryptedData ?? Data(), encoding: .utf8) ?? "")' width="516" height="132"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, whats happening in this code?&lt;/p&gt;

&lt;p&gt;Firstly, created a aleatory key using &lt;a href="https://developer.apple.com/documentation/cryptokit/symmetrickey#overview"&gt;SymmetricKey&lt;/a&gt; and defines the message data that we want encrypt.&lt;/p&gt;

&lt;p&gt;And next, use &lt;a href="https://developer.apple.com/documentation/cryptokit/aes/gcm"&gt;AES.GCM&lt;/a&gt; to storaged in &lt;a href="https://developer.apple.com/documentation/cryptokit/aes/gcm/sealedbox"&gt;SealedBox&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Right, your message has encrypt!&lt;/p&gt;

&lt;p&gt;To decrypt this message, use AES.GCM.open passing your sealedBox and key. &lt;/p&gt;

&lt;p&gt;Case need encrypt message with definitive key, change .init of SymmetricKey for this:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;let key = SymmetricKey(data: "{YOUR_KEY}".data(using: .utf8)!)&lt;/code&gt;&lt;/p&gt;

</description>
      <category>swift</category>
      <category>mobile</category>
      <category>security</category>
    </item>
    <item>
      <title>UIScrollView com View Code / PT-BR</title>
      <dc:creator>João Matheus</dc:creator>
      <pubDate>Sat, 09 Dec 2023 14:39:06 +0000</pubDate>
      <link>https://dev.to/joaomatheus/componente-uiscrollview-com-view-code-pt-br-5g52</link>
      <guid>https://dev.to/joaomatheus/componente-uiscrollview-com-view-code-pt-br-5g52</guid>
      <description>&lt;p&gt;Quando iniciei com desenvolvimento iOS quebrei bastante a cabeça para entender como fazer a UISrollView funcionar. Neste blog vou mostrar como faço o uso da UISrollView via View Code.&lt;/p&gt;

&lt;p&gt;Para começar crie um componente UIScrollView e adicione a sua View Controller e configure as constraints&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;lazy var scrollView: UIScrollView = {
    let element = UIScrollView()
    element.translatesAutoresizingMaskIntoConstraints = false
    element.backgroundColor = .yellow
    return element
}()

override func viewDidLoad() {
    super.viewDidLoad()
    view.addSubview(scrollView)

    NSLayoutConstraint.activate([
        scrollView.topAnchor.constraint(equalTo: view.topAnchor),
        scrollView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
        scrollView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
        scrollView.bottomAnchor.constraint(equalTo: view.bottomAnchor)
    ])
}

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

&lt;/div&gt;



&lt;p&gt;Até aqui, se executar a sua &lt;strong&gt;scrollView&lt;/strong&gt; vai aparecer na tela.&lt;/p&gt;

&lt;p&gt;Comece o processo de adicionar elementos na &lt;strong&gt;scrollView&lt;/strong&gt;. Crie uma view qualquer&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;lazy var anyView: UIView = {
    let element = UIView()
    element.translatesAutoresizingMaskIntoConstraints = false
    element.backgroundColor = .red
    return element
}()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Na função viewDidLoad, adicione a &lt;strong&gt;anyView&lt;/strong&gt; na &lt;strong&gt;scrollView&lt;/strong&gt; e configure as devidas constraints&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;scrollView.addSubview(anyView)
NSLayoutConstraint.activate([
    anyView.topAnchor.constraint(equalTo: scrollView.topAnchor, constant: 100),
    anyView.leadingAnchor.constraint(equalTo: scrollView.leadingAnchor),
    anyView.trailingAnchor.constraint(equalTo: scrollView.trailingAnchor),
    anyView.heightAnchor.constraint(equalToConstant: 100),
    anyView.widthAnchor.constraint(equalToConstant: 300),
    anyView.bottomAnchor.constraint(equalTo: scrollView.bottomAnchor, constant: -40)
])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Sua anyView deve ficar amostra na tela agora. Porém note que eu tive que configurar as constraints &lt;strong&gt;heightAnchor&lt;/strong&gt; e &lt;strong&gt;widhtAnchor&lt;/strong&gt; para que seja exibida na tela. Experimente comentar uma dessas constraints e verá que a &lt;strong&gt;anyView&lt;/strong&gt; não será exibida.&lt;/p&gt;

&lt;p&gt;Isso acontece porque a &lt;strong&gt;scrollView&lt;/strong&gt; precisa saber a altura e largura de seus componentes para permitir o correto cálculo de deslocamento.&lt;/p&gt;

&lt;p&gt;Ou seja, para cada novo componente, temos que fazer esse processo. Porém podemos minimizar isso criando uma outra view que terá o papel de obter a largura e também compor as views da &lt;strong&gt;scrollView&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Comece criando a nova view em seguida na função &lt;strong&gt;viewDidLoad&lt;/strong&gt; adicione na &lt;strong&gt;scrollView&lt;/strong&gt; e configure suas constraints&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;lazy var viewHandler: UIView = {
    let element = UIView()
    element.translatesAutoresizingMaskIntoConstraints = false
    element.backgroundColor = .green
    return element
}()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;scrollView.addSubview(viewHandler)
NSLayoutConstraint.activate([
    viewHandler.topAnchor.constraint(equalTo: scrollView.topAnchor),
    viewHandler.leadingAnchor.constraint(equalTo: scrollView.leadingAnchor),
    viewHandler.trailingAnchor.constraint(equalTo: scrollView.trailingAnchor),
    viewHandler.bottomAnchor.constraint(equalTo: scrollView.bottomAnchor),
    viewHandler.widthAnchor.constraint(equalTo: scrollView.widthAnchor)
])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Dessa forma já estamos informando para nossa &lt;strong&gt;scrollView&lt;/strong&gt; qual a largura do conteúdo.&lt;br&gt;
Se executar o projeto vai perceber que a &lt;strong&gt;viewHandler&lt;/strong&gt; não aparece na tela, isso acontece porque a &lt;strong&gt;scrollView&lt;/strong&gt; desconhece a altura da &lt;strong&gt;viewHandler&lt;/strong&gt;. Para resolver esse obstáculo vamos utilizar a &lt;strong&gt;anyView&lt;/strong&gt;.&lt;br&gt;
Mais acima adicionamos a &lt;strong&gt;anyView&lt;/strong&gt; na &lt;strong&gt;scrollView&lt;/strong&gt;, altere para &lt;strong&gt;viewHandler&lt;/strong&gt; e reconfigure as constraints&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;viewHandler.addSubview(anyView)
NSLayoutConstraint.activate([
    anyView.topAnchor.constraint(equalTo: viewHandler.topAnchor, constant: 100),
    anyView.leadingAnchor.constraint(equalTo: viewHandler.leadingAnchor),
    anyView.trailingAnchor.constraint(equalTo: viewHandler.trailingAnchor),
    anyView.heightAnchor.constraint(equalToConstant: 1000),
    anyView.bottomAnchor.constraint(equalTo: viewHandler.bottomAnchor, constant: -40)
])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Sem o uso de &lt;strong&gt;widhtAnchor&lt;/strong&gt; na &lt;strong&gt;anyView&lt;/strong&gt; e o PRINCIPAL, conectando o &lt;strong&gt;bottomAnchor&lt;/strong&gt; com a nossa &lt;strong&gt;viewHandler&lt;/strong&gt;, dessa forma a &lt;strong&gt;scrollView&lt;/strong&gt; consegue obter a altura.&lt;/p&gt;

&lt;p&gt;Ao executar poderá ver sua &lt;strong&gt;anyView&lt;/strong&gt; e o scroll funcionando devidamente.&lt;/p&gt;

&lt;p&gt;Na adição de um novo componente, o último elemento da &lt;strong&gt;viewHandler&lt;/strong&gt;(de cima para baixo) é quem deve apontar o bottomAnchor para &lt;strong&gt;viewHandler.bottomAnchor&lt;/strong&gt;, assim a &lt;strong&gt;scrollView&lt;/strong&gt; vai continuar a pegar a altura correta.&lt;/p&gt;

&lt;p&gt;Ficou em dúvida? Viu algum ponto de melhoria? Fique a vontade para comentar! :)&lt;/p&gt;

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