<?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 Yunus Oktay on Medium]]></title>
        <description><![CDATA[Stories by Yunus Oktay on Medium]]></description>
        <link>https://medium.com/@yunusoktaydev?source=rss-2b8b1d27be90------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*7NQr9N16b_TIqPrsat-R9A.png</url>
            <title>Stories by Yunus Oktay on Medium</title>
            <link>https://medium.com/@yunusoktaydev?source=rss-2b8b1d27be90------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 19:37:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@yunusoktaydev/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[Real Time Face Detection in Flutter: Camera Stream and Google ML Kit Integration]]></title>
            <link>https://medium.com/@yunusoktaydev/real-time-face-detection-in-flutter-camera-stream-and-google-ml-kit-integration-6906986c70c7?source=rss-2b8b1d27be90------2</link>
            <guid isPermaLink="false">https://medium.com/p/6906986c70c7</guid>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[Yunus Oktay]]></dc:creator>
            <pubDate>Sun, 21 Dec 2025 09:19:12 GMT</pubDate>
            <atom:updated>2025-12-21T09:19:12.785Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n9resp9BE8b1mDnSoZ7Bzg.png" /></figure><p>In the mobile application landscape, asking a user to “take a selfie” seems like a trivial task. However, when quality is paramount for processes like <strong>KYC (Know Your Customer)</strong>, AI-driven avatars, or profile verification, simply snapping a picture isn’t enough.</p><p>Blurry photos, faces partially out of frame, or multiple people in a single shot can lead to backend rejections and a frustrating user experience.</p><p>In this article, we will build a “Smart Camera” module using <strong>Flutter</strong> and <strong>Google ML Kit</strong>. Instead of just capturing an image, we will analyze the camera stream in real-time, validate the user’s face, and only allow a capture when the conditions are perfect.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*xEdLm-wkVgh4eSFdfS8AvA.gif" /></figure><h3>Prerequisites</h3><p>To follow this tutorial, add these dependencies to your pubspec.yaml:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ktC_hB2NPyTkVinHYaNmrg.png" /></figure><ul><li><a href="https://pub.dev/packages/google_mlkit_face_detection"><strong>google_mlkit_face_detection</strong></a>: The core engine for face analysis.</li><li><a href="https://pub.dev/packages/camera"><strong>camera</strong></a>: Provides the raw image stream.</li><li><a href="https://pub.dev/packages/permission_handler"><strong>permission_handler</strong></a>: Essential for managing camera permissions gracefully on Android and iOS.</li></ul><h3>Why Google ML Kit?</h3><p>While there are various solutions for face detection (like TFLite or cloud-based APIs), Google ML Kit stands out for mobile development for three key reasons:</p><ul><li><strong>On-Device Performance:</strong> All processing happens locally on the phone. It’s fast and works offline.</li><li><strong>Privacy:</strong> Since face data is not sent to a server for detection, it is privacy-compliant by design.</li><li><strong>Detailed Metadata:</strong> It doesn’t just find a bounding box; it provides landmarks (eyes, nose, mouth positions), head rotation (Euler angles), and classification probabilities (smiling, eyes open).</li></ul><h3>1. The Bridge: Converting Camera Streams to ML Kit</h3><p>The most technically challenging part of this integration is bridging the gap between Flutter’s camera package and ML Kit.</p><p>The camera stream provides raw data (usually YUV on Android and BGRA on iOS) via the CameraImage class. ML Kit, however, requires an InputImage object with specific metadata.</p><p>Here is the utility class CameraUtils that handles this low-level byte conversion:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b3cb3a35245674ea1c36ec926e34e31d/href">https://medium.com/media/b3cb3a35245674ea1c36ec926e34e31d/href</a></iframe><p><strong>Note:</strong> The bytesPerRow parameter in InputImageMetadata is vital. If this is incorrect, the resulting image passed to the detector will look scrambled or skewed.</p><h3>2. Configuring the Detector: Speed vs. Accuracy</h3><p>ML Kit allows us to configure the FaceDetector based on our needs. Since we are processing a live stream, performance is key, but we also need accuracy to ensure the user is looking at the camera.</p><p>Here is how we configure the detector in our ImageAnalysisService:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4cf7fdcfe39bb9f60627bd9677f36480/href">https://medium.com/media/4cf7fdcfe39bb9f60627bd9677f36480/href</a></iframe><h3>3. Optimization: The Throttling Technique</h3><p>A modern smartphone camera captures 30 to 60 frames per second (FPS). Running a heavy machine learning model on <strong>every single frame</strong> will overheat the device and drain the battery rapidly.</p><p>To solve this, we use a technique called <strong>Throttling</strong> (or frame skipping). We only process a frame if the previous processing is finished <em>and</em> a certain interval has passed.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/74b07d10991b1e994fb7a96e4bc163e2/href">https://medium.com/media/74b07d10991b1e994fb7a96e4bc163e2/href</a></iframe><p>This simple modulo operation ensures the UI remains smooth (running at native FPS) while the heavy logic runs at a manageable rate (e.g., ~6–10 times per second).</p><h3>4. Validation Logic: Ensuring the “Perfect Shot”</h3><p>Detection is just the first step. To ensure high-quality captures for KYC or biometric purposes, we need to enforce strict rules. The updated _validateFaces method acts as a real-time filter that only gives the &quot;green light&quot; when specific conditions are met.</p><h4>1. Anti-Spoofing: Single Face Detection</h4><p>To prevent fraud or background noise from interfering with the verification, we first ensure exactly one person is present in the frame.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/22daca9cde965c5848ae307417af37b7/href">https://medium.com/media/22daca9cde965c5848ae307417af37b7/href</a></iframe><h4>2. Liveness Check: Eyes Open Validation</h4><p>By using leftEyeOpenProbability and rightEyeOpenProbability, we ensure the user is conscious and not blinking. We&#39;ve set a threshold of <strong>0.5</strong> for reliability.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e112dbff0eac198434b23c9e9b92a854/href">https://medium.com/media/e112dbff0eac198434b23c9e9b92a854/href</a></iframe><h4>3. Dynamic Centering: The “Safe Zone”</h4><p>We calculate the face’s center relative to the image dimensions. We define a <strong>“Safe Zone”</strong> (the middle 40% of the screen). If the face center falls outside the 30%–70% range, the user is prompted to adjust.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/64f264dd131ad827bc866baaae87d60e/href">https://medium.com/media/64f264dd131ad827bc866baaae87d60e/href</a></iframe><h4>4. Proximity Control: Size Check</h4><p>To avoid blurry or low-resolution face crops, the face must be close enough to the camera. We ensure the face width occupies at least <strong>35%</strong> of the frame width.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/92faa0e588a6e1a6e7d9489915bf5a59/href">https://medium.com/media/92faa0e588a6e1a6e7d9489915bf5a59/href</a></iframe><h4>5. The Final Approval</h4><p>If all the checks above pass, the user is notified that the conditions are perfect for the capture.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/36819fbc4aea34f37179050917d614a1/href">https://medium.com/media/36819fbc4aea34f37179050917d614a1/href</a></iframe><h4>Why this matters?</h4><blockquote>This logic transforms the user experience from a “guessing game” into a <strong>guided process</strong>. By providing specific feedback like <em>“Move closer”</em> or <em>“Open your eyes”</em>, you significantly reduce the friction in your onboarding flow and decrease the rate of manual review in your backend.</blockquote><h3>What’s Next?</h3><p>Now that you have a solid foundation, you can extend this module with:</p><ul><li><strong>Liveness Detection:</strong> Ask the user to blink or smile to ensure it’s not a static photo.</li><li><strong>Face Mesh:</strong> Use ML Kit Face Mesh for more precise 3D face modeling.</li><li><strong>Auto-Capture:</strong> Trigger the takePicture() function automatically the moment all validation conditions stay &quot;True&quot; for 2 consecutive seconds.</li></ul><h3>Conclusion</h3><p>By combining the Flutter camera package with <strong>Google ML Kit</strong>, we transformed a standard camera view into an intelligent input module. This approach significantly improves data quality for backend systems and provides a professional, guided experience for the user.</p><p>Real-time image processing in Flutter is powerful, but it requires careful management of memory (buffers) and processing power (throttling).</p><h4>Implementation &amp; Source Code</h4><p>You can find the full source code, including the camera utility and analysis service, in the GitHub repository below. Feel free to star it and use it as a reference for your own projects!</p><p>🔗 <strong>GitHub Repository:</strong></p><p><a href="https://github.com/yunusoktay/FaceDetection">GitHub - yunusoktay/FaceDetection</a></p><h3>Pro Tips for Implementation</h3><ol><li><strong>Dispose Resources:</strong> Always call _faceDetector.close() and _cameraController.dispose() when the widget is destroyed to prevent serious memory leaks.</li><li><strong>Platform Permissions:</strong> Don’t forget to add NSCameraUsageDescription to your Info.plist (iOS) and the camera permission to AndroidManifest.xml.</li><li><strong>UI Feedback:</strong> Since the camera stream is asynchronous, use a local state variable to show/hide the “Capture” button instantly based on the validation result.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6906986c70c7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The SwiftUI Navigation Architecture That Will Save Your Projects: The Router Pattern]]></title>
            <link>https://medium.com/icommunity/the-swiftui-navigation-architecture-that-will-save-your-projects-the-router-pattern-a38349198702?source=rss-2b8b1d27be90------2</link>
            <guid isPermaLink="false">https://medium.com/p/a38349198702</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <dc:creator><![CDATA[Yunus Oktay]]></dc:creator>
            <pubDate>Tue, 14 Oct 2025 17:09:44 GMT</pubDate>
            <atom:updated>2025-10-14T17:09:44.002Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ik4ODA0TyXMuFq4LTvUq-A.png" /></figure><p>Ditch simple NavigationLink’s and build a scalable, testable, and centralized routing system using NavigationStack from SwiftUI 4+.</p><h3>Introduction: The Inevitable Chaos and the Search for a Solution</h3><p>When we start developing with SwiftUI, using NavigationLink(&quot;Detail&quot;, destination: DetailView())feels like magic. It&#39;s simple and effective. But as your application grows, this magic begins to turn into a &quot;spaghetti code&quot; nightmare. The NavigationLink’s stretching from one View to another quickly become unmanageable.</p><p>But what if you need to send a user directly to a screen three levels deep in your app when they tap on a notification? Or what if, after a purchase is completed, you need to dismiss all intermediate screens and return the user to the home page?</p><p>This is where simple navigation methods fall short, and we need a more architectural solution: The <strong>Router (or Coordinator) Pattern.</strong> In this article, we will explore step-by-step, with code examples, how to build this modern and powerful structure using NavigationStack.</p><h3><strong>1. The Models: The Data Foundation of the App</strong></h3><p>First, let’s define the data structures (models) that our application will use. These are simple structures that carry data between our screens.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/58db5db9625a6360dc134632ff30f8d6/href">https://medium.com/media/58db5db9625a6360dc134632ff30f8d6/href</a></iframe><h4><strong>Why Identifiable and Hashable?</strong></h4><ul><li><strong>Identifiable:</strong> This protocol allows SwiftUI views like List to uniquely identify each element (thanks to its id property).</li><li><strong>Hashable:</strong> This protocol is mandatory for NavigationStack to be able to distinguish each screen (route) from one another. In the background, NavigationStack uses these &quot;hash&quot; values to determine which screen to display.</li></ul><h3>2. The RouteType Enum: The Brain of Our Navigation</h3><p>This is the heart of the system. It manages all possible screen destinations in the app and how to reach them from a single, central point.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/107d3a9861cc61f394a0238bc334f70c/href">https://medium.com/media/107d3a9861cc61f394a0238bc334f70c/href</a></iframe><h4><strong>What This Enum Does:</strong></h4><ul><li><strong>Centralized Directory of Routes:</strong> It allows us to manage all possible navigation destinations from a single place. When we want to add a new screen, we simply add a new case here.</li><li><strong>Type-Safe Data Passing:</strong> The definition case product(ProductModel) ensures that whenever we want to navigate to a product detail page, the compiler forces us to provide a ProductModel. This prevents errors like trying to open a screen without the necessary data.</li><li><strong>A View Factory:</strong> The destination function creates the correct View based on the incoming route. This way, ContentViewdoesn&#39;t need to know how ProductDetailView is created.</li></ul><h3>3. ContentView: The Starting Point of Navigation</h3><p>This is where we set up our NavigationStack and create the initial links that begin the user&#39;s journey.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3bf8202eae3f513ee0f88772d22fdf9c/href">https://medium.com/media/3bf8202eae3f513ee0f88772d22fdf9c/href</a></iframe><p><strong>Summary of the Flow (for </strong><strong>ContentView):</strong></p><ol><li>The user taps the NavigationLink for &quot;iPhone 17&quot;.</li><li>Instead of navigating to a destination, the link takes the RouteType.product(iphone17Model) from its value property.</li><li>It adds this value to the $path array, which is bound to the NavigationStack. The path array now becomes [.product(iphone17Model)].</li><li>NavigationStack detects that the path array has changed.</li><li>The .navigationDestination block is triggered. It receives the RouteType.product(iphone17Model) value as its route parameter.</li><li>The code route.destination(path: $path) is called, which in turn executes the switch block inside the RouteType enum.</li><li>The .product case matches, and a ProductDetailView(product: iphone17Model, path: $path) is created and pushed onto the screen.</li></ol><h3>4. Detail Screens and Deep Navigation</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bae154a32dc0bb99c439478e478e65d0/href">https://medium.com/media/bae154a32dc0bb99c439478e478e65d0/href</a></iframe><p><strong>Flow in </strong><strong>ProductDetailView:</strong></p><ol><li>The user taps the “See Review” button.</li><li>The button’s action executes path.append(.review(review)) on the path array, which is connected via @Binding.</li><li>The path array is now updated to: [.product(iphone17Model), .review(theRelevantReviewModel)].</li><li>The NavigationStack in ContentView detects this change once again!</li><li>The .navigationDestination block is triggered again. This time, the incoming route value is RouteType.review(theRelevantReviewModel).</li><li>The route.destination(...) function is called, and this time, a ReviewDetailView is created and pushed onto the screen.</li></ol><p>Thanks to this structure, each screen doesn’t need to know what the next screen is. It simply says, “I want to add this route,” and the central system handles the rest.</p><h3>5. Full Control Over Navigation: Going Back and Popping to Root</h3><p>One of the greatest advantages of this structure is the power to control navigation programmatically. We can manage not only forward navigation but also backward actions.</p><h4>Going Back to the Previous Screen (Pop)</h4><p>To return the user to the previous screen, we simply need to remove the last element from the path array. This is perfect for custom &quot;Back&quot; buttons or automatic returns after a specific action.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a26da14c160d122ca19d2d14e1ddcb4d/href">https://medium.com/media/a26da14c160d122ca19d2d14e1ddcb4d/href</a></iframe><h4>Returning to the Home Screen (Pop to Root)</h4><p>In scenarios like completing an order or logging out, we might want to clear the entire navigation stack and return the user to the very beginning. To do this, we just need to clear the path array completely.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/173dd633afb80aaf10b5800618abdd57/href">https://medium.com/media/173dd633afb80aaf10b5800618abdd57/href</a></iframe><h3>6. Expanding the Router: Handling Sheets and FullScreenCovers</h3><p>In a real world application, we don’t just push new views onto a NavigationStack. We also present views modally, using sheets and full-screen covers. You can easily extend your Router to manage these presentations as well. This addition will turn your article into a resource for creating an advanced navigation system.</p><h4>Extending the RouteType Enum</h4><p>First, we add new cases to our RouteType to represent the modal views we want to present.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9c17f93dcda2b102c0018c82dae587b0/href">https://medium.com/media/9c17f93dcda2b102c0018c82dae587b0/href</a></iframe><h4>Managing Modal State</h4><p>For modal presentations, we need a separate state variable because they are not part of the NavigationStack&#39;s path. We&#39;ll create a new optional state variable to hold the sheet we want to show.</p><p>To use the .sheet(item:...) modifier, our RouteType also needs to conform to the Identifiable protocol.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bbaf3548b4c81afd859a6c78e4042739/href">https://medium.com/media/bbaf3548b4c81afd859a6c78e4042739/href</a></iframe><p>The same logic applies perfectly to .fullScreenCover(item: $...) for presenting full screen modal views.</p><h3>Conclusion: Why You Should Adopt This Approach</h3><p>While it might seem a bit complex at first, this Router pattern provides a truly comprehensive solution for all your navigation needs. The key advantages of this holistic structure are:</p><ul><li><strong>Centralized Control:</strong> All navigation logic, from push navigations to modal sheets, is consolidated within the RouteType enum. To add a new screen or a new flow, you only need to edit a single file.</li><li><strong>Decoupling and Flexibility:</strong> Views don’t need to know about each other. This allows you to develop, test, and reuse screens independently.</li><li><strong>Programmatic Navigation:</strong> You can trigger any navigation from anywhere in your code without user interaction, such as after a push notification is received or an API call completes.</li><li><strong>Ease of Testing:</strong> You can test your entire user flow, including modal presentations, just by manipulating your state variables, even without a UI.</li><li><strong>Scalability:</strong> Even if you add dozens of new screens and presentation styles to your project, this structure will remain organized and manageable.</li></ul><p>In short, I highly recommend adopting this navigation architecture to build clean, maintainable, and professional codebases in your SwiftUI projects.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a38349198702" width="1" height="1" alt=""><hr><p><a href="https://medium.com/icommunity/the-swiftui-navigation-architecture-that-will-save-your-projects-the-router-pattern-a38349198702">The SwiftUI Navigation Architecture That Will Save Your Projects: The Router Pattern</a> was originally published in <a href="https://medium.com/icommunity">iCommunity</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[State Management in Flutter: Writing Clean Code with BLoC and Cubit]]></title>
            <link>https://medium.com/@yunusoktaydev/state-management-in-flutter-writing-clean-code-with-bloc-and-cubit-f9d6d803ef10?source=rss-2b8b1d27be90------2</link>
            <guid isPermaLink="false">https://medium.com/p/f9d6d803ef10</guid>
            <category><![CDATA[clean-code]]></category>
            <category><![CDATA[state-management]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[flutter-development]]></category>
            <category><![CDATA[bloc-architecture]]></category>
            <dc:creator><![CDATA[Yunus Oktay]]></dc:creator>
            <pubDate>Fri, 22 Aug 2025 13:48:54 GMT</pubDate>
            <atom:updated>2025-08-22T13:48:54.204Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ABRk3ZRpv_BiiwJdOc43ZQ.png" /></figure><p>One of the biggest challenges we face when developing Flutter applications is effectively managing the application’s state. Especially as our application grows, separating the user interface from business logic becomes increasingly critical. This is where the flutter_bloc package comes into play.</p><h3>What is BLoC Architecture?</h3><p>BLoC (Business Logic Component) is an architectural pattern developed by Google and adopted by the Flutter community. Its main purpose is to enable us to write more testable, reusable, and maintainable code by completely separating the application’s business logic from the user interface.</p><p>The working principle of BLoC architecture is quite simple:</p><ol><li>User performs an action (presses a button, fills out a form)</li><li>This action is sent to the BLoC as an Event</li><li>BLoC processes the event and produces a new State</li><li>UI updates itself according to this new state</li></ol><h3>Understanding the Core Concepts</h3><h4>Event</h4><p>Events represent occurrences in the application. Situations like user pressing a button, initiating an API call, or submitting form data are all events.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/88bf8b2206109c15f9baea1f8b1b1633/href">https://medium.com/media/88bf8b2206109c15f9baea1f8b1b1633/href</a></iframe><h4>State</h4><p>State represents the current condition of the application. Information like counter value, loading status, error messages are kept within the state.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/57d443b0e309f3919caae5769486f1c5/href">https://medium.com/media/57d443b0e309f3919caae5769486f1c5/href</a></iframe><h4>Bloc</h4><p>Bloc is the class that listens to events and produces new states in response. All business logic resides here.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/300b4246d9d4dcb30a5d392e37c6081d/href">https://medium.com/media/300b4246d9d4dcb30a5d392e37c6081d/href</a></iframe><h3>Connecting UI with BLoC</h3><p>After creating our BLoC, let’s see how to use it with Flutter widgets.</p><h4>BlocProvider</h4><p>Used to provide BLoC to the widget tree:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cd429cc702fd4181a2433c479da46b1b/href">https://medium.com/media/cd429cc702fd4181a2433c479da46b1b/href</a></iframe><h4>BlocBuilder</h4><p>Listens to state changes and updates the UI:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c2d89233c7227fed72bac039bcb04607/href">https://medium.com/media/c2d89233c7227fed72bac039bcb04607/href</a></iframe><h3>Cubit: BLoC’s Simple Sibling</h3><p>ometimes all the features that BLoC offers can be overwhelming. Especially in simple state management scenarios, defining events can cause unnecessary code bloat. This is where Cubit comes into play.</p><p>Cubit is the simpler version of BLoC. There’s no event concept; state changes are made by directly calling methods.</p><h4>Same Counter App with Cubit</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4339e89169cd71699905dc73e89755eb/href">https://medium.com/media/4339e89169cd71699905dc73e89755eb/href</a></iframe><p>Usage on the UI side is almost identical:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f2fe182cb0f931d21c3cffcdff301c28/href">https://medium.com/media/f2fe182cb0f931d21c3cffcdff301c28/href</a></iframe><h3>BLoC vs Cubit: Which Should You Choose?</h3><h4>Use BLoC If:</h4><ul><li>You have complex business logic</li><li>You have many different event types</li><li>You want to track the history of events</li><li>You want a more strict architectural structure</li></ul><h4>Use Cubit If:</h4><ul><li>Simple state management is sufficient</li><li>You’re doing rapid prototyping</li><li>You want to write less code</li><li>You don’t need the event concept</li></ul><h3>Real World Example: User List</h3><p>As a more realistic example, let’s write a Cubit that fetches a user list from an API:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6d3de96bff70245d27a294667566205b/href">https://medium.com/media/6d3de96bff70245d27a294667566205b/href</a></iframe><h3>Advantages of BLoC</h3><ol><li>Separation of Concerns: Business logic and UI are completely separated</li><li>Testability: BLoCs can be easily unit tested</li><li>Reusability: The same BLoC can be used on different pages</li><li>Scalability: It’s easy to maintain structure in large projects</li><li>Reactive Programming: Reactive programming thanks to stream-based structure</li></ol><h3>Conclusion</h3><p>The flutter_bloc package offers excellent solutions for both simple and complex scenarios for state management in Flutter. You can start quickly with Cubit and transition to BLoC when needed.</p><p>Most importantly, whichever approach you choose, your code will be cleaner, testable, and maintainable. In modern Flutter development processes, BLoC architecture has become an indispensable part of professional projects.</p><p>Remember: The best architecture is the one that best fits your project’s needs. Starting simple and increasing complexity when necessary is always a better strategy.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f9d6d803ef10" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering Object-Oriented Programming in Dart: A Complete Guide for Flutter Developers]]></title>
            <link>https://medium.com/@yunusoktaydev/mastering-object-oriented-programming-in-dart-a-complete-guide-for-flutter-developers-a49a0db4145c?source=rss-2b8b1d27be90------2</link>
            <guid isPermaLink="false">https://medium.com/p/a49a0db4145c</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[object-oriented]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[dart]]></category>
            <dc:creator><![CDATA[Yunus Oktay]]></dc:creator>
            <pubDate>Sat, 31 May 2025 14:02:46 GMT</pubDate>
            <atom:updated>2025-05-31T14:02:46.917Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XMrSOR1d2Q10mqCdMI_r_g.png" /></figure><p>Dart is a modern programming language developed by Google and forms the foundation of the Flutter framework. With its strong OOP support, it’s an ideal language for developing complex and scalable applications. In this guide, we’ll examine Dart’s OOP features with detailed examples.</p><h3>Basic Concepts of OOP</h3><h4>1. Encapsulation</h4><p>Encapsulation is the principle of keeping a class’s data and methods together while protecting them from external access. In Dart, variables and methods starting with an underscore (_) are considered private.</p><p><strong>Example: E-commerce Product Management</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9b5f9c07dcab25ed7dd7694cbe674fe3/href">https://medium.com/media/9b5f9c07dcab25ed7dd7694cbe674fe3/href</a></iframe><h4>2. Inheritance</h4><p>Inheritance allows a class to inherit properties and behaviors from another class. This reduces code duplication and enables the creation of hierarchical structures.</p><p><strong>Example: School Management System</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/54dc5d6963bd50d5475d61812adea6cd/href">https://medium.com/media/54dc5d6963bd50d5475d61812adea6cd/href</a></iframe><h4>3. Polymorphism</h4><p>Polymorphism allows different classes using the same interface to exhibit different behaviors. There are two types: runtime and compile-time polymorphism.</p><p><strong>Example: Media Player System</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/42785652a075818f918db6e253ea28ed/href">https://medium.com/media/42785652a075818f918db6e253ea28ed/href</a></iframe><h4>4. Abstraction</h4><p>Abstraction is the principle of simplifying complex systems by showing only necessary details. In Dart, it’s achieved through abstract classes and interfaces.</p><p><strong>Example: Vehicle Rental System</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fba4a8a6a850a4bfe7a1e4ae5ca6c219/href">https://medium.com/media/fba4a8a6a850a4bfe7a1e4ae5ca6c219/href</a></iframe><h3>Advanced OOP Concepts</h3><h4>Mixins</h4><p>Mixins in Dart provide a multiple inheritance-like structure and facilitate code sharing.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/12b330b855ef9b4d9a6262b6f7ee82fb/href">https://medium.com/media/12b330b855ef9b4d9a6262b6f7ee82fb/href</a></iframe><h4>Extension Methods</h4><p>Extension methods allow us to add new functionality to existing classes.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4f6dde04a30b1d54a0cf803a96e867b3/href">https://medium.com/media/4f6dde04a30b1d54a0cf803a96e867b3/href</a></iframe><h3>OOP Applications in Flutter</h3><p>In Flutter, OOP principles are heavily used in widget structure and state management. Widgets are defined as classes, and powerful UI structures are created using OOP techniques such as inheritance and composition.</p><p>This guide has explained the fundamentals and advanced features of OOP in Dart with comprehensive examples. By understanding these principles, you can develop cleaner, more maintainable, and scalable Flutter applications.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a49a0db4145c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Write Effective Swift Documentation in Xcode — Part Two]]></title>
            <link>https://medium.com/icommunity/how-to-write-effective-swift-documentation-in-xcode-part-two-5425b636418d?source=rss-2b8b1d27be90------2</link>
            <guid isPermaLink="false">https://medium.com/p/5425b636418d</guid>
            <category><![CDATA[documentation]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[ios-development]]></category>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Yunus Oktay]]></dc:creator>
            <pubDate>Wed, 26 Mar 2025 14:34:44 GMT</pubDate>
            <atom:updated>2025-03-26T14:42:59.403Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to Write Effective Swift Documentation in Xcode — Part Two</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cO8MNVDqGZgRtjIqywg3Ew.png" /></figure><p>If you haven’t read my first article on this topic, you can check it out here: <a href="https://medium.com/icommunity/how-to-write-effective-swift-documentation-in-xcode-e34793463cb9">How to Write Effective Swift Documentation in Xcode</a>.</p><p>Clear documentation is crucial for making your Swift code more understandable and maintainable. Xcode allows you to document your code efficiently using <strong>Markdown</strong> within multi-line comments. This helps developers read and navigate the codebase more easily.</p><h3>Using Markdown in Swift Documentation</h3><p>Xcode supports <strong>Markdown</strong> in comments, allowing you to format text effectively.</p><p>For example, you can structure documentation like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/10a9f5a894f5ade4a17dbe1d30d82c2d/href">https://medium.com/media/10a9f5a894f5ade4a17dbe1d30d82c2d/href</a></iframe><p>Here, the <strong>User struct</strong> is documented using Markdown, making it easier to understand. This style of documentation will appear in Xcode’s <strong>Quick Help</strong> panel, allowing developers to quickly grasp the functionality of the code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/260/1*kEQSsLTGo1RXYDBK3_RoOw.png" /></figure><h3>Understanding the greeting(person:) Function Documentation</h3><p>The greeting(person:) function is a well-documented example of how to handle function comments in Swift. Let’s break it down:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fd0fb7a20f2f93f2391e800ec1b27a6b/href">https://medium.com/media/fd0fb7a20f2f93f2391e800ec1b27a6b/href</a></iframe><h4>1. Summary</h4><ul><li><em>“A way that this user greets others.”</em></li><li>This brief description provides an overview of the function’s purpose, which is to generate a greeting for a given user.</li></ul><h4>2. Discussion</h4><ul><li>The function only uses the firstName and lastName properties of the User object, meaning the person parameter does not influence the greeting in any other way.</li><li>The explanation helps developers understand the function’s behavior before using it.</li></ul><h4>3. Warning (- Warning:)</h4><ul><li>The function specifies that the greeting will always follow the caller’s localization settings.</li><li>This is important for developers working with multilingual applications.</li></ul><h4>4. Error Handling (- Throws:)</h4><p>The function can throw two different errors:</p><ul><li>MyError.invalidPerson → If the person is not recognized by the caller.</li><li>MyError.hardToPronounce → If the person’s name exceeds 20 characters, making it difficult to pronounce.</li></ul><p>This section informs developers of possible exceptions they need to handle when calling the function.</p><h4>5. Parameter (- Parameter:)</h4><ul><li>The function takes a User object as input, which represents the person being greeted.</li></ul><h4>6. Return Value (- Returns:)</h4><ul><li>Returns a simple greeting string in the format: &quot;Hello [First Name] [Last Name]&quot;.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/294/1*RwSjy3hKJXNyEE_g6M-ffg.png" /></figure><h3>Additional Documentation Callouts</h3><p>You can enhance documentation using <strong>callout tags</strong>, which provide extra information. These callouts are displayed as bold headers in <strong>Quick Help</strong>.</p><p>Example syntax:</p><pre>- Callout: description</pre><p>Here are some commonly used callouts:</p><ul><li><strong>Attention:</strong> Important details developers should not overlook.</li><li><strong>Author:</strong> Notes the original author of the code.</li><li><strong>Bug:</strong> Highlights known issues.</li><li><strong>Complexity:</strong> Explains the time or space complexity of an algorithm.</li><li><strong>Deprecated:</strong> Marks code that is outdated.</li><li><strong>Experiment:</strong> Identifies experimental features.</li><li><strong>Important:</strong> Flags significant details about usage.</li><li><strong>Note:</strong> Adds useful comments.</li><li><strong>Todo:</strong> Lists tasks for future improvements.</li><li><strong>Version:</strong> Specifies the version of the feature.</li><li><strong>Warning:</strong> Highlights risks or potential issues.</li></ul><p>Example:</p><pre>/// - Warning: This function may slow down performance on large datasets.</pre><h3>Conclusion</h3><p>Over time, even the most familiar code can become difficult to understand — whether for your team or your future self. Writing clear, structured documentation ensures that your code remains maintainable, readable, and easy to work with.</p><p>While documenting can feel time-consuming, it ultimately saves time by reducing confusion and making it easier to onboard new developers. By using <strong>Markdown formatting, structured comments, and Xcode’s auto-documentation features</strong>, you can create high-quality documentation that enhances your development workflow.</p><p>Investing in good documentation today will pay off in the long run. 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5425b636418d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/icommunity/how-to-write-effective-swift-documentation-in-xcode-part-two-5425b636418d">How to Write Effective Swift Documentation in Xcode — Part Two</a> was originally published in <a href="https://medium.com/icommunity">iCommunity</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Imperative vs. Declarative UI Development: A Comparison of UIKit and SwiftUI]]></title>
            <link>https://medium.com/icommunity/imperative-vs-declarative-ui-development-a-comparison-of-uikit-and-swiftui-4bc96b5d8684?source=rss-2b8b1d27be90------2</link>
            <guid isPermaLink="false">https://medium.com/p/4bc96b5d8684</guid>
            <category><![CDATA[imperative-programming]]></category>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[uikit]]></category>
            <category><![CDATA[programming-paradigms]]></category>
            <category><![CDATA[declarative-programming]]></category>
            <dc:creator><![CDATA[Yunus Oktay]]></dc:creator>
            <pubDate>Fri, 14 Feb 2025 17:24:26 GMT</pubDate>
            <atom:updated>2025-02-14T17:24:26.871Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y421wPq0KZ2vLC79ypJvDQ.png" /></figure><h4><strong>Introduction</strong></h4><p>Modern iOS development revolves around two fundamental paradigms for creating user interfaces (UI): <strong>Imperative</strong> and <strong>Declarative</strong>. Apple’s two major UI frameworks — UIKit and SwiftUI — embody these approaches respectively. In this article, we’ll explore how each paradigm works, discuss their advantages and disadvantages, and highlight scenarios in which one might be preferred over the other.</p><h3>Imperative UI (UIKit)</h3><p><strong>Imperative programming</strong> is an approach where the developer explicitly defines step-by-step instructions for creating and updating UI elements. With UIKit, you manually configure each detail — setting properties, adding actions, and defining layout constraints one by one.</p><h4>Characteristics</h4><ul><li><strong>Manual Control:</strong> Every UI component’s properties (such as color, size, and position) are defined explicitly in code.</li><li><strong>State Management:</strong> When data changes, the UI must be updated manually (for example, updating the title or appearance of a button).</li><li><strong>Lifecycle Management:</strong> The lifecycle methods of views (like viewDidLoad and viewDidAppear) are controlled manually by the developer.</li></ul><h4>Example in UIKit (Login Button)</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5f194b4738f9327353914fd47b2119d5/href">https://medium.com/media/5f194b4738f9327353914fd47b2119d5/href</a></iframe><h4>Advantages</h4><ul><li><strong>Flexibility:</strong> Offers complete control over every detail of the UI.</li><li><strong>Maturity:</strong> Millions of apps have been built using UIKit, proving its robustness.</li></ul><h4>Disadvantages</h4><ul><li><strong>Complexity:</strong> Requires many lines of code and manual state management.</li><li><strong>Error-Prone:</strong> Mistakes like missing constraints or misconfiguring actions are common.</li></ul><p><strong>Visual Flow:</strong><br>In UIKit, you can illustrate the component creation process with a flow diagram:</p><ol><li><strong>Component Creation</strong></li><li><strong>Setting Properties</strong></li><li><strong>Adding Target/Action</strong></li><li><strong>Adding to the View Hierarchy</strong></li><li><strong>Setting Constraints</strong></li></ol><h3>Declarative UI (SwiftUI)</h3><p><strong>Declarative programming</strong> allows the developer to describe what the UI should look like and how it should behave, while the framework automatically handles the details. SwiftUI is a modern, concise example of this paradigm.</p><h4>Characteristics</h4><ul><li><strong>Automatic Layout:</strong> Instead of manually setting constraints, you define your layout using stacks and alignment options.</li><li><strong>Reactive State Management:</strong> Property wrappers like @State and @Binding ensure that data changes are automatically reflected in the UI.</li><li><strong>Concise Syntax:</strong> Code is shorter, more readable, and easier to understand.</li></ul><h4>Example in SwiftUI (Login Button)</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/78f411fcc13e70c82e54820f0d6e0acc/href">https://medium.com/media/78f411fcc13e70c82e54820f0d6e0acc/href</a></iframe><h4>Advantages</h4><ul><li><strong>Speed and Less Code:</strong> Enables rapid development with fewer lines of code and minimal errors.</li><li><strong>Reactive:</strong> Data changes automatically update the UI.</li><li><strong>Platform Support:</strong> The same codebase can be deployed across iOS, macOS, watchOS, and tvOS.</li><li><strong>Live Preview:</strong> Xcode’s SwiftUI Live Preview allows you to see changes in real time.</li></ul><h4>Disadvantages</h4><ul><li><strong>Learning Curve:</strong> The declarative approach and SwiftUI-specific concepts (such as Combine and modifiers) can be challenging for beginners.</li><li><strong>Limitations:</strong> For highly customized or complex UI components, you might still need to rely on UIKit.</li><li><strong>iOS 13+ Only</strong>: Excludes older devices.</li></ul><p><strong>Visual Flow:</strong><br>In SwiftUI, you declare the UI in a single block, specifying what it should be rather than detailing every step. This can be summarized with a simple block diagram:</p><ul><li><strong>Declare UI Appearance</strong></li><li>Specify State and Interactions</li><li>Framework Manages the Rest</li></ul><h3>Comparison Table</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5vnXGnGk7HYVxk8w3Ezhyg.png" /></figure><h3>When to Use Which Approach</h3><h4>Choose UIKit (Imperative) When:</h4><ul><li>You are updating an existing UIKit project.</li><li>Custom UI components (e.g., custom drawings, complex animations) are needed.</li><li>Support for iOS 12 or earlier is required.</li></ul><h4>Choose SwiftUI (Declarative) When:</h4><ul><li>You are starting a new project.</li><li>You need rapid prototyping.</li><li>Cross-platform support (iOS, macOS, watchOS) is a priority.</li><li>You prioritize clean and modern code.</li></ul><h3>Hybrid Approach: Combining UIKit and SwiftUI</h3><p>Apple supports using both UIKit and SwiftUI together. This hybrid approach is ideal for gradually transitioning existing projects to SwiftUI or for using both frameworks within the same project.</p><ul><li><strong>UIHostingController:</strong> Used to host SwiftUI views within UIKit-based applications.</li><li><strong>UIViewRepresentable:</strong> Allows embedding UIKit components within SwiftUI.</li></ul><h3>Future Outlook</h3><ul><li><strong>SwiftUI 6.0</strong>: Expected to address navigation limitations (e.g., complex deep linking).</li><li><strong>Declarative Dominance</strong>: Apple’s investment suggests SwiftUI will eventually replace UIKit for new projects.</li></ul><h3>Conclusion</h3><p>Both approaches have their own strengths and use cases:</p><h4><strong>UIKit (Imperative):</strong></h4><ul><li><strong>Control and Flexibility:</strong> Provides detailed control over every aspect.</li><li><strong>Traditional Applications:</strong> Preferred for mature, complex projects.</li></ul><h4><strong>SwiftUI (Declarative):</strong></h4><ul><li><strong>Modern and Rapid Development:</strong> Offers reactivity and live previews with less code.</li><li><strong>Clean Code:</strong> Focuses on declaring what the UI should be rather than detailing how to build it step by step.</li></ul><p>While Apple continues to invest in SwiftUI, understanding both paradigms is essential for any iOS developer.</p><p>This article compares Imperative and Declarative UI development approaches through examples, advantages, and usage scenarios. It aims to help both beginners and experienced developers determine which method best suits their project needs.</p><h4>Poll: Which Do You Prefer?</h4><p>🗳️ <strong>UIKit</strong> | 🗳️ <strong>SwiftUI</strong><br><em>Share your choice in the comments!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4bc96b5d8684" width="1" height="1" alt=""><hr><p><a href="https://medium.com/icommunity/imperative-vs-declarative-ui-development-a-comparison-of-uikit-and-swiftui-4bc96b5d8684">Imperative vs. Declarative UI Development: A Comparison of UIKit and SwiftUI</a> was originally published in <a href="https://medium.com/icommunity">iCommunity</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Write Effective Swift Documentation in Xcode]]></title>
            <link>https://medium.com/icommunity/how-to-write-effective-swift-documentation-in-xcode-e34793463cb9?source=rss-2b8b1d27be90------2</link>
            <guid isPermaLink="false">https://medium.com/p/e34793463cb9</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[documentation]]></category>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Yunus Oktay]]></dc:creator>
            <pubDate>Sat, 25 Jan 2025 17:37:54 GMT</pubDate>
            <atom:updated>2025-01-25T17:58:15.719Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZeNQDZdhhXtBPLx2RjA4rA.png" /></figure><p>When we haven’t looked at the code we’ve written for a long time, we might forget what it does. Or, when using Apple’s classes and not knowing how to use them, we might resort to various methods to learn how to use them. We can find this information in documentation like Apple Developer Documentation or within Xcode.</p><h3>Quick help popover</h3><p>When you Option-click on any class, you get a quick help popover like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*ZKPUmB9_-5MCk7WrKguPJQ.gif" /></figure><h3>Symbol inspector Quick Help</h3><p>Quick help is also displayed under the quick helper inspector in the right-side toggle inspector.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*wbjg3Vg_UCaQbeZbs_-0YA.png" /></figure><h3>Code completion hint</h3><p>When you start typing code, Xcode shows you the functions, properties, and other capabilities of that class and provides a hint at the very bottom about what they do.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*yTtNJlzngleg6lJb_iOAgA.png" /></figure><h3>Command Line</h3><p>We should use comments for our code so that, when we come back to it after a long time or when another developer looks at it, they can understand what the code does.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*WyU87ZJQaC2gPoyOx0Ykkw.png" /></figure><p>To add multi-line documentation, you need to use an extra asterisk (*) in the opening delimiter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*J5yP8yC5XzG4Perxye5nTg.png" /></figure><h3>Summary and Discussion</h3><p>The above documentation comment will produce a document with a summary section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*3LFeUm6RniNqvNCgEyPR7g.png" /></figure><p>To add a discussion section, all you need to do is write another paragraph. Anything other than the first paragraph will belong in the discussion section.</p><p>If you want to add the sentence after the comma to the discussion section, just leave a blank line between the two sentences.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*D9kDuFMluZU0NmVSvG4dNQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*-53hiOdIFfECSFlEhTUacQ.png" /></figure><p>You can also use markdown in your documentation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RwmWl9igjeXmvuMtimRgWw.png" /></figure><p>The above documentation example will produce the following quick help:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x1oPTWi_PnUwKXMPTOuHiA.png" /></figure><h3>Conclusion</h3><p>In this article, the key message is that while writing good documentation takes time and effort, it is essential for maintaining understandable and maintainable code. Documentation helps both the original developer and others understand the code’s purpose and functionality, making collaboration easier and reducing the chance of errors. By using tools like quick help and markdown comments, developers can create clear, organized documentation. Though time-consuming, investing in documentation ultimately saves time and effort in the long run by making code easier to manage, refactor, and scale.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e34793463cb9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/icommunity/how-to-write-effective-swift-documentation-in-xcode-e34793463cb9">How to Write Effective Swift Documentation in Xcode</a> was originally published in <a href="https://medium.com/icommunity">iCommunity</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Generic Network Layer for iOS Apps]]></title>
            <link>https://medium.com/icommunity/building-a-generic-network-layer-for-ios-apps-5469d11324f0?source=rss-2b8b1d27be90------2</link>
            <guid isPermaLink="false">https://medium.com/p/5469d11324f0</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[ios-development]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Yunus Oktay]]></dc:creator>
            <pubDate>Sat, 21 Dec 2024 14:20:51 GMT</pubDate>
            <atom:updated>2024-12-29T14:59:33.754Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1-BrrrZycuUWeMzrNeW5rg.png" /></figure><p>Modern iOS applications often interact with multiple APIs, making efficient network request management critical. Instead of writing repetitive code for each network request, a generic and reusable network layer simplifies the process while ensuring scalability and maintainability. In this article, we’ll walk through the steps of designing such a network layer using Swift.</p><p>A generic network layer provides the flexibility to handle various data types while reducing code duplication. This tutorial will cover essential aspects like JSON parsing, error handling, and HTTP methods to build a robust network layer.</p><h3>Why Build a Generic Network Layer?</h3><p>A network layer abstracts the details of API communication, offering several benefits:</p><ul><li><strong>Abstraction:</strong> Separates API logic from the application’s core functionality, making the codebase cleaner.</li><li><strong>Code Reusability:</strong> Prevents repetitive code for each request.</li><li><strong>Type Safety:</strong> Leverages Swift’s strong type system for decoding responses and error handling.</li><li><strong>Scalability</strong>: As your app grows and interacts with more APIs, this structure makes it easier to expand without adding complex, redundant code.</li></ul><p>A generic approach allows us to reuse the same code for different data models and endpoints, reducing development time and potential errors.</p><h3>Designing the Network Layer</h3><h3>1. The Core Network Structure</h3><p>The Network structure manages all network requests and handles response decoding. Here’s the basic implementation:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/52af6bd37dad893ba1c10eb07bd11890/href">https://medium.com/media/52af6bd37dad893ba1c10eb07bd11890/href</a></iframe><p><strong>Key Points:</strong></p><ul><li><strong>Request Function</strong>: Decodes data into the desired generic type (e.g., Product).</li><li><strong>JSON Parsing</strong>: Utilizes Swift’s Codable protocol for type-safe decoding.</li><li><strong>Request</strong>: URLSession.shared.dataTask sends a request to the server and receives a response (data, response, error).</li><li><strong>Data Validation</strong>: The received data is checked, and if nil, the process terminates.</li><li><strong>JSON Decoding</strong>: The data is decoded into a generic type (T) using JSONDecoder.</li><li><strong>Result Handling</strong>:</li><li>On Success, The decoded data is passed via completion(.success(json)).</li><li>On Failure, An error is returned via completion(.failure(error)).</li></ul><p>This structure processes the incoming data and passes the result back to the caller.</p><h3>2. The RequestType Enum</h3><p>The RequestType enum centralizes API endpoint and HTTP method definitions.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ace261eabe88e1586cea716393a5e9d8/href">https://medium.com/media/ace261eabe88e1586cea716393a5e9d8/href</a></iframe><ul><li>The RequestType enum defines various API endpoints (e.g., /products, /addtocart/{cartId}/{productId}).</li><li>The endPoint property provides the URL path for each request type.</li><li>The httpMethod property defines the HTTP method for each request.</li></ul><p>This structure streamlines endpoint management and reduces hardcoding.</p><h3>3. HTTP Methods Enum</h3><p>Define an enum for HTTP methods to enhance type safety and readability:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/48ca21195f049da9893d0167416aaa85/href">https://medium.com/media/48ca21195f049da9893d0167416aaa85/href</a></iframe><p>The HttpMethod enum allows us to easily manage HTTP methods for our requests and avoids hardcoding strings like &quot;GET&quot; or &quot;POST&quot;.</p><h3>Defining Response Models</h3><p>API responses are typically in JSON format. To handle these responses, define Codable structures that map to the expected data:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1c931da1583bf3735fb404f60fae7b88/href">https://medium.com/media/1c931da1583bf3735fb404f60fae7b88/href</a></iframe><p>These structures model the responses from the API, ensuring that the data is processed correctly. Thanks to the Codableprotocol, JSON data can be easily converted into Swift objects.</p><h3>Practical Examples of Using the Generic Layer</h3><h4>1. Fetching Product Data</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5d38f261a20fd66ab7f2633cca17001d/href">https://medium.com/media/5d38f261a20fd66ab7f2633cca17001d/href</a></iframe><p>Here, the generic request function decodes the API response into BaseResponse&lt;[Product]&gt;.</p><p>The fetchProducts() function makes a network request to fetch a list of products using the Network struct.</p><ul><li>It calls the request method with the .products endpoint.</li><li>On success, if products are returned in the response, they are stored in the products array and the UI is updated on the main thread to reload the data in the collectionView.</li><li>On failure, it prints an error message.</li></ul><p>This function handles fetching product data and updating the UI accordingly.</p><h4><strong>2. Fetching Cart Data</strong></h4><p>In this second example, we use the same request function but with a different response type: BaseResponse&lt;CartResponse&gt;. This time, the API response includes cart information, which is handled by the CartResponse model.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8bb39849e5ff134834526c93cf423748/href">https://medium.com/media/8bb39849e5ff134834526c93cf423748/href</a></iframe><p>The network layer returns a BaseResponse&lt;CartResponse&gt; object containing cart details, enabling structured access to the data.</p><p>The fethCartData() function sends a network request to fetch cart data from the API.</p><ul><li>On success, when the API response is successfully received, the cart data is assigned to the cart property, and the UI is updated. The method also notifies that the operation is complete.</li><li>On failure, if an error occurs, the error message is printed to the console.</li></ul><p>This function is used to fetch cart data and perform necessary updates once the operation is completed.</p><h3>Integrating the Network Layer with the ViewModel</h3><p>In your CartViewModel, once the network layer is set up, you can easily fetch data by calling the fethCartData()function. The ViewModel will handle the logic for making network requests and updating the UI once the data is fetched.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0f9c6b0087a8c7c4fce84e29447a4863/href">https://medium.com/media/0f9c6b0087a8c7c4fce84e29447a4863/href</a></iframe><h4>What Happens Here?</h4><ul><li>viewModel.fetchCartData() is called to initiate a network request to fetch cart data.</li><li>Upon success, the cart property in the ViewModel is updated, and the UI is notified to refresh.</li><li>The delegate is used to inform the view controller that the cart operation is complete, ensuring proper UI updates and responsiveness.</li></ul><p>This approach ensures a clean separation between the network logic and the UI, promoting maintainability and testability.</p><h3>Integrating the ViewModel with the TableView</h3><p>To effectively display the fetched cart data in the UI, we use a UITableView. By implementing the UITableViewDelegateand UITableViewDataSource protocols in our CartVC, we bind the ViewModel&#39;s data to the table view. Here&#39;s how it works:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/71ec480558d310118054aa2cd3a7f757/href">https://medium.com/media/71ec480558d310118054aa2cd3a7f757/href</a></iframe><h3>Key Points:</h3><ol><li><strong>Data Binding</strong><br>The numberOfRowsInSection method dynamically determines the number of rows based on the products array in the ViewModel. This ensures that the table view updates automatically when the data changes.</li><li><strong>Cell Configuration</strong><br>In cellForRowAt, the reusable CartCell is dequeued and configured with the product data from the ViewModel. The delegate pattern is used to handle actions (e.g., button taps) inside the cell.</li><li><strong>Dynamic Row Height</strong><br>The heightForRowAt method sets a consistent row height for the cart items, enhancing the layout&#39;s visual consistency.</li></ol><p>By connecting the CartVC to the ViewModel and configuring the table view in this manner, the fetched data seamlessly integrates with the user interface. This approach ensures clean separation of concerns and keeps the UI logic manageable.</p><h3>Cart Operations with Protocols in the Network Layer</h3><p>Managing the network layer involves handling data and updating the UI. In this section, we’ll explore how CartVCinteracts with two protocols: CartCellProtocol and CartViewModelProtocol, to manage cart operations and update the UI accordingly.</p><p><strong>Interacting with Protocols</strong></p><p>The CartVC class implements both CartCellProtocol and CartViewModelProtocol. These protocols manage cart operations, such as removing products from the cart and updating the UI.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1031cf37ece0667af2006285f4cae212/href">https://medium.com/media/1031cf37ece0667af2006285f4cae212/href</a></iframe><p><strong>Method Descriptions:</strong></p><ol><li>removeProduct(id:): This method is called when a product needs to be removed from the cart. It triggers the viewModel.removeProduct(id:) method to handle the removal, then reloads the table view to reflect the changes.</li><li>didFinishCartOperation(): After a cart operation is completed (e.g., removing a product or completing a purchase), this method reloads the table view to update the UI. It’s called after the cart operation finishes.</li><li>removeProduct(): This method is called when the view model signals that a product has been removed from the cart. Like didFinishCartOperation(), it reloads the table view to update the UI.</li><li>buyCart(): This method will handle the checkout process when the user decides to buy the items in their cart. It can trigger actions such as processing payment or navigating to a checkout screen.</li></ol><p><strong>UI Updates</strong></p><p>For all of these methods, UI updates are done on the main thread using DispatchQueue.main.async. This ensures that the UI is updated smoothly and correctly after each operation.</p><p>With this approach, we successfully retrieved the data and integrated it into the UI components.</p><h3>Conclusion</h3><p>In this article, we explored how to build a <strong>generic network layer</strong> for iOS applications. By leveraging <strong>generics</strong>, we created a flexible and reusable solution that reduces repetitive code and enhances maintainability. With a type-agnostic approach, we handled different data types in a clean, modular, and scalable manner.</p><p>The examples demonstrated the power of generics in managing diverse API responses, such as product and cart data, using the same core structure. By adopting this approach, you can streamline your network operations while maintaining a robust and error-resistant codebase.</p><p>Full project → <a href="https://github.com/yunusoktay/Eticaret">https://github.com/yunusoktay/Eticaret</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5469d11324f0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/icommunity/building-a-generic-network-layer-for-ios-apps-5469d11324f0">Building a Generic Network Layer for iOS Apps</a> was originally published in <a href="https://medium.com/icommunity">iCommunity</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>