<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Awesa on Medium]]></title>
        <description><![CDATA[Stories by Awesa on Medium]]></description>
        <link>https://medium.com/@atyantaawesa?source=rss-2bf8028e7cda------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*m6ZM7Np84PB8wEYh0Bqe8A.jpeg</url>
            <title>Stories by Awesa on Medium</title>
            <link>https://medium.com/@atyantaawesa?source=rss-2bf8028e7cda------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 23:01:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@atyantaawesa/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Creating a Real-Time Application with Socket.IO]]></title>
            <link>https://medium.com/@atyantaawesa/creating-a-real-time-application-with-socket-io-b87c5cc574b7?source=rss-2bf8028e7cda------2</link>
            <guid isPermaLink="false">https://medium.com/p/b87c5cc574b7</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[socketio]]></category>
            <category><![CDATA[back-end-development]]></category>
            <category><![CDATA[websocket]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Awesa]]></dc:creator>
            <pubDate>Wed, 30 Nov 2022 07:21:51 GMT</pubDate>
            <atom:updated>2022-11-30T08:54:43.508Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Introduction</strong></p><p>Hi! It seems like forever since I posted here. Last time I wrote about my experience of using SwiftUI from the perspective of a web developer, which you can read about <a href="https://medium.com/@atyantaawesa/the-wonders-of-swiftui-my-journey-in-ios-development-so-far-1012537be465">here</a> if you’re interested. In that article, I said that although I had been taking the role of an iOS Developer, I still think of myself as a web developer at heart. This prompted me to try and pursue a back-end developer gig on my next project in the academy. And the good news is, I got it!</p><p><strong>Kobar</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Sff3M9H-7x9GNzkR" /><figcaption>Kobar App</figcaption></figure><p>Meet Kobar, an app that helps high-school students learn programming by competing with their friends to solve programming problems. Some unique features that this app offers are its own programming language, it’s called Gaul-lang, a programming language with Indonesian words as syntax, check it out <a href="https://gaul-lang.up.railway.app/">here</a>, and a real-time battle feature!</p><p>Our app requires a back end that supports real-time two-way communication in order to make our battle feature to work. This is a bit different than the back end that I usually handle, which uses REST API. Instead, I use a technology called WebSocket, which is a full-duplex communication protocol using a TCP connection. This is the technology behind online games, real-time chat, real-time collaborative editing, and many more.</p><p><strong>Demystifying WebSocket</strong></p><p>Let’s demystify WebSocket a bit more. WebSocket uses a TCP connection. TCP or Transmission Control Protocol, is one of the backbone of our modern internet. It essentially defines how data are being exchanged between devices. Many other protocols rely on TCP to work, namely HTTP and FTP. REST API relies on HTTP, which can be illustrated with this diagram.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/792/0*ZKLVKK_L1VoAwh65" /><figcaption>HTTP Request-Response Diagram</figcaption></figure><p>As you can see, normally server can only send data back after the client had requested it in the first place. But on Kobar’s battles, you will get notified when your opponent does something, for example if you joined the battle, the opponent will get notified that a new player has joined the room, or when your opponent submitted their code, you will get notified that they’ve finished the problem. Take a look at this diagram for example on how our application talks to the server during the battle.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/735/0*nyt9joVxO_tZRuE9" /><figcaption>Kobar’s Battle Feature Diagram</figcaption></figure><p>As you can see, data and events can be sent to the client from the server without the client requesting it. So, a normal REST API over HTTP wouldn’t work in this case. That’s why I opted to use WebSocket, which is a full-duplex communication protocol, meaning that it can handle a two-way communication in real-time. Take a look at this diagram of how WebSocket works.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/789/0*R2Ba2Jf-kTZ7ykAB" /><figcaption>WebSocket Connection Diagram</figcaption></figure><p>The initial request is still sent using HTTP, which contains a request to upgrade the connection to ws or WebSocket. After that, the server will validate the upgrade request and if it approves it, it will send a 101 code for switching protocol from http to ws. The connection will stay open and allows both sides (client and server) to send data to each other. The connection will only close when one side explicitly closes their channel.</p><p>This protocol is suitable for our needs since it allows the server to send data and events to the client without them having to request it first. For example, when a user submitted their code, they will send the data to the server over WebSocket, the server then receives this and send an event to the user’s opponent notifying that the user had submitted their code.</p><p>Another example of how WebSocket is used is on chat applications like Line, WhatsApp, or Telegram. When your friend sends you a message, you will get notified and get the message that they sent without you having to request it first. Your app will always be ready to listen to incoming messages.</p><p><strong>Socket.IO</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*HwQRH6J6EeE0S2IL" /><figcaption>Socket.IO Logo</figcaption></figure><p>It’s clear after the design process that WebSocket is the way to go for our application. To make its implementation simpler, I opted to use a library called Socket.IO. Socket.IO describes itself as a bidirectional and low-latency communication for every platform. It is built on top of the aforementioned WebSocket protocol, but in the rare case that it fails, it will fallback to other technology that supports two-way communication like HTTP long-polling or automatic reconnection.</p><p>A few reasons on why I choose Socket.IO to implement WebSocket for Kobar are;</p><ul><li>It is widely used and adopted by the tech community, so support and resources will not be hard to find.</li><li>Supports many platforms and languages, in Kobar’s case, it supports both Node.js that we used on the server as well as Swift which is used on the client.</li><li>Finally, it supported rooms. Room is an arbitrary channel that sockets (think of it as the client in this case for simplicity) can join and leave. It can be used to broadcast events to a subset of clients. So for example if a user wants to battle with their friend, both of them will join a room. We can have an unlimited number of rooms opened at the same time and the users inside each room will not interact with other users from a different room, isolating them completely. This is how I implemented the battles on Kobar, each battle is essentially a room which two users can join and leave.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/688/0*W6_I8e07FhSBYKP4" /><figcaption>Socket.IO Rooms Illustration</figcaption></figure><p><strong>Example</strong></p><p>Let me show you a little example of how to create an back-end to handle real-time communication. I will use a chat application as an example.</p><p>I will use Express as my framework, but as stated before, Socket.IO supports many frameworks and programming languages.</p><p>First of all, we’ll create a basic Express app.</p><pre>import express from &quot;express&quot;;<br>import { Server } from &quot;http&quot;;<br>import { Server as SocketIO } from &quot;socket.io&quot;;<br><br>const app = express();<br>const http = Server(app);<br>const io = new SocketIO(http);<br>const port = process.env.PORT || 3000;<br><br>http.listen(port, () =&gt; {<br>  console.log(`Socket.IO server is running at http://localhost:${port}/`);<br>});</pre><p>After that, we can define the behavior of our app when a client connects to our back end using WebSocket.</p><pre>io.on(&quot;connection&quot;, (socket) =&gt; {<br>  socket.broadcast.emit(&quot;userJoined&quot;, {<br>    message: &quot;A new user has joined the chat!&quot;,<br>   });<br>});</pre><p>The connection event will be called when a new socket connection is established. In this particular example, we will broadcast an event of userJoined with the data of an object containing the message “A new user has joined the chat!”. This will be sent to every client that is connected to our back end except for the new user itself (since we use broadcast), so they will get notified when a new user joined the chat.</p><p>Next, we will handle the message being sent itself.</p><pre>socket.on(&quot;sendMessage&quot;, (messageContent) =&gt; {<br>  socket.emit(&quot;messageSent&quot;);<br><br>  socket.broadcast.emit(&quot;messageIncoming&quot;, {<br>    sender: socket.id,<br>    message: messageContent,<br>  });<br>});</pre><p>Here, the server will listen to a sendMessage event from the client, which also requires a messageContent. If a client emit this event to the server, the server will emit a messageSent event back to the client which sends the message in the first place using socket.emit. After that the server will emit a broadcast to all of the other clients connected (excluding the sender itself) a messageIncoming event which includes an object containing the sender’s socket id and the message content.</p><p>In the example above, there will be a single room where everybody will be able to send and receive messages. If we want to implement a private chat feature, we can utilize Socket.IO rooms.</p><pre>io.on(&quot;connection&quot;, (socket) =&gt; {<br>  <br>  socket.on(&quot;joinRoom&quot;, (roomCode) =&gt; {<br>    socket.join(roomCode);<br><br>    socket.to(roomCode).emit(&quot;userJoined&quot;, {<br>      message: `${socket.id} has joined the chat!`,<br>     });<br>  };<br>  <br>  socket.on(&quot;sendMessage&quot;, (roomCode, messageContent) =&gt; {<br>    socket.emit(&quot;messageSent&quot;);<br><br>    socket.to(roomCode).emit(&quot;messageIncoming&quot;, {<br>      sender: socket.id,<br>      message: messageContent,<br>    });<br>  });<br><br>});</pre><p>Now, the client need to emit a joinRoom event with the roomCode before they can start chatting. When sending messages, they also have to specify the roomCode. The message emitted to the room will only be able to be seen by the users that have joined the room. The roomCode in this case will be any valid string, you can implement a validator using middleware if you want but it’s not necessary to do so. Users that joined the room with the same code will be put in the same room.</p><p>So that’s a very simplified overview of how I created a real-time application using Socket.IO, if you are interested on the codes you can visit Kobar’s repo <a href="https://github.com/deXOR0/kobar-server">here</a>.</p><p>Before we part ways, I’d like to give a shout out to my awesome team that helps to bring Kobar to life.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*puT2wEYbYhvw9ltN" /><figcaption>The Kobar Team</figcaption></figure><p>If you want to give Kobar a try, feel free to download it from <a href="https://testflight.apple.com/join/Sm1qmlsO">TestFlight</a>!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_vmuJvHWWI9ASt3Q" /><figcaption>Kobar App on TestFlight</figcaption></figure><p>With that being said, I hoped that you guys enjoyed this little article, and learn something from it. I would love to hear your thoughts on the topic of WebSocket or back end development in general.</p><p>Until next time!</p><p>-Awesa</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b87c5cc574b7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Wonders of SwiftUI: My journey in iOS development, so far]]></title>
            <link>https://medium.com/@atyantaawesa/the-wonders-of-swiftui-my-journey-in-ios-development-so-far-1012537be465?source=rss-2bf8028e7cda------2</link>
            <guid isPermaLink="false">https://medium.com/p/1012537be465</guid>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[apple]]></category>
            <category><![CDATA[ios-developer]]></category>
            <category><![CDATA[ios-development]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Awesa]]></dc:creator>
            <pubDate>Fri, 05 Aug 2022 04:34:49 GMT</pubDate>
            <atom:updated>2022-08-07T17:10:30.170Z</atom:updated>
            <content:encoded><![CDATA[<p>Before we begin, let me preface this by saying that I’m by no means an expert in any of the topics I will be discussing in this article. Think of this as more of a guy-telling-his-friends-about-his-coding-journey rather than a follow-along tutorial or even worse, a guide. With that being said, let’s get started!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*04EMPmhk8LzDaUV8SstVeg.png" /><figcaption>My team in the academy</figcaption></figure><h4>Introduction</h4><p>First things first, let me introduce myself. My name is Awesa, I’m currently participating in the Apple Developer Academy program as an iOS developer. Apple Developer Academy is a great place to learn a great deal about iOS development, product management, design, and many more. One of the things that I learned is SwiftUI and in this article, I want to share a little about it. But to understand and appreciate it more properly, let’s take a trip of my learning journey in iOS development with Apple Developer Academy.</p><h4>Starting iOS Development &amp; UIKit</h4><p>I started the academy in March 2022. The academy program is broken down into challenges, so far I’ve completed four challenges. Through these 4 challenges, I’ve always taken the role of an iOS developer. But to tell you the truth, I never thought of myself as an iOS developer. I have always identified as a web developer, even now after about 6 months in the academy. I came from a background in back-end development with some front-end sprinkled here and there, and never even touched iOS development before the academy. So it’s safe to say that I’m much more comfortable working with HTML, JavaScript, and CSS rather than auto layout and custom table view cells.</p><p>It also probably doesn’t help that my introduction to iOS development is through UIKit. Don’t get me wrong, UIKit is a powerful tool, and you can do so much with it. But to say that it doesn’t resemble web development, boy, is that an understatement (at least in my opinion). In the beginning, it was all good in UIKit town, I was even stoked to discover that I can just drag and drop stuff into the storyboard and got myself a decent-looking app, just like that. But that was before I discovered the dreaded auto layout. Let me tell you a little secret, I didn’t even bother with the auto layout for my first two apps in the academy. We have very limited time constraints and many features to implement so I had always prioritized functionality over best practices (horrifying, I know).</p><p>So for my first two apps, I dragged and dropped all the components into the storyboard and call it a day, I knew that the app will look all over the place if I run it on another generation of devices, but it was a limitation that I was willing to take, in my mind I thought, “I can make the UI looks decent without auto layout on a specific device, so I’ll just run it there, at least it works”. But I understand that if I ever want to get serious in iOS development, I have to learn auto layout and deal with it eventually.</p><p>Approaching the third challenge, I learned that a lot of companies use what’s called UIKit programmatically. I read about it and basically, I discovered that people just abandon the storyboard completely and do everything in code. To set the layout and placement of the components, you need to utilize the auto layout. There’s that, I can’t get around it anymore. Around the same time, I begin to hear about this new thing called SwiftUI. At first, it wasn’t something that piqued my interest and shrug it off as another quirky feature that I’ll get to at some point like the auto layout before. Some of my friends pitched the idea to use SwiftUI instead of UIKit and tell me all of its advantages when compared to UIKit. But I, being as stubborn as ever, decided to keep using UIKit for the next app. My thinking was, that I just got comfortable enough to use UIKit, and decided that this was the time that I’m going to learn the auto layout for real.</p><h4>UIKit can get complicated really quickly</h4><p>So the team moved on and agreed to use UIKit for the third challenge. For the third challenge, our main feature revolves around a chat view, like the ones you find on WhatsApp or other chatting apps. We never built a chat view before, but our mentors urged us to try to build it ourselves from the ground up as opposed to using a third-party library. This is what it should look like.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/739/0*YU2pbTsm4ept2eGa" /><figcaption>Chat view feature</figcaption></figure><p>Given that it was our main feature, we decided to put a lot of focus into it. We even assign a coder just to specifically handle that feature and nothing else. Luckily, we had an amazing coder on our team (shout out to Salman!), he managed to get a working prototype in a couple of days and moved on to build all the different chat bubble types inside it. In the end, this is what he came up with. For context, in addition to regular chat, there are also activity chat bubbles that allow the user to pick options on the chat bubble.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*YAOF23vTofz18Ff6" /><figcaption>Chat messaging system courtesy of Salman</figcaption></figure><p>You can see that it gets pretty complicated really quickly. There are multiple different types of table view cells, which houses option views, etc. Even with our very talented coder tackling the problem, there are still some bugs that persist and remained unsolved.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/739/0*C5isnQjUM88hoDIa" /><figcaption>The stack view inside is cut-off and can’t be scrolled</figcaption></figure><p>All and all the development of the chat feature probably takes more than two weeks in total. There are a lot of different things and edge cases that we need to take care of. Of course, at the time, we don’t really have much choice other than keep pushing through all the hurdles.</p><h4>The Fourth Challenge, Code Bud, and SwiftUI</h4><p>So the third challenge came and went, and I arrived at the fourth challenge. Every challenge has its own theme, for example, the second challenge’s theme was “organize”. The fourth challenge was “how to improve your learning in the academy”. For this, I decided to make a coding session management app, which lets you set up your coding session and break time, gives you a timer, tracks your session, and reminds you when you should take a break or end the session. I decided on this app because I have this problem where I really got into a coding session and literally forgot to take a break. This happens quite a few times and it’s a major problem for me, but it’s a story for another time. For now, if you’re interested, you can check it out <a href="https://github.com/deXOR0/apple-nano-challenge-2">here</a>, it’s called Code Bud and it’s pretty cool 😎</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dbg1xPLV3VXtuDGrkpNApA.png" /><figcaption>Code Bud: Manage your coding sessions, built by yours truly</figcaption></figure><p>In addition to this, another requirement was to build it with SwiftUI. I’ve been reluctant to learn the framework and had put it off for a while, but now it’s forced upon me. But to be honest, I’m grateful that it happened because let me tell you, SwiftUI is <strong>AMAZING</strong>.</p><h4>SwiftUI vs UIKit</h4><p>I’ve said that my background is in web development, and I’m somewhat familiar with modern front-end frameworks like React. In my opinion, coding in SwiftUI is very similar in concept to React and other web frameworks, so I really feel at home with it.</p><p>For starters, you can set up a State variable, and use it to store a value that will be displayed by the UI. If the value ever changes, the UI will automatically update the value that it displays as well. Sounds familiar? Yes, this is basically like using the useState hook in React.</p><p>Next, is the layout itself. My brain is in tune with how to lay out stuff with HTML and CSS. So when I see a mockup or design, my first thought is to break it down into divs, and divs, and divs, and divs. But in UIKit, it’s a little different. Generally, when I see a layout in UIKit, I will have to think in terms of components. Take for example this design.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/390/0*pGjJPAkk5ksSwIwO" /><figcaption>Story detail view from the Compy app</figcaption></figure><p>Automatically, my brain will break this down with divs in mind. So it becomes like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/390/0*erhcYumfPxsSaSRW" /><figcaption>Everyday is div day</figcaption></figure><p>All of those boxes are divs if it’s not clear enough. What’s inside the divs? I don’t really care about it yet, since I know that everything inside it will follow the div’s convention, and at the very least, we can make the basic layout first. But in UIKit, it’s not that simple. It’s probably more like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/390/0*hxu-TklDZLLTsMMy" /><figcaption>UIKit and the joy of auto layout</figcaption></figure><p>Wait, that’s the components! You’re right, in UIKit, I usually just put the components in without an enclosing “thing” housing every component. Technically, I can utilize UIView for this but it’s not a straightforward process and requires me to do further setup before using it to help lay out my stuff. So how do we set the layout? Well with the auto layout, of course. So in this example, I have to set up the auto layout for every single component, to tell it how to interact with other components surrounding it. Which takes a lot of time. Think of it as layouting your website with just the help of paddings and margins. It gets old really quickly.</p><p>So how do we do it in SwiftUI? It looks something like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/390/0*dkaARCw0ohlHUgnc" /><figcaption>Stacks to the rescue!</figcaption></figure><p>Stacks for the win! You can think of stacks like divs, but even better. On the web, a div usually fills the entire view width, so if you have two divs, it will usually be placed one above the other. You can change this behavior with z-index, flex, or other CSS tricks. But in SwiftUI, you have 3 kinds of stacks, VStacks, to put things vertically, like how a normal div works, HStack to put things horizontally, and ZStack to put things on top of each other. Every component, including stacks that you put inside a stack, will follow its convention. Another useful thing is the spacer, which will automatically fill all of the unused space. If you put a spacer on top of your component, it will fill the entire unused space on top of your component and push your component down, and so on and so forth. With this, layouting in SwiftUI becomes very easy and intuitive. And did I tell you, you don’t need to bother with the auto layout? Everything just works, for all devices. You just need to set the paddings and spacers, and you’re set.</p><p>One more useful thing that you can do to make your life even easier in SwiftUI is to utilize the MVVM pattern, but it’s also a story for another day. But the gist is, it’s easier and faster to develop your app with SwiftUI, for the most part. There’s a very good video by Paul Hudson of him building two identical apps with SwiftUI and UIKit, when compared, he managed to build the SwiftUI app a lot faster and with fewer lines of code. You can watch the video here.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fqk2y-TiLDZo%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dqk2y-TiLDZo&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fqk2y-TiLDZo%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/b51e8d0cdabb0a1787e945a192a87955/href">https://medium.com/media/b51e8d0cdabb0a1787e945a192a87955/href</a></iframe><p>Remember the chat view from my second challenge? I managed to replicate the basics and get it working in just a couple of minutes with a List, Stacks, and Spacers.</p><h4>SwiftUI Limitations</h4><p>Of course, SwiftUI is not perfect. It does have its own limitations. For example, one annoying thing that I found is it doesn’t support multi-component picker out of the box, and I have to build it myself, although it is very easy to set up on UIKit. Another even bigger point is that SwiftUI is a new framework, Apple only just introduced it on 2019. So the framework hasn’t matured as much as UIKit, and the adoption is still fairly limited in production. If you’re planning on working professionally as an iOS developer right now, I wouldn’t let go of UIKit just yet.</p><p>With that being said, I hoped that you guys enjoyed this little article, and learn something from it. I would love to hear your thoughts on the topic of SwiftUI vs UIKit, or even iOS development in general.</p><p>Until next time!</p><p>-Awesa</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1012537be465" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>