<?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 Anang Nugraha on Medium]]></title>
        <description><![CDATA[Stories by Anang Nugraha on Medium]]></description>
        <link>https://medium.com/@anangnugraha?source=rss-c180321b19fc------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*jNdTdS83ObXg09xJ_63lrg.png</url>
            <title>Stories by Anang Nugraha on Medium</title>
            <link>https://medium.com/@anangnugraha?source=rss-c180321b19fc------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 13:35:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@anangnugraha/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[Mobile Development in 2025: Cross-Platform vs. Native]]></title>
            <link>https://anangnugraha.medium.com/mobile-development-in-2025-cross-platform-vs-native-20ad528eee8b?source=rss-c180321b19fc------2</link>
            <guid isPermaLink="false">https://medium.com/p/20ad528eee8b</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[mobile-development]]></category>
            <dc:creator><![CDATA[Anang Nugraha]]></dc:creator>
            <pubDate>Fri, 28 Feb 2025 08:08:34 GMT</pubDate>
            <atom:updated>2025-02-28T08:08:34.611Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cnxEw5Dq82dgkRV5" /><figcaption>Photo by <a href="https://unsplash.com/@balazsketyi?utm_source=medium&amp;utm_medium=referral">Balázs Kétyi</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Mobile development is constantly evolving, and developers must choose the best approach to stay competitive. As we enter 2025, the debate between cross-platform and native development continues. This article explores the key factors developers should consider when selecting a technology stack, weighing the pros and cons of each approach.</p><h3>What is Native Development?</h3><p>Native development means building mobile applications specifically for one platform — iOS or Android — using platform-specific languages. Swift or Objective-C is used for iOS, while Kotlin or Java is common for Android.</p><h3>Advantages of Native Development</h3><h4>Full Access to Device Features</h4><p>Native development provides direct access to all hardware and software features, including sensors like the gyroscope and accelerometer.</p><h4>Optimal Performance</h4><p>Because native apps use platform-specific languages, they can fully utilize device capabilities, making them faster and more efficient — especially for gaming and high-performance applications.</p><h4>Stability and Reliability</h4><p>Native apps tend to be more stable as they do not rely on additional frameworks or middle layers, reducing the likelihood of bugs and crashes.</p><h3>Disadvantages of Native Development</h3><h4>Higher Costs</h4><p>Developing separate codebases for iOS and Android requires more resources, increasing both development and maintenance costs.</p><h4>Longer Development Time</h4><p>Since each platform requires its own codebase, implementing features takes longer, delaying app releases.</p><h3>What is Cross-Platform Development?</h3><p>Cross-platform development allows developers to write one codebase that runs on both iOS and Android. Popular frameworks include Flutter, React Native, and .NET MAUI.</p><h3>Advantages of Cross-Platform Development</h3><h4>Single Codebase</h4><p>A single codebase simplifies maintenance, reduces costs, and speeds up development.</p><h4>Cost-Effective</h4><p>Since only one team is needed for both platforms, project costs decrease, making it an attractive option for startups and budget-conscious businesses.</p><h4>Faster Updates</h4><p>Changes and bug fixes can be deployed to both platforms simultaneously, improving efficiency.</p><h3>Disadvantages of Cross-Platform Development</h3><h4>Performance Issues</h4><p>An additional abstraction layer can slow performance, making cross-platform apps less efficient than native ones.</p><h4>Limited Access to Device Features</h4><p>Some platform-specific features may not be available or require additional plugins, increasing complexity.</p><h4>Framework Dependency</h4><p>Developers must rely on framework updates. If the framework is discontinued, as with Xamarin, apps may face stability issues.</p><h3>Case Study: Native vs. Cross-Platform Decision</h3><p>A company using Xamarin struggled with bugs and performance issues when Microsoft ended its support. Since 80% of their users were on iOS, they decided to rebuild their app using native iOS development, ensuring stability and long-term viability.</p><h3>Key Factors in Choosing an Approach</h3><h4>User Base</h4><p>If most users are on one platform, focusing on native development may be more effective.</p><h4>App Requirements</h4><p>Apps that rely on device-specific features or high performance should use native development.</p><h4>Budget and Timeline</h4><p>Cross-platform development is ideal for companies with limited budgets and the need for a faster time-to-market.</p><h4>Long-Term Strategy</h4><p>The chosen technology should be future-proof, considering potential framework discontinuation.</p><h3>The Role of Cross-Platform Development in 2025</h3><p>As frameworks like Flutter and React Native mature, they are becoming more competitive with native development. Progressive Web Apps (PWAs) also offer additional flexibility.</p><h4>The Hybrid Approach</h4><p>Some developers use a hybrid model — cross-platform for general features and native code for performance-critical components.</p><h3>Conclusion</h3><p>In 2025, choosing between native and cross-platform development depends on business needs, budget, and technical requirements. Cross-platform is ideal for fast development and cost savings, while native is best for high-performance applications. The key is to stay flexible and adapt to technological advancements to ensure long-term success in mobile development.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=20ad528eee8b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Step-by-Step Guide to Becoming an Mobile Developer.]]></title>
            <link>https://anangnugraha.medium.com/a-step-by-step-guide-to-becoming-an-mobile-developer-e0c724580a0d?source=rss-c180321b19fc------2</link>
            <guid isPermaLink="false">https://medium.com/p/e0c724580a0d</guid>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Anang Nugraha]]></dc:creator>
            <pubDate>Wed, 26 Feb 2025 11:10:38 GMT</pubDate>
            <atom:updated>2025-02-26T11:10:38.523Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*YYHjZy7yQMcUr5_y" /><figcaption>Photo by <a href="https://unsplash.com/@lazizli?utm_source=medium&amp;utm_medium=referral">Lala Azizli</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>If you’re considering embarking on a journey to become a mobile app developer, you’re in good company. Mobile app development is a rapidly growing field, offering numerous opportunities for creativity, problem-solving, and financial rewards. In this guide, we’ll explore the various paths to becoming a mobile app developer, the essential skills you’ll need, the pros and cons of each learning method, and actionable steps to kickstart your career.</p><p><strong>Understanding the Role of a Mobile App Developer</strong></p><p>Mobile app developers create applications for platforms like Android and iOS. Typically, developers specialize in one platform to become an expert, but those who master cross-platform technologies like React Native or Flutter have a competitive edge. Mobile app developers can work for large corporations, small businesses, as freelancers, or as indie developers publishing their apps.</p><p><strong>Career Paths for Mobile App Developers</strong></p><p>There are three primary paths to consider as an aspiring mobile app developer:</p><p><strong>1. Working for a Company</strong></p><p>As a company-employed mobile app developer, your tasks might include maintaining existing apps, building new features, fixing bugs, and testing. This role could range from creating new apps to adding features to existing ones or handling multiple tasks in a smaller business.</p><p><strong>2. Freelancing</strong></p><p>Freelancing allows you to meet clients, understand their needs, plan, and deliver apps from start to finish. As you gain experience, you may handle multiple clients simultaneously and even hire other developers to grow a consulting firm.</p><p><strong>3. Indie App Development</strong></p><p>Indie developers create, market, and publish their apps, aiming to earn a full-time living through the App Store or Play Store. This path offers creative freedom but comes with the highest risk, as success hinges on the market’s reception of your app.</p><p><strong>Education and Skill Development</strong></p><p><strong>1. Self-Taught Learning</strong></p><p>Self-teaching is a viable option thanks to various online resources such as videos, books, and courses. This method allows you to learn at your own pace and is often more affordable. However, it requires discipline and may lead to potential pitfalls without guidance.</p><p><strong>Pros:</strong></p><p>• Flexible learning schedule</p><p>• Variety of learning formats</p><p>• Low cost</p><p><strong>Cons:</strong></p><p>• Lack of immediate guidance</p><p>• Requires strong self-discipline</p><p><strong>2. University Programs</strong></p><p>Attending a university provides structure, professional instruction, and recognized certifications. This path can be costly and time-consuming but may offer a more comprehensive education.</p><p><strong>Pros:</strong></p><p>• Accredited certification</p><p>• Structured learning with deadlines</p><p>• Professional instruction</p><p><strong>Cons:</strong></p><p>• High cost</p><p>• Significant time commitment</p><p>• Potential travel or relocation expenses</p><p><strong>3. Coding Bootcamps</strong></p><p>Coding bootcamps provide an intensive, short-term learning experience. These programs balance structure with flexibility and are suited for individuals looking for a faster route into the industry.</p><p><strong>Pros:</strong></p><p>• Shorter duration than traditional programs</p><p>• Intensive, focused learning</p><p>• Opportunity for peer learning</p><p><strong>Cons:</strong></p><p>• Can still be costly</p><p>• Demanding schedule</p><p>•Quality can vary between bootcamps</p><p><strong>Essential Skills for Mobile App Development</strong></p><p><strong>iOS Development Skills</strong></p><p>If you choose to focus on iOS development, you’ll need to learn Swift, a modern and easy-to-read programming language. You’ll also need to familiarize yourself with SwiftUI for user interface design and Xcode, the development environment for building apps.</p><p><strong>Android Development Skills</strong></p><p>For Android development, you’ll need to learn Java or Kotlin, alongside understanding Android Studio, the corresponding development environment.</p><p><strong>Key Skills Across Platforms</strong></p><p>• Programming languages (Swift for iOS, Java/Kotlin for Android)</p><p>• Development environments (Xcode for iOS, Android Studio for Android)</p><p>• User interface frameworks (SwiftUI for iOS, XML for Android)</p><p>• Source control (e.g., Git)</p><p>• Testing and debugging</p><p>• Knowledge of app store submission processes</p><p><strong>Steps to Kickstart Your Career</strong></p><p>1. <strong>Get the Basics:</strong></p><p>• Choose iOS or Android development.</p><p>• Learn the necessary programming languages and development environments through self-teaching, university programs, or bootcamps.</p><p>2. <strong>Build a Portfolio:</strong></p><p>• Develop and publish personal projects.</p><p>• Utilize GitHub to showcase your code.</p><p>• Create and release apps on app stores to demonstrate your skills.</p><p>3. <strong>Craft Your Resume:</strong></p><p>• Highlight personal projects and relevant experiences.</p><p>• Use quantifiable achievements to demonstrate your impact.</p><p>4. <strong>Apply for Jobs:</strong></p><p>• Target junior positions.</p><p>• Leverage your portfolio to stand out.</p><p><strong>Mindset and Persistence</strong></p><p>The journey to becoming a mobile app developer requires the right mindset:</p><p>• <strong>Realistic Expectations:</strong> Understand the time and effort required to gain skills.</p><p>• <strong>Consistent Practice:</strong> Dedicate regular sessions to learning and practicing.</p><p>• <strong>Dual Goals:</strong> Set long-term and short-term goals to maintain motivation.</p><p><strong>Technical and Soft Skills for Job Applications</strong></p><p>• <strong>Technical Skills:</strong> In addition to mobile development, understand algorithms, data structures, and source control.</p><p>• <strong>Soft Skills:</strong> Effective communication, teamwork, and problem-solving abilities are crucial.</p><p><strong>Final Thoughts</strong></p><p>Becoming a mobile app developer is a challenging but rewarding journey that opens doors to various career opportunities. Whether you choose to work for a company, freelance, or develop your own apps, the skills you acquire will be invaluable. Stay disciplined, keep learning, and embrace the challenges along the way. With persistence and dedication, you can achieve your dream of becoming a successful mobile app developer.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e0c724580a0d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Memory Management & Retain Cycle in Swift, an explanation with example.]]></title>
            <link>https://anangnugraha.medium.com/memory-management-retain-cycle-in-swift-an-explanation-with-example-f018d292acd3?source=rss-c180321b19fc------2</link>
            <guid isPermaLink="false">https://medium.com/p/f018d292acd3</guid>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift-programming]]></category>
            <category><![CDATA[ios-development]]></category>
            <dc:creator><![CDATA[Anang Nugraha]]></dc:creator>
            <pubDate>Sun, 06 Nov 2022 15:15:34 GMT</pubDate>
            <atom:updated>2023-04-26T08:49:06.646Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FAwo9U2yZwa7z8Kq" /><figcaption>Photo by <a href="https://unsplash.com/@lastly?utm_source=medium&amp;utm_medium=referral">Tyler Lastovich</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>On this article we will learn about Memory Management and Retain Cycle on Swift, and first of all before we go further with retain cycle, we need to know briefly about the memory management in swift, to manage app memory usage swift using ARC, according to the official documentation, its say:</p><blockquote>Swift uses <em>Automatic Reference Counting</em> (ARC) to track and manage your app’s memory usage. In most cases, this means that memory management “just works” in Swift, and you don’t need to think about memory management yourself. ARC automatically frees up the memory used by class instances when those instances are no longer needed.</blockquote><p>we need to remember the last sentence, “ARC automatically frees up the memory used by class instances when those instances are no longer needed.”, from this sentence, we can understand that ARC <strong>frees</strong> objects only if the strong reference count goes to ‘<strong>zero</strong>’. The retain cycle will occur if the reference count can&#39;t go to zero because there 2 instances that have a strong reference to each other and can cause what we call a memory leak, what is a memory leak then?</p><p>A memory leak is a situation where memory that is allocated by an object is not released when that object goes out of scope, and it can affect the application and can slow it down or even got crash.</p><h3>Example of Retain Cycle:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/301/1*GwfNRQRFV1TKwLulIQe_2A.png" /></figure><p>we can see that there are 2 objects that have a strong reference to each other when it happens these 2 objects cannot be released from the memory (never ending circle) and occurring memory leak.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*qKfL9ZLZ2B7kZieeTZT2qQ.jpeg" /></figure><p>oke lets jump to the code example</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6f55af985f3380ee9420e7dd794df2b2/href">https://medium.com/media/6f55af985f3380ee9420e7dd794df2b2/href</a></iframe><p>let&#39;s say we have a class named Person with name and address as the variables and have a function to initiate the class and deinit will be called when the object of the class got deinitied, on line 15 we create an instance variable of Person named person, so person has a strong reference to the object.</p><p>as said before, ARC will not release or deallocated the memory of the object before the count becomes zero, so at line 16 we assign person1 to nil so the object will be deallocated and the print statement on the deinit function will be printed on log.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/307/1*_Y-1KClGqicxs2EaIQQUBA.png" /></figure><p>next, we try what if we add a new variable reference to the person1 variable that we created before:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bb53ea87438ca4d81bfd00fec77edeea/href">https://medium.com/media/bb53ea87438ca4d81bfd00fec77edeea/href</a></iframe><p>let&#39;s run the code, and you maybe wondering “why is the deinit function not called?”. So, person1 variable will not get deallocated even though we assign nil to that variable because we create the new variable that strongly references the person1 variable instance, so person1 variable only can be released if we assign person2 variable to nil.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5fce325c22c210cce9fa6f9f5764949b/href">https://medium.com/media/5fce325c22c210cce9fa6f9f5764949b/href</a></iframe><p>now “<strong><em>Person Arthur Morgan has deinitied” </em></strong>printed to the screen.</p><p>Okay, let&#39;s move to the real problem.</p><p>let&#39;s say, we have class Person and class Car, person can have an car, and car can be owned by a person, so on class Person we add variable car of Car class type, and on class Car we add a variable person of Person class like an example below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/501/1*to9hmL1-sWluU_Ddd428Pg.png" /></figure><p>Let&#39;s see how the retain cycle happens.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fd6cbf733f3cfb80e2d49185e81dbc0a/href">https://medium.com/media/fd6cbf733f3cfb80e2d49185e81dbc0a/href</a></iframe><p>as we can see on the code snippets above, we create a variable of Person and Car then we assign car to person and vice versa, then like we did before, we make these two variables become nil and run the code.</p><p>and… yeah, the deinit function of these two objects not being called and not printed on log screen, and that how the retain cycle occurs, its because this two variable of object person and car have a strong reference to each other so the ARC will never go zero and it can never release from memory (memory leak).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/743/1*QMcByUtlJ0HtUEclAHiuwg.png" /></figure><p>diagram:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/571/1*lQcwQyKDKnYjAbzx_TTn4Q.png" /></figure><p>So, what do we need to do to solve this problem?</p><p><strong>Solution</strong></p><p>there are several solutions to avoid the retain cycle situation, here we will try a different approach.</p><ol><li><strong>Weak reference for the rescue</strong></li></ol><p>from the previous example we already using strong reference, actually, there is 3 different type of references that we can use, Strong, Weak and Unowned. The strong reference is the default when we create and variable of any type, so what is a weak preference?</p><p>Weak preference means a pointer to an object which is not protected from being deallocated. So the retain count <strong><em>is not</em></strong> increased. But using weak also means that a weak reference can become nil during its lifetime.</p><p>According to <a href="https://cocoacasts.com/what-is-the-difference-between-strong-weak-and-unowned-references">cocoacast article</a> using weak have several consequences that are important to keep in mind.</p><ol><li><strong>ARC</strong> automatically sets a weak reference to nil when the class instance it points to is deallocated. That is a good thing. You don&#39;t want to have a reference pointing to a class instance that no longer exists. so by marking the variable with weak, the retain cycle will got break.</li><li>because <strong>ARC</strong> sets a weak reference to nil when the class instance is deallocated, weak references always need to be declared optional.</li></ol><p>Okay, let&#39;s jump straight to the example.</p><p>we assume that not all Person has a car, so we try to make the variable “car” in the class Person which is optional to be weak, by adding the weak keyword before writing var.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/15bd7e45f6e62d64767e571448021e25/href">https://medium.com/media/15bd7e45f6e62d64767e571448021e25/href</a></iframe><p>lets run this code and see if we sucessfully break the retain cycle or not.</p><p>and yeahh, we can see the printed text from the deinit function on log window.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/571/1*Benx0Q8E3-4k7fk_YeDbPQ.png" /></figure><p><strong>2. Unowned reference.</strong></p><p>Another solution is using unowned references, they serve the same purpose as weak references, that is, they avoid strong reference cycles because it does not increment or decrement the reference count of an object.</p><p>but what is the difference and when did we use weak or unowned?</p><p>the first difference, a weak reference is nullable and always declared as optional, which is set to nil if the instance they reference is deallocated. When that happens, the reference is set to nil. The value of a weak reference needs to be unwrapped before it can be accessed, whereas we can directly access the value of an unowned reference because, unlike a <strong>weak</strong> reference, the program guarantees to the Swift compiler that a <strong>unowned</strong> reference will not be <strong>nil</strong> when it is accessed.</p><p>so, for the example, we can use the unowned reference when we are sure that the variable cannot be nil, here we have a class named IdCard that has vars name and owner, the owner is Person that is not optional (the card must be owned by one person).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/44c7e5ee9d09e6f9efc4346d44ee36b5/href">https://medium.com/media/44c7e5ee9d09e6f9efc4346d44ee36b5/href</a></iframe><p>3. Using struct instead of class</p><p>the next approach is we can use struct instead of class, but why ? as we know that differentiation between class and struct is class is reference type and struct is a value type, so the struct is always created as a unique instance and there is no deinitializer to call in this case, but when the instances are set to nil the struct are released. So we can use struct instead of class as long we don&#39;t need some class functionality like inheritance or ObjC, let&#39;s try it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/672f63bf08d7a0e9388d8be076997257/href">https://medium.com/media/672f63bf08d7a0e9388d8be076997257/href</a></iframe><p>Okay, those are three different ways to avoid the Retain Cycle.</p><p>Now besides of example above, there are some cases where we have to pay attention to the potential for retain cycles.</p><ol><li><strong>Closure</strong></li></ol><blockquote><em>In swift accessing a self inside a closure makes the closure have strong reference to self. </em><strong><em>[weak self]</em></strong><em> creates a weak reference to </em><a href="https://www.codingem.com/self-in-swift/"><strong><em>self</em></strong></a><em> in a closure. This prevents memory leaks due to strong reference cycles.</em></blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4e2bf8a823c7fcd9beae704fcd5a5eaa/href">https://medium.com/media/4e2bf8a823c7fcd9beae704fcd5a5eaa/href</a></iframe><p>based on the explanation above, the code snippet above can occur the retain cycle, so what we need to do is to add <strong>[weak self].</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/335d5dd51030bc1f1eb3bd35bccbabf4/href">https://medium.com/media/335d5dd51030bc1f1eb3bd35bccbabf4/href</a></iframe><p>and now the retain cycle is gone.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/611/1*CkVf9hLYEr1z7FNtkVCoSQ.png" /></figure><p><strong>2. Delegate / Protocol</strong></p><p>The <a href="https://docs.swift.org/swift-book/LanguageGuide/Protocols.html">Swift book</a> says that “to prevent strong reference cycles, delegates are declared as weak references.” So we should also pay attention to this retain cycle issue in the use of delegation.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/27a3cf978555c8f7cb72b250036738f5/href">https://medium.com/media/27a3cf978555c8f7cb72b250036738f5/href</a></iframe><p>okay, that’s an explanation of memory management in Swift and the problems we usually face in daily development, especially the Retain Cycle problem, and along with some ways to overcome them.</p><p><strong><em>If you find this post useful, press👏 button as many times as you can and share this post with others. You can leave your feedback/suggestions in the comments 💬 below.</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f018d292acd3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Belajar Santai Alamofire Swift di Tahun 2021]]></title>
            <link>https://anangnugraha.medium.com/belajar-santai-alamofire-swift-di-tahun-2021-98411a053bfc?source=rss-c180321b19fc------2</link>
            <guid isPermaLink="false">https://medium.com/p/98411a053bfc</guid>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[swift-programming]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[alamofire]]></category>
            <dc:creator><![CDATA[Anang Nugraha]]></dc:creator>
            <pubDate>Wed, 22 Sep 2021 13:56:11 GMT</pubDate>
            <atom:updated>2021-09-22T13:56:11.785Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Egl-NquYjm8d6CEl" /><figcaption>Photo by <a href="https://unsplash.com/@royaannmiller?utm_source=medium&amp;utm_medium=referral">roya ann miller</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Oke, kali ini kita akan belajar santai dengan topik Alamofire menggunakan bahasa pemrograman Swift, pertama kita coba kenalan dulu dengan apa itu Alamofire, menurut laman github nya Alamofire adalah sebuah HTTP networking library yang ditulis di bahasa pemrograman Swift. Jadi pada artikel kali ini kita bakal membicarakan cara menggunakan library Alamofire untuk melakukan yang namanya proses HTTP Networking. So, langsung kita ke topiknya.</p><h4>Apa itu Alamofire ?</h4><p>Alamofire adalah sebuah networking library yang ditulis dengan dan untuk bahasa pemerograman Swift, kita bisa menggunakan library tersebut untuk melakukan Http Request pada Apple Platform seperti iOS atau MacOS. Contoh paling umum nya adalah kita gunakan untuk berkomunikasi dengan RestAPI seperti melakukan pengiriman data atau pengambilan data dari webservice.</p><p>Alamofire ini merupakan sebuah API yang dibangun diatas URLSession yang merupakan class dari Swift, karena hal tersebut Alamofire juga menggunakan konsep yang serupa dengan URLSession, seperti:</p><ol><li><strong>Session</strong>: merupakan shared resource yang dapat digunakan pada beberapa atau banyak request yang memiliki fungsi untuk mengkoordinasikan data-transfer task.</li><li><strong>Task</strong>: bertugas untuk membuat request dan menerima response, setiap task merupakan milik sebuah session. Task terdiri dari data task, upload task, download task dan stream task.</li></ol><p>Kalau dengan URLSession saja sudah bisa melakukan tugas-tugas tersebut, terus kenapa kita harus menggunakan Alamofire ?</p><p>Salah satu alasannya adalah kode yang kita tuliskan bisa menjadi lebih ringkas, mudah dibaca dan tentunya menjadi lebih elegan :D dibandingkan dengan URLSession yang bisa berimbas ke Development yang menjadi lebih cepat, terutama untuk projek dengan skala menengah ke besar, berikut perbandingan jika kita menggunakan Alamofire dan URLSession.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iayaeLTEXxAp6PWB5SqQAw.png" /><figcaption>Perbandingan baris kode Alamofire vs URLSession, Source: GITS Indonesia Youtube Channel</figcaption></figure><p>Di sini saya tidak akan menjelaskan dengan rinci tentang proses pemasangan atau installasi dari library tersebut, Alamofire bisa diinstall melalui CocoaPods atau Swift package manager.</p><p>So, kita langsung saja menuju topik utamanya.</p><h4>GET Request dengan Alamofire</h4><p>Untuk contoh penggunaanya kita menggunakan RestAPI dari <a href="https://httpbin.org/get">https://httpbin.org/</a> web tersebut menyediakan beragam endpoint untuk bisa kita gunakan untuk berbagai skenario percobaan untuk pembelajaran.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/09ea3379f9437c728ae89bf930f9c567/href">https://medium.com/media/09ea3379f9437c728ae89bf930f9c567/href</a></iframe><p>Kode di atas keliatannya singkat sekali, bukan ? yuk kita gali lebih dalam dari cuplikan kode diatas.</p><ul><li><strong>AF, </strong>adalah reference dari instance <strong>Session.default</strong> milik Alamofire, fungsinya mirip seperti <strong>URLSesssion.shared</strong>, yang menjadi starting point dari request yang akan kita buat.</li><li>function <strong>request()</strong> kita gunakan untuk membuat sebuah data task, dalam hal ini berupa HTTP Request. function ini jika kita lihat lebih lanjut memiliki banyak parameter, tapi pada contoh diatas kita hanya memasukkan sebuah url yang akan diakses oleh request tersebut.</li><li>Selanjutnya, hasil dari <strong>request()</strong> dirantaikan lansung dengan function <strong>response()</strong>, pada fungsion response ini menyediakan sebuah closure atau completion handler yang dieksekusi saat request telah selesai dilakukan.</li><li>pada closure dari <strong>response() </strong>memiliki satu parameter yang dapat kita gunakan yaitu <strong>response</strong> dengan type <strong>AFDataResponse&lt;Data?&gt; </strong>yang menyimpan informasi tentang data yang di kembalikan (dapat berupa nil).</li><li>Terakhir function <strong>debugPrint() </strong>untuk melakukan print out data termasuk informasi tambahan dari hasil request tadi.</li></ul><p>Saat kode tersebut dijalankan, makan berikut merupakan hasil yang didapat:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%3Fbg%3Drgba%2528171%252C%2B184%252C%2B195%252C%2B1%2529%26t%3Dseti%26wt%3Dnone%26l%3Dauto%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%2525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3D%25255BRequest%25255D%25253A%252520GET%252520https%25253A%25252F%25252Fhttpbin.org%25252Fget%25250A%252520%252520%252520%252520%25255BHeaders%25255D%25253A%252520None%25250A%252520%252520%252520%252520%25255BBody%25255D%25253A%252520None%25250A%25255BResponse%25255D%25253A%25250A%252520%252520%252520%252520%25255BStatus%252520Code%25255D%25253A%252520200%25250A%252520%252520%252520%252520%25255BHeaders%25255D%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520access-control-allow-credentials%25253A%252520true%25250A%252520%252520%252520%252520%252520%252520%252520%252520Access-Control-Allow-Origin%25253A%252520%252A%25250A%252520%252520%252520%252520%252520%252520%252520%252520Content-Length%25253A%252520487%25250A%252520%252520%252520%252520%252520%252520%252520%252520Content-Type%25253A%252520application%25252Fjson%25250A%252520%252520%252520%252520%252520%252520%252520%252520Date%25253A%252520Sun%25252C%25252019%252520Sep%2525202021%25252007%25253A33%25253A20%252520GMT%25250A%252520%252520%252520%252520%252520%252520%252520%252520Server%25253A%252520gunicorn%25252F19.9.0%25250A%252520%252520%252520%252520%25255BBody%25255D%25253A%25250A%252520%252520%252520%252520%252520%252520%252520%252520%25257B%25250A%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252522args%252522%25253A%252520%25257B%25257D%25252C%252520%25250A%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252522headers%252522%25253A%252520%25257B%25250A%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252522Accept%252522%25253A%252520%252522%252A%25252F%252A%252522%25252C%252520%25250A%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252522Accept-Encoding%252522%25253A%252520%252522br%25253Bq%25253D1.0%25252C%252520gzip%25253Bq%25253D0.9%25252C%252520deflate%25253Bq%25253D0.8%252522%25252C%252520%25250A%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252522Accept-Language%252522%25253A%252520%252522en%25253Bq%25253D1.0%252522%25252C%252520%25250A%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252522Host%252522%25253A%252520%252522httpbin.org%252522%25252C%252520%25250A%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252522User-Agent%252522%25253A%252520%252522Alamofire%25252F1.0%252520%2528com.apple.dt.playground.stub.iOS_Simulator.Alamofire-34EB951E-C2F5-46E3-89EC-A34F673E3445%25253B%252520build%25253A1%25253B%252520iOS%25252014.5.0%2529%252520Alamofire%25252F5.4.3%252522%25252C%252520%25250A%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252522X-Amzn-Trace-Id%252522%25253A%252520%252522Root%25253D1-6146e7bf-41740e5c06a0b6cd7bc6c857%252522%25250A%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%25257D%25252C%252520%25250A%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252522origin%252522%25253A%252520%252522125.165.234.222%252522%25252C%252520%25250A%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252522url%252522%25253A%252520%252522https%25253A%25252F%25252Fhttpbin.org%25252Fget%252522%25250A%252520%252520%252520%252520%252520%252520%252520%252520%25257D%25250A%25255BNetwork%252520Duration%25255D%25253A%2525201.3734620809555054s%25250A%25255BSerialization%252520Duration%25255D%25253A%2525200.0s%25250A%25255BResult%25255D%25253A%252520success%2528Optional%2528487%252520bytes%2529%2529%25250A&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F%3Fbg%3Drgba%252528171%25252C%2B184%25252C%2B195%25252C%2B1%252529%26t%3Dseti%26wt%3Dnone%26l%3Dauto%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%252525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3D%2525255BRequest%2525255D%2525253A%25252520GET%25252520https%2525253A%2525252F%2525252Fhttpbin.org%2525252Fget%2525250A%25252520%25252520%25252520%25252520%2525255BHeaders%2525255D%2525253A%25252520None%2525250A%25252520%25252520%25252520%25252520%2525255BBody%2525255D%2525253A%25252520None%2525250A%2525255BResponse%2525255D%2525253A%2525250A%25252520%25252520%25252520%25252520%2525255BStatus%25252520Code%2525255D%2525253A%25252520200%2525250A%25252520%25252520%25252520%25252520%2525255BHeaders%2525255D%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520access-control-allow-credentials%2525253A%25252520true%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520Access-Control-Allow-Origin%2525253A%25252520%25252A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520Content-Length%2525253A%25252520487%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520Content-Type%2525253A%25252520application%2525252Fjson%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520Date%2525253A%25252520Sun%2525252C%2525252019%25252520Sep%252525202021%2525252007%2525253A33%2525253A20%25252520GMT%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520Server%2525253A%25252520gunicorn%2525252F19.9.0%2525250A%25252520%25252520%25252520%25252520%2525255BBody%2525255D%2525253A%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%2525257B%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252522args%25252522%2525253A%25252520%2525257B%2525257D%2525252C%25252520%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252522headers%25252522%2525253A%25252520%2525257B%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252522Accept%25252522%2525253A%25252520%25252522%25252A%2525252F%25252A%25252522%2525252C%25252520%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252522Accept-Encoding%25252522%2525253A%25252520%25252522br%2525253Bq%2525253D1.0%2525252C%25252520gzip%2525253Bq%2525253D0.9%2525252C%25252520deflate%2525253Bq%2525253D0.8%25252522%2525252C%25252520%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252522Accept-Language%25252522%2525253A%25252520%25252522en%2525253Bq%2525253D1.0%25252522%2525252C%25252520%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252522Host%25252522%2525253A%25252520%25252522httpbin.org%25252522%2525252C%25252520%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252522User-Agent%25252522%2525253A%25252520%25252522Alamofire%2525252F1.0%25252520%252528com.apple.dt.playground.stub.iOS_Simulator.Alamofire-34EB951E-C2F5-46E3-89EC-A34F673E3445%2525253B%25252520build%2525253A1%2525253B%25252520iOS%2525252014.5.0%252529%25252520Alamofire%2525252F5.4.3%25252522%2525252C%25252520%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252522X-Amzn-Trace-Id%25252522%2525253A%25252520%25252522Root%2525253D1-6146e7bf-41740e5c06a0b6cd7bc6c857%25252522%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%2525257D%2525252C%25252520%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252522origin%25252522%2525253A%25252520%25252522125.165.234.222%25252522%2525252C%25252520%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252522url%25252522%2525253A%25252520%25252522https%2525253A%2525252F%2525252Fhttpbin.org%2525252Fget%25252522%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%2525257D%2525250A%2525255BNetwork%25252520Duration%2525255D%2525253A%252525201.3734620809555054s%2525250A%2525255BSerialization%25252520Duration%2525255D%2525253A%252525200.0s%2525250A%2525255BResult%2525255D%2525253A%25252520success%252528Optional%252528487%25252520bytes%252529%252529%2525250A&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fstatic%2Fbrand%2Fbanner.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/3074bbe702847b3237905b4c9656c230/href">https://medium.com/media/3074bbe702847b3237905b4c9656c230/href</a></iframe><p>dari hasil diatas dapat kita lihat informasi berupa request headers, response headers, response body, dan lain sebagainya, dari response tersebut kita bisa menggunakan type Result dari type bawaan bahasa Swift dengan enum, yang didalamnya terdapat .success dan .failure, kita akan lihat ini di section selanjutnya.</p><h4>Menangani Response dengan Decodable</h4><p>Kita bisa menangani response JSON dari RestAPI dengan memanfaatkan komponen dari Swift yaitu Codable, kita bisa menggunakannya untuk melakukan proses decode dari format JSON menjadi swift native types, pada contoh kasus berikut kita mendefiniskan struct <strong>User </strong>sebagai model objek.</p><p>Alamofire memiliki dukungan bawaan untuk Decodable, jadi kita bisa secara otomatis mendecode response kedalam sebuah objek dengan data type yang kita definisikan, cekidot…</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2eb0a07a605ff29bfbabbabb3c0b6220/href">https://medium.com/media/2eb0a07a605ff29bfbabbabb3c0b6220/href</a></iframe><p>Pada code diatas, kita mendefinisikan sebuah struct dengan nama <strong>User </strong>yang conforms untuk protocol Codable (Encodable — Decodable) dengan nama variable yang sama dengan yang ditemukan pada data JSON yang kita gunakan.</p><p>Selanjutnya kita melakukan request dengan Alamofire, kali ini kita menggunakan function <strong>responseDecodable(of:completionHandler:) </strong>dengan 2 parameter.</p><ol><li>parameter <strong>of:</strong> dapat kita masukkan type yang akan kita decode, dalam hal ini <strong>[User].self </strong>(array dari objek User) sesuai dengan format JSON yang digunakan.</li><li>lalu parameter kedua memiliki sebuah completion handler berupa closure.</li></ol><h4>Handling response success dan failure</h4><p>Masih dalam contoh kasus pada kode snippet sebelumnya, langkah selanjutnya kita dapat melakukan handling untuk state success dan failure dengan memanfaatkan Switch Case dari bahasa pemerograman Swift dengan result yang didaptkan dari response.</p><p>Jika request berhasil dilakukan, maka case <strong>.success</strong> akan di trigger dimana case ini memberikan kita sebuah data dengan type yang telah didefinisikan dengan codable sebelumnya <strong>[User].self</strong>.</p><p>Sebaliknya, jika request terdapat kesalahan atau terjadi error maka case .failure akan triggered, state ini memiliki value error dengan type <strong>AFError</strong> yang selanjutnya dapat kita lakukan aksi seperti printout pesan kesalahan dan lain sebagainya.</p><p>Ini merupakan salah satu keunggulan dari Alamofire, jika pada URLSession kita harus berkerja ekstra untuk melakukan checking seperti data == nil, error != nil , dimana dengan menggunakan Alamofire kita hanya perlu melakukan handling dengan case seperti yang dicontohkan diatas. Simpel bukan ?</p><p>Tambahan…</p><p>Oiya kita juga bisa melakukan sebuah validasi untuk request Alamofire berdasarkan statusCode dari http response nya, langsung cek berikut kodenya.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/42a0b594f9eab18e0847d45725eba864/href">https://medium.com/media/42a0b594f9eab18e0847d45725eba864/href</a></iframe><pre>Pada kode yang kita tulis diatas, kita melakukan request kepada sebuah endpoint yang pasti akan mengembalikan response dengan status code 404 Not Found, status code pada request tersebut akan divalidasi dengan function <strong>validate(), </strong>dan<strong> </strong>response dengan status code 200 sampai 399 akan dinyatakan berhasil.</pre><pre>Optional(404)</pre><p>Pada kode yang kita tulis diatas, kita melakukan request kepada sebuah endpoint yang pasti akan mengembalikan response dengan status code 404 Not Found, status code pada request tersebut akan divalidasi dengan function <strong>validate(), </strong>dan<strong> </strong>response dengan status code 200 sampai 399 akan dinyatakan berhasil, selanjutnya jika response pada completion handler terjadi error kita bisa mendapatkan status code dan kita bisa menangani error secara spesifik berdasrkan dari kode statusnya, keren kan ? :D</p><h4>Menambahkan Query Parameters Pada GET Request</h4><p>Oke lanjut ke pembahasan satu ini, biasanya apa lagi yang sering kita temui saat ingin melakukan request ke endpoin request RestAPI ? yup tentu saja Query Parameters, biasanya mereka berada pada url diencode setelah tanda <strong>?</strong></p><p>Sebenarnya ada 2 cara untuk menerapkan query parameters, yaitu</p><ol><li>Secara langsung dituliskan pada URL, contoh <a href="http://httpbin.org/get?foo=bar&amp;lorem=ipsum">http://httpbin.org/get?role=member&amp;page=</a>1.</li><li>Dengan memberikan nilai array parameters pada function <strong>request().</strong></li></ol><p>Disini kita bakal membahas pendekatan yang kedua, berikut adalah contohnya:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/26e914cac1395820b69aea544ed548bc/href">https://medium.com/media/26e914cac1395820b69aea544ed548bc/href</a></iframe><p>Pada kode diatas kita terlebih dahulu mendeklarasikan params berupa Dictionary dengan type data [String: Any] karena value berupa String dan juga Integer, lalu kita memberikan params tersebut kedalam function <strong>request(_:parameters:).</strong></p><p>Alamofire dengan cerdas akan otomatis melakukan encode pada parameter dengan menggunakan <strong>URLEncoding.default.</strong></p><p>Oke, sekian untuk method GET, kita lanjuke ke Method selanjutnya, yaitu POST.</p><h4><strong>Membuat POST Request dengan Alamofire</strong></h4><p>Oke, sekarang kita akan mencoba melakukan http request dengan method POST, jadi method ini pada umumnya mengirimkan request body yang membawa data yang akan dikirimkan.</p><p>Contoh penerapan POST adalah saat melakukan pendaftaran pada sebuah website, kita melakukan request pada RESTApi dengan membawa data pada request body untuk dikirimkan ke webservice.</p><p>Oke langsung saja berikut contoh penerapannya menggunakan Alamofire.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/622b478d45abdeebeb3a16dac8c3f4fb/href">https://medium.com/media/622b478d45abdeebeb3a16dac8c3f4fb/href</a></iframe><p>Kode diatas sebenarnya hampir sama dengan request get yang kita lakukan sebelumnya, perbedaannya ada pada function <strong>request() </strong>yang di dalamnya kita menuliskan parameter <strong>method </strong>dengan value <strong>.post.</strong></p><p>Seperti sebelumnya, kita mengirimkan params berupa dictionary pada http request yang di encode sebagai <strong>application/x-www-form-urlencoded, </strong>yang mana merupakan default saat mengirimkan data dengan method POST.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%3Fbg%3Drgba%2528171%252C%2B184%252C%2B195%252C%2B1%2529%26t%3Dseti%26wt%3Dnone%26l%3Dauto%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%2525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3D%25257B%25250A%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252522args%252522%25253A%252520%25257B%25257D%25252C%252520%25250A%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252522data%252522%25253A%252520%252522%252522%25252C%252520%25250A%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252522files%252522%25253A%252520%25257B%25257D%25252C%252520%25250A%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252522form%252522%25253A%252520%25257B%25250A%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252522email%252522%25253A%252520%252522Anang%252540gmail.com%252522%25252C%252520%25250A%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252522first_name%252522%25253A%252520%252522Anang%252522%25252C%252520%25250A%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252522last_name%252522%25253A%252520%252522Nugros%252522%25250A%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%25257D%25252C%252520%25250A%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252522headers%252522%25253A%252520%25257B%25250A%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252522Accept%252522%25253A%252520%252522%252A%25252F%252A%252522%25252C%252520%25250A%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252522Accept-Encoding%252522%25253A%252520%252522br%25253Bq%25253D1.0%25252C%252520gzip%25253Bq%25253D0.9%25252C%252520deflate%25253Bq%25253D0.8%252522%25252C%252520%25250A%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252522Accept-Language%252522%25253A%252520%252522en%25253Bq%25253D1.0%252522%25252C%252520%25250A%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252522Content-Length%252522%25253A%252520%25252257%252522%25252C%252520%25250A%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252522Content-Type%252522%25253A%252520%252522application%25252Fx-www-form-urlencoded%25253B%252520charset%25253Dutf-8%252522%25252C%252520%25250A%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252522Host%252522%25253A%252520%252522httpbin.org%252522%25252C%252520%25250A%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252522User-Agent%252522%25253A%252520%252522Alamofire%25252F1.0%252520%2528com.apple.dt.playground.stub.iOS_Simulator.Alamofire-EA24EA9E-520F-4377-A6AB-D800176ED73C%25253B%252520build%25253A1%25253B%252520iOS%25252014.5.0%2529%252520Alamofire%25252F5.4.3%252522%25252C%252520%25250A%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252522X-Amzn-Trace-Id%252522%25253A%252520%252522Root%25253D1-61475ba3-7454e90463adc6ad1d7836ac%252522%25250A%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%25257D%25252C%252520%25250A%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252522json%252522%25253A%252520null%25252C%252520%25250A%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252522origin%252522%25253A%252520%252522125.165.234.222%252522%25252C%252520%25250A%252520%252520%252520%252520%252520%252520%252520%252520%252520%252520%252522url%252522%25253A%252520%252522https%25253A%25252F%25252Fhttpbin.org%25252Fpost%252522%25250A%252520%252520%252520%252520%252520%252520%252520%252520%25257D&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F%3Fbg%3Drgba%252528171%25252C%2B184%25252C%2B195%25252C%2B1%252529%26t%3Dseti%26wt%3Dnone%26l%3Dauto%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%252525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3D%2525257B%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252522args%25252522%2525253A%25252520%2525257B%2525257D%2525252C%25252520%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252522data%25252522%2525253A%25252520%25252522%25252522%2525252C%25252520%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252522files%25252522%2525253A%25252520%2525257B%2525257D%2525252C%25252520%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252522form%25252522%2525253A%25252520%2525257B%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252522email%25252522%2525253A%25252520%25252522Anang%25252540gmail.com%25252522%2525252C%25252520%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252522first_name%25252522%2525253A%25252520%25252522Anang%25252522%2525252C%25252520%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252522last_name%25252522%2525253A%25252520%25252522Nugros%25252522%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%2525257D%2525252C%25252520%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252522headers%25252522%2525253A%25252520%2525257B%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252522Accept%25252522%2525253A%25252520%25252522%25252A%2525252F%25252A%25252522%2525252C%25252520%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252522Accept-Encoding%25252522%2525253A%25252520%25252522br%2525253Bq%2525253D1.0%2525252C%25252520gzip%2525253Bq%2525253D0.9%2525252C%25252520deflate%2525253Bq%2525253D0.8%25252522%2525252C%25252520%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252522Accept-Language%25252522%2525253A%25252520%25252522en%2525253Bq%2525253D1.0%25252522%2525252C%25252520%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252522Content-Length%25252522%2525253A%25252520%2525252257%25252522%2525252C%25252520%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252522Content-Type%25252522%2525253A%25252520%25252522application%2525252Fx-www-form-urlencoded%2525253B%25252520charset%2525253Dutf-8%25252522%2525252C%25252520%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252522Host%25252522%2525253A%25252520%25252522httpbin.org%25252522%2525252C%25252520%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252522User-Agent%25252522%2525253A%25252520%25252522Alamofire%2525252F1.0%25252520%252528com.apple.dt.playground.stub.iOS_Simulator.Alamofire-EA24EA9E-520F-4377-A6AB-D800176ED73C%2525253B%25252520build%2525253A1%2525253B%25252520iOS%2525252014.5.0%252529%25252520Alamofire%2525252F5.4.3%25252522%2525252C%25252520%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252522X-Amzn-Trace-Id%25252522%2525253A%25252520%25252522Root%2525253D1-61475ba3-7454e90463adc6ad1d7836ac%25252522%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%2525257D%2525252C%25252520%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252522json%25252522%2525253A%25252520null%2525252C%25252520%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252522origin%25252522%2525253A%25252520%25252522125.165.234.222%25252522%2525252C%25252520%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252522url%25252522%2525253A%25252520%25252522https%2525253A%2525252F%2525252Fhttpbin.org%2525252Fpost%25252522%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%25252520%25252520%2525257D&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fstatic%2Fbrand%2Fbanner.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/65aac922857e4ced3f221d9f9c34d44e/href">https://medium.com/media/65aac922857e4ced3f221d9f9c34d44e/href</a></iframe><p>Cuplikan diatas merupakan request body yang kita kirimkan sebelumnya yang ditampilkan oleh <strong>HTTPBin, </strong>disitu dapat dilihat data yang tadi kita kirimkan.</p><p>Secara default alamofire akan menghandle request post dengan encode <strong>URLEncodedFormParameterEncoder </strong>seperti yang kita lakukan sebelumnya, namun kita juga bisa meminta Alamofire untuk meng-encode nya sebagai JSON dengan memberi value <strong>JSONParameterEncoder</strong> pada parameter encoder dan request akan di set sebagai <strong>Content-Type: application/json</strong>, contohnya seperti berikut.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3302cd8e5b49b28af8a615f38387a629/href">https://medium.com/media/3302cd8e5b49b28af8a615f38387a629/href</a></iframe><p>Maka data yang dikirimkan akan berbentuk seperti ini:</p><pre>{&quot;email&quot;:&quot;Anang@gmail.com&quot;,&quot;first_name&quot;:&quot;Anang&quot;,&quot;last_name&quot;:&quot;Nugros&quot;}</pre><h4>Menambahkan Request Parameter dengan Encodable</h4><p>Selain dengan mengirimkan parameter berupa dictionary, hal canggih lainnya yang bisa kita lakukan dengan Alamofire adalah dengan mengirimkan parameter berupa custom object type yang conform kepada Codable / Encodable, cek contoh berikut:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4b85058f01d263909d1cdf282a554fa8/href">https://medium.com/media/4b85058f01d263909d1cdf282a554fa8/href</a></iframe><p>Kita hanya perlu memasukkan value pada parameter function request dengan custom object type yang kita buat selama objek tersebut conform Codable (Encodable and Decodable), mudah bukan ?</p><p>Pyuhhhhh masuklah kita pada section terakhir pada artikel ini, lumayan panjang juga ya hehe</p><h4>Berkerja dengan HTTP Header</h4><p>jadi HTTP header merupakan bit text yang dikirimkan sebagai bagian dari HTTP Request, kita dapat menggunakannya untuk menyediakan metadata tentang permintaan (atau respons), seperti jenis respons, encoding, length, tanggal/waktu, dan banyak lagi, tetapi pada contoh kasus disini hanya akan membahas header untuk authentication dan/atau authorization yang sangat umum digunakan saat kita berkomunikasi dengan sebuah webservice.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8119503d74fca669d342729cb7611472/href">https://medium.com/media/8119503d74fca669d342729cb7611472/href</a></iframe><p>Pada contoh kode diatas kita ingin mengakses sebuah endpoint yang memerlukan sebuah Authorization berupa Bearer Token untuk dapat mengakses informasinya, pertama kita buat terlebih dahulu sebuah variable dengan type <strong>HTTPHeaders </strong>berupa array dari dictionary, setelah itu kita tinggal memasukkan variable tadi kedalam parameter <strong>headers</strong> di dalam function <strong>request()</strong>.</p><p>oiya HTTPHeaders juga punya beberapa extension untuk mempermudah menambahkan nilai headers yang di inginkan, lihat contoh berikut.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/74360353bf17cf7ad791a2e630d5d973/href">https://medium.com/media/74360353bf17cf7ad791a2e630d5d973/href</a></iframe><p>Keren kan XD ?</p><p>Yupp mungkin sekian untuk artikel kali ini, itu adalah yang bisa saya bagikan dari proses explorasi dan belajar library satu ini.</p><p>References:</p><ul><li><a href="https://learnappmaking.com/alamofire-swift-tutorial/#handling-failed-responses-with-failedlet-error">https://learnappmaking.com</a>/</li><li><a href="https://www.youtube.com/channel/UCwyc5AeH-8bTbA9v-P8Q1Hw">https://www.youtube.com/channel/UCwyc5AeH-8bTbA9v-P8Q1Hw</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=98411a053bfc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Berkenalan dengan Jetpack DataStore Preferences, calon pengganti SharedPreferences ?]]></title>
            <link>https://anangnugraha.medium.com/berkenalan-dengan-jetpack-datastore-preferences-calon-pengganti-sharedpreferences-3a5cfbf727fb?source=rss-c180321b19fc------2</link>
            <guid isPermaLink="false">https://medium.com/p/3a5cfbf727fb</guid>
            <category><![CDATA[jetpack]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[jetpack-datastore]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Anang Nugraha]]></dc:creator>
            <pubDate>Sat, 06 Mar 2021 10:08:24 GMT</pubDate>
            <atom:updated>2021-03-06T10:08:24.503Z</atom:updated>
            <content:encoded><![CDATA[<h3>Berkenalan dengan Jetpack DataStore Preferences, calon pengganti SharedPreferences ?</h3><p>Halo semuanya, kali ini kita bakal membahas salah satu library terbaru yang di keluarkan oleh Android yaitu Jetpack DataStore, sebenarnya library ini sudah diperkenalkan sejak bulan September tahun lalu dengan status Alpha release dan terakhir saat artikel ini ditulis memasuki versi alpha07, meskipun tulisan ini agak telat tapi mungkin bisa jadi alternatif bacaan buat teman-temen.</p><p>Jadi pertama kita berkenalan dulu apa itu Jetpack DataStore ? jadi DataStore merupakan media penyimpanan lokal yang penerapannya sama seperti kita menggunakan Shared Preferences, jadi menurut apa yang saya baca Jetpack DataStore ini hadir dengan berbagai kelebihan dibandingkan dengan Shared Preferences salah satunya DataStore menggunakan Kotlin, Coroutines, dan Flow untuk menyimpan data secara asinkronus, singkatnya DataStore ini bisa menjadi alternatif bahkan menjadi pengganti untuk Shared Preferences itu sendiri, jadi mengapa kita harus mencoba Jetpack DataStore ?</p><ul><li>Dibangun dengan Kotlin, Coroutines dan Flow.</li><li>Menggunakan asinkronus API untuk menyimpan dan membaca data, berbeda dengan Shared Preferences yang melakukannya secara sinkronus dan dalam beberapa kasus dapat menyebabkan error application not responding.</li><li>DataStore aman untuk dipanggil di UI thread. Secara default menggunakan Dispatchers.IO</li><li>Aman dari runtime exceptions.</li><li>Menyediakan metode untuk migrasi dari Shared Preferences.</li><li>DLL.</li></ul><p>Sebenarnya terdapat 2 jenis implementasi dair Jetpack DataStore sebagai berikut:</p><ol><li><strong>Preferences DataStore: </strong>mirip dengan SharedPreferences,data disimpan dalam bentuk pasangan key-value tatapi tidak menyediakan type-safety.</li><li><strong>Proto DataStore: </strong>menyimpan data sebagai custom type dengan skema tertentu menggunakan Protocol Buffer.</li></ol><p>Nah, di artikel ini kita hanya akan membahas Preferences Datastore, sedangkan untuk Proto DataStore mungkin akan kita bahas di artikel dan kesempatan berikutnya.</p><p>Secara lengkap head-to-head dari masing-masing metode adalah seperti pada gambar berikut:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*IITsh2LnLehnvu6D.png" /></figure><p>Oke kita langsung ke cara penggunaan dan implementasinya.</p><p>Pertama tentunya tambahkan dependency library di file app gradle.</p><pre>implementation &quot;androidx.datastore:datastore-preferences:{latestversion}&quot;</pre><p>Setelah itu pada MainActivity kita buat layout xml sederhana dengan satu EditText dan 2 Button untuk menyimpan dan mengambil data.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/017715a69c07f9922081086e8f426ff8/href">https://medium.com/media/017715a69c07f9922081086e8f426ff8/href</a></iframe><p>Di artikel kali ini kita akan memanfaatkan <strong>Kotlin extension functions </strong>untuk membuat fungsi menulis dan membaca data menggunakan Jetpack Datastore.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/be64f46955d4af87dfd787800d7d91c1/href">https://medium.com/media/be64f46955d4af87dfd787800d7d91c1/href</a></iframe><p>Lanjut kita buka MainActivity lalu tambahkan baris berikut untuk membuat object DataStore Preferences.</p><pre>val dataStore: DataStore<em>&lt;</em>Preferences<em>&gt; </em>=<br>    context.<em>createDataStore(</em>name = &quot;anugrahdev-data-store-prefs&quot;<em>)</em></pre><p>Selanjutnya kita buat Preferences Key seperti berikut:</p><pre>companion object <em>{<br>    </em>private val USERNAME = <em>stringPreferencesKey(</em>&quot;username&quot;<em>)<br>}</em></pre><p>Lalu kita dapat menyimpan value pada DataStore Preferences tadi.</p><pre>btnSave.setOnClickListener <strong>{<br>    </strong><em>lifecycleScope</em>.<em>launch </em><strong>{<br>        </strong>dataStore.setValue<em>(</em>USERNAME, textInputEditText.<em>text</em>.<em>toString())<br>    </em><strong>}<br>}</strong></pre><p>Dikode diatas value yang kita masukkan merupakan teks nya ditulis pada EditText.</p><p>Selanjutnya kita juga dapat mengambil value yang telah tersimpan dengan kode berikut:</p><pre>btnGet.setOnClickListener <strong>{<br>    </strong><em>lifecycleScope</em>.<em>launch </em><strong>{<br>        </strong>dataStore.<em>getValueFlow(</em>USERNAME, &quot;&quot;<em>)<br>            </em>.collect <strong>{<br>                </strong>Toast.makeText<em>(</em>this@MainActivity, <strong>it</strong>, Toast.<em>LENGTH_SHORT)</em>.show<em>()<br>            </em><strong>}<br>    }<br>}</strong></pre><p>Untuk kode lengkap pada MainActivity tadi dapat dilihat sebagai berikut:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/72cec0407dfa4699025b5edbaa60dfca/href">https://medium.com/media/72cec0407dfa4699025b5edbaa60dfca/href</a></iframe><p>Gimana ? Miripkan dengan penggunaan shared preferences, yup mereka sama-sama menggunakan key-value tetapi datastore mempunyai peningkatan dan kelebihannya yang dapat menggantikan dari shared preferences itu sendiri.</p><p>Yupp mungkin sekian untuk artikel kali ini, karena library ini masih berada di tahap alpha mungkin belum saatnya untuk kita gunakan di production tetapi untuk sekarang kita bisa belajar, oprek-oprek maupun riset terlebih dahulu dan menunggu sampai library ini rilis versi finalnya.</p><p><strong><em>If you find this post useful, press👏 button as many times as you can and share this post with others. You can leave your feedback/suggestions in the comments 💬 below.</em></strong></p><p><strong><em>For any other issues feel free to reach out to me via Social Media:</em></strong></p><ol><li><a href="https://twitter.com/Anangnugraha8">https://twitter.com/Anangnugraha8</a></li><li><a href="https://www.instagram.com/anangnugraha8/">https://www.instagram.com/anangnugraha8/</a></li><li><a href="https://www.linkedin.com/in/anangnugraha/">https://www.linkedin.com/in/anangnugraha/</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3a5cfbf727fb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cara Install Android Emulator di Apple M1 Chip.]]></title>
            <link>https://anangnugraha.medium.com/cara-install-android-emulator-di-apple-m1-chip-610585e5c79c?source=rss-c180321b19fc------2</link>
            <guid isPermaLink="false">https://medium.com/p/610585e5c79c</guid>
            <category><![CDATA[m1]]></category>
            <category><![CDATA[macos]]></category>
            <category><![CDATA[android-emulator]]></category>
            <category><![CDATA[apple]]></category>
            <category><![CDATA[m1-chip]]></category>
            <dc:creator><![CDATA[Anang Nugraha]]></dc:creator>
            <pubDate>Wed, 24 Feb 2021 14:51:50 GMT</pubDate>
            <atom:updated>2021-02-24T14:51:50.347Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gdL3ofN70Bw6keHF" /><figcaption>Photo by <a href="https://unsplash.com/@antonioas?utm_source=medium&amp;utm_medium=referral">Antonio Scalogna</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Beberapa waktu lalu Apple merilis sebuah produk yang cukup menyita perhatian oleh penggiat IT ataupun pengguna dari produk Apple itu sendiri. Pasalnya, mereka merilis perangkat Macbook dan Mac Mini yang ditenagai oleh prosesor baru buatan mereka sendiri alih-alih menggunakan prosesor buatan dari Intel seperti yang mereka lakukan di beberapa tahun-tahun sebelumnya. Yupss prosesor yang kita bicarakan ini bernama Apple M1. Prosesor ini berbasis ARM(Advanced RISC Machines) yang klaim nya memiliki peforma yang tinggi dan penggunaan daya yang rendah. Tapi sebuah transisi memang tidak bisa dilakukan secara instant, beberapa aplikasi masih belum mendukung untuk berjalan secara native di arsitektur ARM milik M1 meskipun dari pihak Apple sendiri telah menyiapkan sebuah media penejerjemahan untuk software berbasis Intel X86 untuk dapat berjalan di ARM Chip ini.</p><p>Nah yang akan kita bahas kali ini adalah Program Android Emulator dan Android Studio, untuk update terakhir sampai artikel ini diketik saat ini kedua aplikasi tersebut belum didukung sepenuhnya dengan M1 Chip ini, Android Studio tetap dapat dijalankan dengan lancar menggunakan rosetta meskipun kadang ditemukan agak terasa lag, mungkin nanti peformanya bakalan jauh lebih baik saat Android Studio M1 nya rilis secara resmi, yang menurut kabar saat ini sedang dalam masa pengembangan.</p><p>Saat kita menjalankan Android Studio dan mencoba untuk menjalankan Android Emulator, maka akan muncul peringatan seperti berikut :</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/0*okhqxiXS7ilaLULI.png" /></figure><p>Hal tersebut terjadi karena rosetta belum bisa menerjemahkan Kernel extensions dan Virtual Machine apps yang memvirtualisasikan x86_64 computer platforms.</p><p>Kita tetap bisa menjalankan program melalui perangkat asli yang kita koneksikan ke Mac kita, tetapi disini kita akan melihat bagaimana cara menjalankan Android Emulator Preview version.</p><h3>Cara Install Android Emulator Preview di Apple M1.</h3><ol><li>Masuk ke situs <a href="https://github.com/google/android-emulator-m1-preview">https://github.com/google/android-emulator-m1-preview</a> disitu bisa kita lihat keterangan dari update terakhir versi beta tersebut termasuk fitur-fitur yang masih belum di dukung.</li><li>Klik pada release option dan download file DMG versi terbaru dari rilisnya.</li><li>Jalankan file DMG yang berhasil didownload, biasanya MacOS akan memunculkan peringatan, abaikan saja dan lanjutkan proses instalasi seperti biasa.</li><li>Saat dijakankan akan muncul lagi peringatan karena pengembang tidak terverifikasi.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/324/1*B92RInO6dnUdbQT_flC03w.png" /></figure><p>Solusinya adalah pergi ke System Preferences dan pilih Security &amp; Privacy dan plih “Run Anyway” seperti gambar berikut:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sfUDYdF3hbe-dLQL.png" /></figure><p>Sampai sini proses installasi telah selesai dan kita bisa langsung menjalankan Android Emulator.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/990/1*R9blMcP-F1MXkAPk1GoqqQ.png" /></figure><p>Sejauh saya menggunakan android emulatori ni yang jelas masih menjadi kekurangan adalah Chrome yang tidak bisa dijalankan dan kadang random muncul semacam glitch, ya namanya juga masih beta XD.</p><p>Ya lagi-lagi karena dalam masa transisi kita mungkin harus menunggu beberapa waktu lagi hingga kedua program ini support untuk dijalankan pada M1 dengan lancar.</p><p>Untuk proses installasi lengkap juga sudah ada di youtube yang dibuat oleh asadeveloper yang saya sematkan dibawah.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F9_KwTiQp80E%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D9_KwTiQp80E&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F9_KwTiQp80E%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/81683a09d9b0f5e382bdf708ac397bbc/href">https://medium.com/media/81683a09d9b0f5e382bdf708ac397bbc/href</a></iframe><p>Oke jadi segitu dulu untuk tulisan kali ini, mungkin nanti setelah rilis versi native resmi M1 nya akan saya update kembali.</p><p>Terima Kasih.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=610585e5c79c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android Kotlin: Yuk Migrasi ke View Binding]]></title>
            <link>https://anangnugraha.medium.com/android-kotlin-yuk-migrasi-ke-view-binding-95184c70c7a1?source=rss-c180321b19fc------2</link>
            <guid isPermaLink="false">https://medium.com/p/95184c70c7a1</guid>
            <category><![CDATA[android-apps]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Anang Nugraha]]></dc:creator>
            <pubDate>Sat, 12 Dec 2020 09:24:06 GMT</pubDate>
            <atom:updated>2020-12-12T09:24:06.121Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/803/1*PBYW7zmJA6QyZeKOVx3pVA.png" /></figure><p>Dulu di awal belajar cara membuat aplikasi Android untuk pertama kalinya, mungkin sebagian dari kita saat itu masih mengakses komponen view dari kode program menggunakan findViewById(), saat itu masih teringat betapa ribet dan banyaknya usaha yang kita lakukan untuk dapat bisa mengakses view apalagi kalau jumlahnya banyak maka kita harus menuliskan findViewById() berulang-ulang kali yang pastinya banyak memakan waktu dan usaha, hufttttt.</p><p>Dan setelah itu saat kita migrasi menggunakan bahasa pemrograman kotlin, disitu kita diberikan kemudahan lewat kotlin android extensions yang menggunakan synthetic, dengan kotlinx synthetic kita bisa mengakses langsung view dari layout dengan cara menuliskan id view tersebut lalu kotlin akan langsung melakukan synthetic access atau mengimport view tersebut ke kode program kita tanpa perlu repot-repot melakukan ritual findViewById() yang merepotkan.</p><p>Saya secara pribadi cukup enjoy menggunakan kotlin synthetic karena kemudahannya tetapi beberapa waktu lalu Android Team mengumumkan bahwa mereka akan atau telah mempensiunkan Android Extension Plugin yang termasuk Kotlinx Synthetic juga didalamnya, kita tetap bisa menggunakan Kotlin Synthetic namun dalam keadaan deprecated dan menurut kabar yang ada Android Team akan benar-benar menghilangkannya di September 2021, Lalu apa yang kita gunakan setelah Kotlin Synthetic ? Opsi terbaik yang dapat kita ambil adalah dengan menggunakan ViewBinding, lalu apa itu ViewBinding ?</p><p>View Binding akan membuat Binding classes yang akan melakukan bind/mengikat views pada XML layout menjadi generated class yang dapat digunakan di dalam aactivity / fragment kita, jadi intinya saat kita membuat suatu layout maka akan otomatis dibuatkan generated class yang nantinya dapat kita gunakan di dalam kode program.</p><p>kelebihan dan kekurangan dari masing-masing metode dapat di lihat pada tabel berikut:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/691/1*q_GG3n1OuZkvTNhzVNCspA.png" /></figure><p>Keuntungan utama yang kita dapatkan dari penggunaan ViewBinding adalah compile time safety, yaitu tidak seperti saat kita menggunakan Kotlin Synthetic misalkan saat kita ingin melakukan import view Button pada fragment A maka tidak hanya button pada fragment A saja yang bisa kita import menggunakan synthetic tetapi view dari fragment lain juga, yang mana hal tersebut dapat menyebabkan compile time error dan memungkinkan view untuk null, selain itu kelebihan lain adalah kodingan menjadi lebih simpel dan elegan dan build speed yang lebih cepat dibandingkan data binding yang memerlukan annotation processing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*KNKg2aQH0l6NOwwsSdCVNA.jpeg" /></figure><h3><strong>Lets Code</strong></h3><p>Oke, cukup untuk perkenalannya, mari kita langsung saja ke kode program untuk migrasi ke ViewBinding baik saat menggunakan activity maupun fragment.</p><p>Pertama buka build.gradle app lalu tambahkan 3 baris kode berikut untuk mengaktifkan fitur viewBinding setelah itu sync kan kembali projeknya:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6791b43f9ad6ec29dfea54ff26b02c0e/href">https://medium.com/media/6791b43f9ad6ec29dfea54ff26b02c0e/href</a></iframe><p>setelah kita menambahkan viewBinding makan android akan secara otomatis membuatkan kita generated class untuk masing-masing layout yang kita buat.</p><p>Misalkan kita mempunyai sebuah layout activity_main.xml seperti berikut yang terdapat dua view didalamnya:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f8dc47eae026dbbcfbd61d7f01bfb130/href">https://medium.com/media/f8dc47eae026dbbcfbd61d7f01bfb130/href</a></iframe><p>setelah itu ubah MainActivity kita menjadi seperti berikut:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9638e40fd5a17d32bf416278b1127ca7/href">https://medium.com/media/9638e40fd5a17d32bf416278b1127ca7/href</a></iframe><p>sedikit penjelasan, seperti yang kita lihat di baris 3 dan 4 disana kita bisa mendeklarasikan variable binding dengan object reference ActivityMainBinding yang didalamnya terdapat view pada layout, yaitu generated class yang sudah otomatis di buat oleh android berdasarkan layout yang tadi kita tuliskan, jadi misal kita punya layout dengan nama login_activity.xml maka akan otomatis dibuatkan generated class LoginActivityBinding oleh android yang nantinya bisa kita akses melalui Activity kita.</p><p>setelah itu kita inflate view tadi seperti yang ada pada baris ke 8 dan 9, dan mengoveride method onDestroy untuk menghindari memory leak, setelahnya kita bisa mengakses semua view yang ada pada layout dengan menggunakan variable binding yang telah kita deklarasikan sebelumnya cukup dengan cara mengetikkan nama variable binding diikuti dengan id view nya.</p><p><strong>Bagaimana dengan fragment ?</strong></p><p>Oke selanjutnya kita coba lakukan di fragment, lets go!.</p><p>Langkahnya sama seperti pada Activity tadi, kita buat terlebih dahulu class fragment beserta layoutnya lalu kita ubah menjadi seperti berikut:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/767b9a14084631b8598f3e117eb43588/href">https://medium.com/media/767b9a14084631b8598f3e117eb43588/href</a></iframe><p>Kita lihat tidak banyak perbedaan dibandingkan Activity tadi, hanya ada sedikit perbedaan saat melakukan inflate pada layout di baris 10 dan 11, selebihnya hampir sama.</p><h3>That its</h3><p>Yaa itu dia perkenalan singkat dengan viewBinding dan juga cara melakukan migrasi dan penggunaannya pada Activity dan Fragment kita, sudahkan anda mencoba nya ?</p><p>Mungkin sekian dulu untuk artikel kali ini.</p><p><strong><em>If you find this post useful, press👏 button as many times as you can and share this post with others. You can leave your feedback/suggestions in the comments 💬 below.</em></strong></p><p><strong><em>For any other issues feel free to reach out to me via Twitter:</em></strong></p><p><a href="https://twitter.com/Anangnugraha8">https://twitter.com/Anangnugraha8</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=95184c70c7a1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flutter : Implementing Pagination with GetX State Management]]></title>
            <link>https://anangnugraha.medium.com/flutter-implementing-pagination-with-getx-state-management-6b824b1e1eb5?source=rss-c180321b19fc------2</link>
            <guid isPermaLink="false">https://medium.com/p/6b824b1e1eb5</guid>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[state-management]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[dart]]></category>
            <dc:creator><![CDATA[Anang Nugraha]]></dc:creator>
            <pubDate>Sun, 29 Nov 2020 09:54:57 GMT</pubDate>
            <atom:updated>2020-11-29T10:03:12.056Z</atom:updated>
            <content:encoded><![CDATA[<h3>Flutter : Implementing Pagination (Infinite Scroll) with GetX State Management</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4vlkTJCWbP2Kh2vyK9BdEw.png" /></figure><p>When you are using social media like Twitter or Instagram, have you ever wondered what’s at the end of your feed? when you keep scrolling you will realize why that it will not end, The technique has many names, including infinite scrolling pagination, lazy loading pagination, endless scrolling pagination, etc.</p><p>Pagination is considered as the best practice while loading a big amount of data, it will give better performance and resource-efficient.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/652/1*u8FTeV5vGmmc_kxMpMpz_w.png" /></figure><p>In this article, We are going to demonstrate infinite scrolling on Flutter using a test API hosted in <a href="https://5f7cba02834b5c0016b058aa.mockapi.io/api/users?page=1&amp;limit=10">mockapi.io</a> to build a simple list of users app, this time we will use the Model-View-Controller pattern with GetX State Management, so what is GetX ?</p><p>According to the documentation, GetX is an extra-light and powerful solution for Flutter. It combines high-performance state management, intelligent dependency injection, and route management in a quick and practical way, when I&#39;m writing this article, GetX is one of the most liked libraries on pub.dev.</p><p>I tried to make this tutorial simple and you can look at the full code of this project on GitHub repository which I will share below</p><p>in the end, we will have an app like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/228/1*2Ws7Ce5ZwE0DC12LF-YloA.gif" /></figure><p>Okay, let&#39;s get started.</p><h3>Prerequisites</h3><ul><li>Flutter SDK</li><li>IDE of choice: VSCode / Intellij Idea / Android Studio</li></ul><h3>Initial Setup</h3><p>After creating a fresh Flutter project, then open pubspec.yaml and add the following dependencies:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/12ba91697f2971bd9195f33b483dff80/href">https://medium.com/media/12ba91697f2971bd9195f33b483dff80/href</a></iframe><p>in the dependencies we are added Dio as a network service library, lazy_load_scrollview a for a ScrollView that will enable lazy loading, and of course the latest version of GetX.</p><p>this is my package structure for the project, you can follow it if necessary:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/263/1*83U4XBvByfJ7mGdOAQpMWA.png" /></figure><p>After that, we can go to Main.dart, replace everything from it and write like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/70fc4ab2c2d417db11526f64f135849f/href">https://medium.com/media/70fc4ab2c2d417db11526f64f135849f/href</a></iframe><p>From the code above, we can see GetMaterialApp instead of MaterialApp, so what it is? like I said before, in this tutorial we will use GetX library and not only using it state management but we will also use the routing and other features of GetX, GetMaterialApp is not a modified MaterialApp, it is just a pre-configured Widget, which has the default MaterialApp as a child. GetMaterialApp will create routes, inject them, inject translations, inject everything you need for route navigation, that’s what they say in the documentation.</p><p>next, we will make a model for mapping the API response to Dart class model and make PaginationFilter model that we will use for holds pagination data that will be used in the controller.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4d8cb811f9eee5849c4b4fbc3bcc5783/href">https://medium.com/media/4d8cb811f9eee5849c4b4fbc3bcc5783/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7b061882f5637c444acf770bc80f45be/href">https://medium.com/media/7b061882f5637c444acf770bc80f45be/href</a></iframe><p>Now we will make a repository that will encapsulate the logic required to access data sources.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/03843982157b1332696f6c3fbc1b73a7/href">https://medium.com/media/03843982157b1332696f6c3fbc1b73a7/href</a></iframe><p>Now we move to the most important part of this tutorial, its controller where we write the logic for doing pagination.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1aeed2b4e522c080e687a469bd348935/href">https://medium.com/media/1aeed2b4e522c080e687a469bd348935/href</a></iframe><p>in the above class, we make 3 observable variables using a simple “.obs” from GetX, and getAllUsers function for fetching data and assign it into a list of Users, there are three functions that we must pay attention to, including getAllUser(), changePaginationFilter(), and loadNextPage(), on getAllUser() function we fetch the data of users and store it on userData variable, after that we check if it’s the last page by using “if” condition, and if the data is not empty we can store the data to user variable that we declare before with .obs extension, and we handle the page change logic in changePageFilter() and loadNextPage() function.</p><p><strong>At last</strong>, comes the UI building part. I’ve kept it clean and simple with one screen file that contains the entire main UI.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1f3d9c7a2436b738aff200ac392d3386/href">https://medium.com/media/1f3d9c7a2436b738aff200ac392d3386/href</a></iframe><p>You can see that in the body we wrap the ListView widget with a widget from the LazyLoadScrollView library, then we place the widget in the ObX widget for state management processes so that we can call the controller we previously created on the widget.</p><p><strong><em>that’s it for now</em></strong><em>, </em><strong><em>You can find the complete source code of this project in this repository.</em></strong></p><p><a href="https://github.com/anugrahdev/GetX_Pagination">https://github.com/anugrahdev/GetX_Pagination</a></p><p><strong><em>If you find this post useful, press👏 button as many times as you can and share this post with others. You can leave your feedback/suggestions in the comments 💬 below.</em></strong></p><p><strong><em>For any other issues feel free to reach out to me via Twitter:</em></strong></p><p><a href="https://twitter.com/Anangnugraha8">https://twitter.com/Anangnugraha8</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6b824b1e1eb5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Pengalaman online internship di DOT Indonesia sebagai Android Developer.]]></title>
            <link>https://anangnugraha.medium.com/pengalaman-online-internship-di-dot-indonesia-sebagai-android-developer-b63e9431445e?source=rss-c180321b19fc------2</link>
            <guid isPermaLink="false">https://medium.com/p/b63e9431445e</guid>
            <category><![CDATA[internships]]></category>
            <dc:creator><![CDATA[Anang Nugraha]]></dc:creator>
            <pubDate>Thu, 26 Nov 2020 16:40:20 GMT</pubDate>
            <atom:updated>2020-11-26T16:40:20.804Z</atom:updated>
            <content:encoded><![CDATA[<p>Halo, pertama-tama perkenalkan saya Anang saat ini masih terdaftar sebagai mahasiswa TI tingkat akhir di salah satu PTN di kota Palembang, jadi diartikel kali ini saya mau sharing pengalaman selama magang sebagai Android Developer di salah satu software house yang berbasis di kota Malang, yaitu PT. Digdaya Olah Teknologi (DOT) Indonesia di periode bulan Juni — Oktober 2020, jadi maaf kalo kepanjangan XD.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/456/1*UdQ1qRWBD4CnyUb4ex78rQ.png" /></figure><p>Jadi kenapa bisa magang di DOT Indonesia?, sebelumnya pada akhir tahun 2019 sampai awal tahun 2020 sayasudah pernah magang sebagai IT Intern melalui program dari kampus di salah satu BUMN di kota Palembang tapi bukan sebagai Android Developer, bidang di dunia teknologi yang sudah 2 tahun terakhir ini saya ikuti dan tekuni, jadi karena di tahun 2020 terjadi pandemi COVID-19 yang membuat hampir semua perusahaan beralih dari Work From Office menjadi Work From Home atau bekerja dari rumah.</p><p>Pada saat itu beberapa perusahaan terutama di bidang IT mengalihkan aktifitas menjadi daring termasuk kegiatan Internship, jadi masih ada sisi positif dari pandemi ini buat saya karena sebelumnya sangat susah untuk mencari peluang magang di perusahaan IT di bidang yang benar-benar kita inginkan terlebih lagi karena saya berasal dari kota Palembang yang masih sangat jarang sekali perusahaan IT nya, tetapi saat ada nya pandemi ini kita bisa menemukan beberapa perusahaan IT di seluruh indonesia yang membuka peluang magang secara WFH diperusahaan mereka.</p><p>Berhubung saat adanya pembatasan sosial pandemi COVID saat itu perkuliahan sudah selesai dan sedang libur panjang pergantian tahun ajaran jadi waktu-waktu sayahabiskan di rumah bersama laptop untuk belajar dan eksplorasi lebih jauh lagi kemampuan pemrograman dan pengembangan aplikasi Mobile menggunakan native Kotlin dan Flutter SDK tetapi belajar dan eksplorasi sendiri rasanya cukup sulit untuk berkembang lebih jauh lagi, akhirnya sayakepikiran untuk coba cari-cari informasi tempat magang dan saat itu karena cukup niat jadi sayamemanfaatkan platform sosial media Instagram yang disana ada beberapa akun yang memang sering membagikan informasi lowongan pekerjaan dan magang khusus di dunia IT.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*j5mCgNlKpf9N2XJs" /><figcaption>Photo by <a href="https://unsplash.com/@xps?utm_source=medium&amp;utm_medium=referral">XPS</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Saat itu bisa ditemukan ada beberapa peluang magang di perusahaan IT tetapi cukup jarang yang mencari kandidat di bidang Android Developer, dan singkat cerita sayanemuin brosur internship dari DOT Indonesia di Instagram yang menerima Android Developer Intern, tanpa pikir panjang sayalangsung apply persayaratan dan dokumen yang mereka minta, sampai akhirnya mereka mengabari buat melakukan tes teknis.</p><p>Jadi singkatnya tes teknisnya itu bikin aplikasi ngikutin/clone aplikasi tes yang sudah mereka siapin, setelah itu mereka hubungi lagi untuk tes wawancara, saat itu yang melakukan wawancara adalah mas Tofin selaku Talent Manager di DOT Indonesia. Setelah dinyatakan lulus tes minggu depannya masa internship langsung dimulai.</p><p>Dihari pertama magang, kami di beri sesi on-boarding oleh mentor yaitu pengenalan individu dan juga teknis yang harus di ikuti saat menjalankan magang, mulai dari collaboration tools yang digunakan, dan kegiatan keseharian selama magang yang harus kami lakukan, seperti menulis target dan pencapaian setiap harinya, mengikuti daily meeting, dan memberikan salam saat pagi hari sebelum memulai kerja. Selanjutnya ada fase training oleh mentor yaitu kami dilatih kembali untuk mengikuti standar penulisan kode, arsitektur, library yang digunakan dan lain sebagainya, oiya di DOT Android Developmentnya menggunakan arsitektur pattern MVVP + Repository Pattern + Data Binding.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0sJfPs0hsEaWhr8w" /><figcaption>Photo by <a href="https://unsplash.com/@ffstop?utm_source=medium&amp;utm_medium=referral">Fotis Fotopoulos</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Setelah melakukan training selanjutnya kami diarahkan untuk langsung terjun keprojek yang sedang berjalan untuk membantu tim core dari DOT untuk mendevelop sebuah projek aplikasi, dan saat itu aku di terjunkan di projek OSVAS, Aplikasi yang menangani bisnis property (apartemen, working space, dll) dari sewa, jual dan beli, dengan fitur — fitur yang memudahkan user, disitu ada 2 anak magang termasuk saya sendiri.</p><p>Di minggu-minggu pertama magang saya masih melakukan adaptasi dengan struktur penulisan kode dan guideline di DOT sendiri yang cukup berbeda dengan kebiasaan saya saat koding biasanya, di DOT sendiri sudah menyediakan guideline penulisan kode yang sudah sangat rapih dan struktur, tidak seperti kode saya sebelumnya yang masih cukup berantakan, tapi untungnya arsitektur yang digunakan sama dengan yang biasa saya gunakan yakni MVVP + Repository Pattern dengan Data Binding, jadi saya sudah familiar dan tinggal sedikit mengubah cara penulisan kode mengikuti guideline di DOT.</p><p>Kami di beri task langsung oleh mentor berupa pengerjaan satu fitur, oiya dalam pengerjaannya kami menggunakan version control GitLab, selama magang 3 bulan saya terlibat dalam pengerjaan task News Article, OnBoarding, Testimoni, Profile &amp; User Information, Settings, Documents, Deeplink, dan membantu beberapa bugfix, nanti selengkapnya ada pada PPT Jorney Recap.</p><p>Oiya singkat cerita setelah 3 bulan magang dan mengerjakan berbagai task, diujung periode kami melakukan Journey Recap yang berisi rangkuman cerita dan hasil yang didapat selama magang.</p><h3><strong>Apa yang di dapat ?</strong></h3><ul><li>Mendapatkan pengalaman dan sebagai Android Developer langsung di perusahaan IT <strong>(tercapai)</strong></li><li>Menambah skill — skill dan insight baru dan yang belum dimiliki yang dapat berguna untuk bekerja di industri nantinya <strong>(tercapai)</strong></li><li>Menambah pengalaman berkolaborasi dan bekerja kolektif secara tim <strong>(tercapai)</strong></li><li>Mendapatkan insight baru dari rekan — rekan mentor, karyawan maupun sesama magang di DOT <strong>(tercapai)</strong></li></ul><p>Selepas magang di DOT sendiri saya merasa penulisan koding dan struktur projek yang saya kerjakan menjadi lebih rapih dan teratur dan mendapat banyak insight pengerjaan real-world project.</p><p>untuk selengkapnya sudah di rangkup di slides Journey Recap</p><p><a href="https://docs.google.com/presentation/d/1Ybo8DzghVsSRseLrpSpqk9jS4oBoXQOyic4R-gevrp8/edit?usp=sharing">https://docs.google.com/presentation/d/1Ybo8DzghVsSRseLrpSpqk9jS4oBoXQOyic4R-gevrp8/edit?usp=sharing</a></p><p>Mungkin sekian cerita dari saya XD, maaf kalo kepanjangan, Terima Kasih</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b63e9431445e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Penggunaan Kotlin Sealed Class Untuk State Management Pada MVVM Pattern Android]]></title>
            <link>https://medium.com/dot-intern/penggunaan-kotlin-sealed-class-untuk-state-management-pada-mvvm-pattern-android-68829863362e?source=rss-c180321b19fc------2</link>
            <guid isPermaLink="false">https://medium.com/p/68829863362e</guid>
            <category><![CDATA[sealed-classes]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[case-study]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Anang Nugraha]]></dc:creator>
            <pubDate>Mon, 29 Jun 2020 08:21:45 GMT</pubDate>
            <atom:updated>2020-09-25T04:15:47.055Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*OSOMkE9xevFz8VA8" /><figcaption>Photo by <a href="https://unsplash.com/@mreichelt?utm_source=medium&amp;utm_medium=referral">Marc Reichelt</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Apa itu Sealed Class ?</h3><p>Sealed class adalah sebuah konsep baru pada bahasa pemrograman Kotlin yang tidak kita temukan di bahasa pemrograman Java, mari kita berkenalan dengan Sealed Class terlebih dahulu.</p><blockquote><em>A sealed class allows you to</em><strong><em> represent constrained hierarchies in which an object can only be of one of the given types</em></strong><em>.</em></blockquote><blockquote><em>That is, we have a class with a specific number of subclasses. What we get in the end is a concept very similar to an enum. The difference is that in the enum we only have one object per type, while in the sealed classes we can have several objects of the same class.</em></blockquote><blockquote><em>This difference </em><strong><em>will allow objects from a sealed class to keep state</em></strong><em>. This will bring us some advantages that we’ll see in a moment, and also opens the doors to some functional ideas.<br> — Antonio Leiva</em></blockquote><p>Begitulah kira-kira sedikit penjelasan tentang Sealed Class menurut <em>Antonio Leiva, </em>dari kutipan diatas dapat diartikan<em> </em>Sealed Class adalah class yang merepresentasikan pembatasan hierarki class, apa yang bisa kita dapatkan pada dasarnya sangat mirip dengan Enum Class yang mungkin sudah sering kita gunakan sebelumnya, perbedaannya adalah pada Enum kita hanya memiliki satu objek per class, sedangkan di Sealed Class kita dapat memiliki beberapa objek dari class yang sama, pada Sealed Class di dalamnya semua subclass harus berada pada file yang sama ditempat Sealed Class tersebut dideklarasikan dan Sealed Class<em> </em>juga memiliki default modifierabstract</p><h3>Mengapa Menggunakan Sealed Class ?</h3><p>Seperti yang telah disinggung diatas bahwa Sealed Class sangat mirip dengan Enum class, bahkan pada salah satu artikel tulisan Antonio Leiva yang dapat dibaca <a href="https://antonioleiva.com/sealed-classes-kotlin/">disini</a> menyebut Sealed Class sebagai Enum dengan kekuatan-super, lalu apa yang menjadi kelebihan Sealed Class dari Enum Class ?</p><p>Mari kita lihat penggunaan basic dari Enum class terlebih dahulu,</p><pre>enum class State{<br>    ERROR,<br>    LOADING,<br>    DATA<br>}</pre><p>dan pada view dapat ditulis seperti berikut,</p><pre>fun setViewState(state: State) {<br>    when(state) {<br>        State.ERROR -&gt; { // set error state in the view}<br>        State.LOADING -&gt; { // set loading state in the view }<br>        State.DATA -&gt; { // hide loading or error states in the view}<br>    }<br>}</pre><p>Namun, masalahnya adalah dengan menggunakan enum class seperti di atas, kita tidak bisa mengirim parameter ke View atau Activity kita, dan kita tidak disarankan untuk mengirim <em>context </em>atau <em>UI reference</em> apa pun di dalam MVVM pattern karena pada prinsipnya adalah untuk memisahkan logic dengan UI kita, tapi sebelum itu mari berkenalan dulu dengan apa itu MVVM Pattern.</p><p>MVVM (Model-View-ViewModel) adalah salah satu <em>Architectural Patterns</em> yang membagi tanggung jawab kepada tiga komponen, yaitu Model, View dan ViewModel. View bertanggung jawab untuk semua hal yang berhubungan dengan UI. Model merupakan komponen yang bertanggung untuk menyediakan data yang dibutuhkan. Terakhir ViewModel merupakan komponen inti dari <em>Architectural Patterns</em> ini, tugasnya menyimpan dan mengambil data dari Model untuk nantinya ditampilkan oleh View.</p><p>Jadi, pada dasarnya, jika kita ingin menggunakan enums untuk sesuatu yang sederhana yang tidak perlu menyimpan data atau tipe data yang berbeda per value-nya, maka hal tersebut tidak masalah akan tetapi jika kita membutuhkan sesuatu yang lebih spesifik seperti contoh yang akan kita bahas, kita memerlukan sesuatu yang lain, apa itu? yups, Sealed Class.</p><p>Pada artikel kali ini kita akan melihat bagaimana penggunaan Sealed Class untuk manajemen <em>network state</em> pada pengembangan aplikasi Android dengan MVVM Pattern, jadi tujuannya adalah kita akan membuat satu <em>generic class</em> yang akan menyimpan value berupa loading status, network error dan data yang akan dikirimkan ke view dan menjaga kodingan kita tetap <em>clean </em>dan <em>simple</em>.</p><h3>Contoh Penggunaan Sealed Class ?</h3><p>Pada contoh kasusnya kita akan membuat program sederhana untuk menampilkan daftar berita yang kita dapat dari API milik NewsAPI dan menggunakan MVVM Pattern, untuk API tersebut bisa kita gunakan secara gratis namun harus mendaftar terlebih dahulu <a href="https://newsapi.org/docs">disini</a> untuk mendapatkan token akses ke API.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*PEhJK_XPTfv-OY39cLEu7Q.jpeg" /></figure><p>Pertama kita atur terlebih dahulu dependency yang ada pada gradle, kira-kira menjadi seperti ini.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d7d3066e9000e7205fbc7fba87a2d29d/href">https://medium.com/media/d7d3066e9000e7205fbc7fba87a2d29d/href</a></iframe><p>Buat juga data class / model seperti berikut.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1f437f234e7259fc86f0892eadc272bb/href">https://medium.com/media/1f437f234e7259fc86f0892eadc272bb/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/209ca1f06b3c26b934538b7e90739f84/href">https://medium.com/media/209ca1f06b3c26b934538b7e90739f84/href</a></iframe><p>Selanjutnya buat class repository untuk transaksi data dari API.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7ca8d479a4a358cb8c78d119ae726c15/href">https://medium.com/media/7ca8d479a4a358cb8c78d119ae726c15/href</a></iframe><p>Lalu, yang terpenting adalah buatlah satu Sealed Class seperti berikut ini.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/815b39361232ce83b26123b5f9a6f766/href">https://medium.com/media/815b39361232ce83b26123b5f9a6f766/href</a></iframe><p>Ok, jadi sekarang sepertinya kita memiliki apa yang kita butuhkan yaitu <em>Loading State </em>untuk menyimpan kondisi saat program memuat data, lalu <em>Error State</em> yang memiliki parameter message untuk membawa pesan error menuju View, dan <em>Success State</em> yang akan membawa data untuk ditampilkan dalam tampilan.</p><p>Selanjutnya buatlah satu class ViewModel seperti contoh berikut.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b89cdc4d1bc93cecdaf313c7b80d0539/href">https://medium.com/media/b89cdc4d1bc93cecdaf313c7b80d0539/href</a></iframe><p>Seperti kita lihat di baris ke 12 sampai 18, saat function getHeadlineNews di dalam scope Coroutines dipanggil maka LiveData headlineNews yang kita definisikan sebagai Resource akan mendapatkan state Loading terlebih dahulu artinya saat pertama kali function tersebut dipanggil maka state loading lah yang pertama muncul, selanjutnya jika response dari data repository berhasil didapatkan maka LiveData headlineNews akan berisi state Success yang didalam nya terdapat Data yang kita dapatkan dari repository, dan jika data dari repository gagal didapatkan maka LiveData headlineNews akan memiliki value berupa resource yang memiliki pesan error.</p><p>Dan yang terakhir adalah bagaimana kita menggunakannya didalam view (activity/fragment).</p><p>Pada view kita deklarasikan terlebih dahulu ViewModel nya setelah itu perhatikan contoh pada cuplikan kode berikut ini.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1b5289cdb9714b749d938d2bfdd3a448/href">https://medium.com/media/1b5289cdb9714b749d938d2bfdd3a448/href</a></iframe><p>Fokuskan perhatian kita pada baris ke 15 sampai 35, disana kita melakukan <em>observasi </em>pada livedata ViewModel kita yang mengembalikan nilai berupa Resource&lt;List&lt;Article&gt;&gt; artinya kita mendapatkan Resource yang memiliki data berupa list dari Article.</p><p>Selanjutnya kita lakukan operasi pengkondisian menggunakan operator when yang memiliki kondisi <em>response </em>yang merupakan Resource, lalu jika state pada Resource tersebut adalah loading yang mana state tersebut adalah state pertama yang akan kita dapatkan saat melakukan observe pada LiveData yang sebelumnya kita definisikan di viewmodel, maka Progress Bar akan di tampilkan, dan selanjutnya jika data berhasil didapatkan maka kondisi akan memasuki state Success dan akan mendapatkan List dari Article yang nantinya data tersebut bisa kita tampilkan kelayar, dan jika saat pengambilan data terdapat kesalahan/error maka kita akan memasuki kondisi state Error dan didalamnya kita akan menampilkan pesan kesalahan berupa Toast.</p><p>Begini kira-kira tampilan aplikasi yang kita buat</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*veMfJn3Jd03WzW9RcYHwVg.gif" /><figcaption>Hasilnya</figcaption></figure><p>Bagaimana, mudah bukan ?, selain itu dengan menggunakan Sealed Class sebagai state manajemen dapat membuat kodingan kita tetap <em>clean</em>.</p><h3>Kesimpulan</h3><p>Kotlin Sealed Class pada dasarnya mirip seperti Enum Class namun lebih powerful dengan berbagai macam kelebihannya. Kita bisa mengirimkan variable atau nilai apapun di dalam Sealed Class, dan masih banyak lagi impelementasi dari Selaled Class yang dapat kita eksplorasi lebih jauh lagi.</p><p>Untuk source code lengkap dari projek yang kita bangun diatas dapat dilihat di Repository Github saya,</p><p><a href="https://github.com/anugrahdev/ResourceSealedClassExample">https://github.com/anugrahdev/ResourceSealedClassExample</a></p><p>*maaf untuk link repo sebelumnya saya update karena terdapat kesalahan, enjoy.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=68829863362e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/dot-intern/penggunaan-kotlin-sealed-class-untuk-state-management-pada-mvvm-pattern-android-68829863362e">Penggunaan Kotlin Sealed Class Untuk State Management Pada MVVM Pattern Android</a> was originally published in <a href="https://medium.com/dot-intern">DOT Intern</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>