<?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 Rivaldo Fernandes on Medium]]></title>
        <description><![CDATA[Stories by Rivaldo Fernandes on Medium]]></description>
        <link>https://medium.com/@rivaldofez?source=rss-391d363fd29c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*h8A7tZ0x1UWifTWIED2Znw.png</url>
            <title>Stories by Rivaldo Fernandes on Medium</title>
            <link>https://medium.com/@rivaldofez?source=rss-391d363fd29c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 12:54:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rivaldofez/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[Enabling and Customizing Swipe-Back Navigation in UIKit iOS]]></title>
            <link>https://medium.com/@rivaldofez/enabling-and-customizing-swipe-back-navigation-in-uikit-ios-7343b671e32a?source=rss-391d363fd29c------2</link>
            <guid isPermaLink="false">https://medium.com/p/7343b671e32a</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[uikit]]></category>
            <category><![CDATA[navigation]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Rivaldo Fernandes]]></dc:creator>
            <pubDate>Thu, 18 Sep 2025 18:50:12 GMT</pubDate>
            <atom:updated>2025-09-18T18:50:12.361Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vgah955VJi7muQQJhp2Nnw.png" /><figcaption>Header Illustration</figcaption></figure><p>As an iOS Developer who started mobile application development as an Android Developer, I just found out a quite tricky simple behavior about back navigation, while in Android you can access the native back button provided by the Android system (either button or gesture), but in iOS you can only access native back behavior by gesture, but with a lot of limitations. In this article, let’s getting know more about this behavior and how to implement it into your iOS App</p><h3><strong>Introduction</strong></h3><p>Maybe in an iPhone app, you commonly use this gesture in some applications such as Mail, Messages, or Settings by swiping inward from the left edge of the screen to the right, then the previous screen slides back into view smoothly. This is called interactive pop navigation in UIKit, one of the signature iOS gestures for moving backward through a stack hierarchy.</p><p>In general, swipe-back navigation is powered by two main elements:</p><h4>1. <a href="https://developer.apple.com/documentation/uikit/uinavigationcontroller">UINavigationController</a> and its View Controller Stack</h4><p>Each time you push a view controller onto a UINavigationController, you add it to the stack. Refer to the official documentation, a navigation controller object manages the view controllers using an ordered array, known as the navigation stack. The top of the stack is the view controller that you currently see, and the one underneath is the previous screen, and so on. When you swipe back, you are essentially popping the view controller at the top of the stack and revealing the one underneath</p><h4>2. interactivePopGestureRecognizer</h4><p>The navigation controller actually puts this gesture recognizer on its view and uses it to pop the view controller on top of the navigation stack. This recognizer listens for the user’s swipe from the left edge of the screen, and then animates the pop transition interactively, meaning that the user controls the speed of the animation and makes the behavior look legit.</p><p>You don’t need to do anything, actually, to enable swipe-back. Just simply using UINavigationController, push a view controller, keep the default back button and navigation bar visible, and the gesture “just works.”. But as a great iOS Developer, you can’t just be normal, especially when you have to follow your designer’s beyond imagination desires to create a very weird navigation bar, and as a result, you sometimes feel confused why the gesture stops working when there is a customization in the navigation.<br>In the next section, we’ll look at why swipe back sometimes breaks and what you can do to bring it back.</p><h3>Why does it break?</h3><p>Maybe you have some questions in your mind, if normal swipe-back navigation “just-works”, why could a little change make it break?. The truth is, UIKit’s default back navigation &amp; header behavior works under several conditions. When you change any of them, the gesture can disappear or become unreliable. Understanding these conditions is the first step to fixing them. Here are the most common reasons why the swipe-back gesture stops working:</p><h4>1. Custom Back Button</h4><p>When you use your own <em>navigationItem.leftBarButtonItem</em> (or replace the back button image), UIKit will assume that you handle manual the back action by yourself and disable the built in gesture recognizer</p><h4>2. Navigation Bar Hidden</h4><p>When you call <em>navigationController?.setNavigationBarHidden(true, animated:)</em>, UIKit removed the default back button and also disable the swipe-back gesture unless you re-enable it manually</p><h4>3. Gesture Recognizer Disabled Programmatically</h4><p>When you use <em>interactivePopGestureRecognizer?.isEnabled</em> and set the value <em>false</em>, it would tell UIKit to disable the gesture swipe back</p><h4>4. Conflicting Gesture Recognizers</h4><p>If you add you own others gestures (for example pan gesture for side menu), the gesture maybe overlap and can interfere the built in gesture unless you manually coordinate the implementation delegates</p><h4>5. There is only one View Controller in the Stack</h4><p>Obviously when you navigation stack consist only one view controller or screen, there is no screen to be pop and the gesture won’t begin</p><h3>How to Enable and Customize Swipe-Back in UIKit</h3><p>Now that you know why swipe-back sometimes disappears, let’s bring it back under your control. UIKit exposes the gesture recognizer powering this feature through a property on <em>UINavigationController: interactivePopGestureRecognizer</em>. By working with this recognizer directly, you can re-enable swipe-back, customize when it fires, and avoid most pitfalls.</p><p>Here’s the core idea:</p><ol><li>Enable the recognizer:</li></ol><pre>navigationController?.interactivePopGestureRecognizer?.isEnabled = true</pre><p>2. Assign a delegate:</p><pre>navigationController?.interactivePopGestureRecognizer?.delegate = self</pre><p>3. Decide when it should begin:</p><pre>func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -&gt; Bool {<br>    return navigationController?.viewControllers.count ?? 0 &gt; 1<br>}</pre><p>These three steps do 90% of the work. Once you’ve done this in a view controller, swipe-back will work even if you’ve customized the back button or hidden the navigation bar. In some cases, when you have to implement all three steps in every view controller, it would be a boilerplate if you put the code in each of your view controllers. You can simplify it by creating a top-level parent as a base view controller and implement it in that, then you just need to set each of your view controllers to inherit from that base class.</p><h3>Enhance Swipe Back Gesture with Stack Manipulation &amp; Fully Customize Navigation Header</h3><p>At this moment, maybe you think that the natively swipe-back gesture is already perfect and covers all your cases. If you are familiar with the function <em>popToViewController</em> you can start questioning, is it possible to swipe back and return to not only one screen before but also return to the specific screen we want in the navigation stack?</p><p>The answer absolutely yes, you can use swipe back gesture to specific screen as long as the view controller already in the navigation stack by utilizing custom <em>UIViewControllerAnimated</em> and <em>popToViewController()</em>. Without any further a do, let’s start do it :)</p><h4>1. Create Custom Pop Animator</h4><p>A custom animator is used to replace the default push / pop animation of <em>UINavigationController</em>. Your custom pop animator must conform to <em>UIViewControllerAnimatedTransitioning</em> and added to <em>UINavigationController</em>. The main idea of this custom pop animator is to define <em>what the transition looks like</em></p><pre>class CustomPopVCAnimator: NSObject, UIViewControllerAnimatedTransitioning {<br>    let duration: TimeInterval = 0.3 //Interval swipe transition duration<br><br>    func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -&gt; TimeInterval {<br>        return duration<br>    }<br><br>    func animateTransition(using context: UIViewControllerContextTransitioning) {<br>        guard let fromVC = context.viewController(forKey: .from),<br>              let toVC = context.viewController(forKey: .to) else {<br>            context.completeTransition(false)<br>            return<br>        }<br><br>        let container = context.containerView<br>        container.insertSubview(toVC.view, belowSubview: fromVC.view)<br><br>        let width = fromVC.view.frame.width<br>        toVC.view.frame = fromVC.view.frame.offsetBy(dx: -width / 3, dy: 0)<br><br>        UIView.animate(withDuration: duration, animations: {<br>            fromVC.view.frame = fromVC.view.frame.offsetBy(dx: width, dy: 0)<br>            toVC.view.frame = toVC.view.frame.offsetBy(dx: width / 3, dy: 0)<br>        }, completion: { finished in<br>            context.completeTransition(!context.transitionWasCancelled)<br>        })<br>    }<br>}</pre><h4>2. Create Interaction Controller</h4><p>This interaction controller is used to control the progress of the animation interactively when the user starts the gesture. You must create interaction controller as part of <em>UIPercentDrivenInteractiveTransition</em></p><pre>var interactiveTransitionController: UIPercentDrivenInteractiveTransition?</pre><h4>3. Create Custom Gesture Recognizer</h4><p>You must create custom recognizer using <em>UIScreenEdgePanGestureRecognizer</em> to listen user swipe-back action from the left edge</p><pre>var swipeBackPanGesture: UIScreenEdgePanGestureRecognizer?</pre><h4>4. Create Custom Navigation Header</h4><p>If you have custom navigation header across all screens or view controllers, you can define it here, or using share outlet if you used XIB</p><pre>//Custom Navigation Header, you can create by yourself or use from this article repo<br>let navHeader = NavigationHeader() </pre><h4>5. Setting up Custom Navigation Header</h4><p>If you used custom navigation header, make sure to disable built in navigation header, this navigation header also become a condition if the behavior need to be same like native navigation header, we can check visibility, icon or action of the custom navigation header to determine the gesture recognizer</p><pre>private func setupNavHeader() {<br>        navigationController?.setNavigationBarHidden(true, animated: false)<br>        view.addSubview(navHeader)<br>        NSLayoutConstraint.activate([<br>            navHeader.leadingAnchor.constraint(equalTo: view.leadingAnchor),<br>            navHeader.trailingAnchor.constraint(equalTo: view.trailingAnchor),<br>            navHeader.topAnchor.constraint(equalTo: view.topAnchor)<br>        ])<br>        navHeader.leftButtonAction = { [weak self] in<br>            self?.navigationController?.popViewController(animated: true)<br>        }<br>    }</pre><h4>6. Setting up SwipeBack Gesture Recognizer</h4><p>At this part, we setup the screen edge pan gesture recognizer to listen user gesture and execute action to run</p><pre>//Method to setup swipe back gesture related to the visibility of BackButton in navigation header and it&#39;s action<br>    func setupSwipeBackGesture() {<br>        navigationController?.interactivePopGestureRecognizer?.isEnabled = false<br>            if navHeader.leftButton.isHidden == false &amp;&amp; navHeader.leftButtonAction != nil {<br>                if swipeBackPanGesture == nil {<br>                    swipeBackPanGesture =  UIScreenEdgePanGestureRecognizer(target: self, action: #selector(swipeBackPanGestureAction(_:)))<br>                    swipeBackPanGesture?.edges = .left<br>                    if let gesture = swipeBackPanGesture {<br>                        view.addGestureRecognizer(gesture)<br>                    }<br>                }<br>                return<br>            }<br>        <br>        if let gesture = swipeBackPanGesture {<br>            view.removeGestureRecognizer(gesture)<br>        }<br>        swipeBackPanGesture = nil<br>    }</pre><h4>7. Integrate UIScreenEdgePanGestureRecognizer and interactiveTransitionController</h4><p>To make your transition animation progressively smooth by gesture listened, you should implement progress by calculating the view translation and set when the interaction transition controller should finish.</p><pre>///Method to handle gesture action and pop current view controller<br>    @objc func swipeBackPanGestureAction(_ gesture: UIScreenEdgePanGestureRecognizer) {<br>        let translation = gesture.translation(in: view)<br>        let progress = min(max(translation.x / view.bounds.width, 0), 1)<br><br>        switch gesture.state {<br>        case .began:<br>            interactiveTransitionController = UIPercentDrivenInteractiveTransition()<br>            navHeader.leftButtonAction?()<br>        <br>        case .changed:<br>            interactiveTransitionController?.update(progress)<br><br>        case .ended, .cancelled:<br>            let velocity = gesture.velocity(in: view).x<br>            let shouldFinish = progress &gt; 0.5 || velocity &gt; 1300<br><br>            if shouldFinish {<br>                interactiveTransitionController?.finish()<br>            } else {<br>                interactiveTransitionController?.cancel()<br>            }<br>            interactiveTransitionController = nil<br><br>        default:<br>            break<br>        }<br>    }</pre><h4>8. Bind to View Controller Lifecycle in Base View Controller</h4><pre>    override func viewDidLoad() {<br>        super.viewDidLoad()<br>        setupNavHeader()<br>    }<br>    <br>    override func viewWillAppear(_ animated: Bool) {<br>        super.viewWillAppear(animated)<br>        setupSwipeBackGesture()<br>        navigationController?.delegate = self<br>    }<br>    <br>    override func viewWillDisappear(_ animated: Bool) {<br>        super.viewWillDisappear(true)<br>        if navigationController?.delegate === self {<br>            navigationController?.delegate = nil<br>        }<br>    }</pre><h4>9. Implement delegate UINavigationController</h4><p>Make sure you implement UINavigationControllerDelegate with these following functions</p><pre>func navigationController(_ nav, interactionControllerFor animationController:) -&gt; UIViewControllerInteractiveTransitioning? {<br>    return interactiveTransitionController<br>}<br>//Supplies the interactive controller (if any) so the animation is tied to user gesture progress.<br>//If nil, UIKit performs a normal (non-interactive) animation.<br><br>func navigationController(_ nav, animationControllerFor operation:) -&gt; UIViewControllerAnimatedTransitioning? {<br>    if operation == .pop {<br>        return CustomPopVCAnimator()<br>    }<br>    return nil<br>}<br>//Supplies your custom animation for pop operations only.<br>//CustomPopVCAnimator runs instead of the default slide animation.</pre><h4>10. Time To Test</h4><p>For the result of that swipe-back customization will be like this, looks great right?. As you can see, we can pop back to specific screen like from Screen E to Screen B</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/888/1*luOVOiorOOav9X8Y-iWk3Q.gif" /><figcaption>Custom Swipe-Back Navigation Demo</figcaption></figure><h4>11. Wrap Up</h4><p>This setup recreates iOS’s native swipe-back interaction from scratch:</p><ul><li><strong>Your gesture recognizer</strong> detects the swipe.</li><li><strong>UIPercentDrivenInteractiveTransition</strong> drives progress.</li><li><strong>CustomPopVCAnimator</strong> renders the animation.</li><li><strong>NavigationControllerDelegate</strong> stitches everything together.</li></ul><p>It’s essentially a DIY version of Apple’s default but with full freedom for design and behavior.</p><p>Custom swipe-back navigation lets you move beyond the default iOS feel and create a smoother, more branded experience. With just a few lines of code, you can control the animation, the interaction, and the gesture itself. Try it out, tweak it, and make it yours.</p><p>Feel free to see the full code in my github <a href="https://github.com/rivaldofez/Medium-SwipeBackNavigation">https://github.com/rivaldofez/Medium-SwipeBackNavigation</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7343b671e32a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[LLDB Demystified: Debugging Secrets Every iOS Developer Should Know]]></title>
            <link>https://medium.com/@rivaldofez/lldb-demystified-debugging-secrets-every-ios-developer-should-know-dce534747e89?source=rss-391d363fd29c------2</link>
            <guid isPermaLink="false">https://medium.com/p/dce534747e89</guid>
            <category><![CDATA[lldb]]></category>
            <category><![CDATA[debug]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[xcode]]></category>
            <dc:creator><![CDATA[Rivaldo Fernandes]]></dc:creator>
            <pubDate>Thu, 05 Dec 2024 19:35:47 GMT</pubDate>
            <atom:updated>2024-12-07T05:11:07.982Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eT5L0YtYKara3ca7GhHgPw.png" /><figcaption>LLDB in Xcode</figcaption></figure><p>Ever found yourself staring at your code, wondering why it just <em>doesn’t work</em> despite looking perfectly fine? Debugging can feel like navigating a maze blindfolded — unless you have the right tools. Enter LLDB: the secret weapon every iOS developer should master. From inspecting variables with a single command to manipulating code on the fly, LLDB empowers you to debug smarter, not harder. In this article, we’ll demystify LLDB and show you how to wield it like a pro in Xcode.</p><p>Ready to elevate your development game? Let’s dive into the magic of LLDB!</p><h3>What is LLDB?</h3><p>Imagine being a detective on the trail of a bug hiding deep in your code. You have a map, but it’s incomplete — variables are mysteries, the call stack is a maze, and time is ticking. Enter LLDB, Xcode’s built-in superpower. Think of it as your magnifying glass, decoder, and time machine all rolled into one. LLDB allows you to pause, inspect, and even manipulate your app while it runs, giving you unparalleled control over your debugging process. But what exactly is LLDB, and why should every developer master it?</p><p><strong>LLDB (Low-Level Debugger)</strong> is a powerful, modern debugger integrated into Xcode, primarily used for debugging iOS, macOS, watchOS, and tvOS applications. It is part of the LLVM project and serves as the default debugger in Xcode, replacing GDB. LLDB operates at a low level, allowing developers to inspect, analyze, and manipulate code execution in real time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f4LRA0vXdbHoNnHu2dkgKw.png" /><figcaption>LLDB in running Xcode Project</figcaption></figure><h3>Key Features of LLDB</h3><p>There are many uses for LLDB for us as iOS Developers, of course it is well integrated in Xcode as explained previously, but in this article, I want to try to highlight the key features of the most frequently used ones based on my experience.</p><h4><strong>1. Object and Variable Inspection</strong></h4><ul><li>You can examine variables, objects, and memory states while the application is paused at a breakpoint.</li><li>Commands like po (print object) allow you to view object descriptions, making it easier to understand their runtime states.</li></ul><h4>2. Expression Evaluation</h4><ul><li>LLDB allows you to execute code dynamically during a debugging session using the expression or e command. This is useful for testing quick fixes or exploring scenarios without changing your source code.</li></ul><h4>3. Call Stack Navigation</h4><ul><li>It helps trace the execution path through functions and methods using commands like bt (backtrace).</li></ul><h4>4. Breakpoints and Watchpoints</h4><ul><li>Set breakpoints to pause execution at specific lines or functions.</li><li>Use watchpoints to monitor memory changes of specific variables.</li></ul><h4>5. Advanced Debugging Capabilities</h4><ul><li>Inspect raw memory, analyze threads, and debug multithreaded applications seamlessly.</li><li>Attach LLDB to running processes for live debugging.</li></ul><h4>6. Customizability</h4><ul><li>Developers can write custom scripts or use .lldbinit to tailor LLDB’s behavior to their workflow.</li></ul><h3>Basic and General Commands</h3><p>After a year of several key features, here are some commonly used commands that you can try to help your debugging process become faster and smoother:</p><h4>1. General Inspection</h4><ul><li><strong>po (print object)</strong><br>Prints a description of an object using the description method.</li></ul><pre>po &lt;nameOfVariable&gt;</pre><ul><li><strong>p (print)</strong><br>Prints the value of variables, even non-Objective-C objects like structs, enums, and primitives.</li></ul><pre>p &lt;nameOfVariable&gt;</pre><ul><li><strong>v </strong>(variable)<br>Displays information about variables in the current context.</li></ul><pre>v &lt;nameOfVariable&gt;</pre><ul><li><strong>frame variable (or </strong><strong>fr v)</strong><br>Lists all variables in the current stack frame.</li></ul><pre>frame variable<br>fr v</pre><h4>2. Memory and Runtime Inspection</h4><ul><li><strong>expression (or </strong><strong>e)</strong><br>Evaluates arbitrary expressions at runtime. This can modify state, call methods, or even reassign variables.</li></ul><pre>e &lt;someVariable&gt; = &lt;valueVariable&gt;<br>e &lt;someMethod&gt;<br>e &lt;someExpression&gt;</pre><ul><li><strong>memory read</strong><br>Reads the memory at a specific address.</li></ul><pre>memory read &lt;memoryAddress i.e 0x7ffeeebfff10&gt;</pre><ul><li><strong>memory write</strong><br>Writes to a specific memory address (use with caution because it’s harmful).</li></ul><pre>memory write &lt;memoryAddress&gt; &lt;memoryValue&gt;</pre><ul><li><strong>malloc and </strong><strong>free</strong><br>Allocate or deallocate memory directly</li></ul><pre>malloc &lt;sizeMemory&gt;<br>free &lt;memoryAddress&gt;</pre><h4>3. Memory and Runtime Inspection</h4><ul><li><strong>breakpoint set (or </strong><strong>b)</strong><br>Sets breakpoints at functions, methods, or specific lines.</li></ul><pre>b &lt;nameOfMethod&gt;  // Breakpoint at method<br>b &lt;nameOfFile&gt;.swift:&lt;numOfLine&gt;    // Breakpoint at a line</pre><ul><li><strong>breakpoint list (or </strong><strong>bl)</strong><br>Lists all breakpoints.</li></ul><pre>breakpoint list</pre><ul><li><strong>breakpoint delete (or </strong><strong>bd)</strong><br>Deletes specific or all breakpoints.</li></ul><pre>bd &lt;breakpointNumber&gt;<br>bd all</pre><ul><li><strong>thread step-in (or </strong><strong>s)</strong><br>Steps into the next function call.</li></ul><pre>thread step-in</pre><ul><li><strong>thread step-over (or </strong><strong>n)</strong><br>Steps over the current line.</li></ul><pre>thread step-over</pre><p><strong>thread return</strong><br>Exits the current function early, optionally returning a value.</p><pre>thread return &lt;valueForReturn&gt;</pre><h4>4. Call Stack and Threads</h4><ul><li><strong>bt (backtrace)</strong><br>Displays the call stack.</li></ul><pre>bt</pre><ul><li><strong>thread list</strong><br>Lists all threads.</li></ul><pre>thread list</pre><ul><li><strong>thread select</strong><br>Switches to a specific thread.</li></ul><pre>thread select &lt;threadNumber&gt;</pre><ul><li><strong>frame select</strong><br>Switches to a specific stack frame.</li></ul><pre>frame select &lt;frameNumber&gt;</pre><h4>5. Call Stack and Threads</h4><ul><li><strong>image list</strong><br>Lists all loaded modules (i.e, system frameworks, dynamic libraries etc).</li></ul><pre>image list</pre><ul><li><strong>disassemble</strong><br>Disassembles the current code for low-level debugging.</li></ul><pre>disassemble</pre><ul><li><strong>watchpoint set</strong><br>Monitors a variable or memory address for changes.</li></ul><pre>watchpoint set variable someVariable</pre><ul><li><strong>log enable</strong><br>Enables logging for specific subsystems, like Core Data or network debugging.</li></ul><pre>log enable --categories SQL --level debug</pre><p>As you dive deeper into LLDB, you can find that it is more than just a debugger — it’s a problem-solving companion that can save hours of frustration and help you better understand your code. The next time a bug tries to hide in plain sight, you’ll have the tools and confidence to hunt it down with ease.</p><p>So, take some time to explore LLDB, experiment with its commands, and integrate it into your development workflow. Who knows? Debugging might just become your favorite part of coding.</p><p><strong>“Happy debugging!”</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dce534747e89" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From Chaos to Clarity: Resolving Xcode Project Conflicts with Tuist Part 2]]></title>
            <link>https://medium.com/@rivaldofez/from-chaos-to-clarity-resolving-xcode-project-conflicts-with-tuist-part-2-a4f8921ad618?source=rss-391d363fd29c------2</link>
            <guid isPermaLink="false">https://medium.com/p/a4f8921ad618</guid>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[tuist-migration]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[tuist]]></category>
            <dc:creator><![CDATA[Rivaldo Fernandes]]></dc:creator>
            <pubDate>Tue, 26 Nov 2024 23:19:50 GMT</pubDate>
            <atom:updated>2024-11-26T23:19:50.975Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5riDZYm9oCFnORH5151l9A.png" /><figcaption>Tuist — Command Line Interface tool for managing iOS Project</figcaption></figure><p>If you think that Tuist is just a simplification of code conflicts in Xcode projects, think again…. In Part 1, we already discussed the introduction of Tuist, project setup, and management, and tried to create a new simple project. But that’s just the beginning. Tuist does more than just solve problems; it transforms the projects created into scalable, modular, and structured ones.</p><p>In this article, we’re taking things to the next level. Imagine effortlessly managing target, modularizing your codebase for reusability, and handling complex dependency graphs — all without breaking a sweat. Tuist makes it possible.</p><p>Whether you’re leading a team through a growing app or struggling to maintain order in a sprawling modular project, this guide will show you how to wield Tuist like a pro. By the end, you’ll not only understand Tuist’s advanced features — you’ll wonder how you ever managed without them.</p><p>Ready to elevate your development game? Let’s dive into the magic of Tuist!</p><h3>Get Started with Sample Project</h3><p>First of all, before starting exercises and detailed discussion, in this Part 2 I will use a project that I have created before called Pokepedia, a simple application that consumes the Pokedex API. You can access the project on my GitHub via the following URL</p><p><a href="https://github.com/rivaldofez/Pokepedia">GitHub - rivaldofez/Pokepedia</a></p><p>A little introduction, the Pokepedia application is modular depending on the PokepediaCore module which contains generic functions and base components, PokepediaCommon which contains base localization and font customization, PokepediaPokemon which is a module to handle the main Pokemon data and PokepediaSpecies which is a module to handle detailed pokemon species data. Pokepedia also depends on external libraries, such as RxSwift, Alamofire, Realm, Lottie, SDWebImage. The following is a dependency diagram on this Pokepedia project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ymu62ucM_ubbOvH8g895Iw.png" /><figcaption>Dependency Diagram Pokepedia</figcaption></figure><p>You can clone and familiarize yourself with some of the components, project setups, and code in this Pokepedia project to make it easier to practice migrating to Tuist.</p><h3>Migration to Tuist</h3><p>Basically, the setup and configuration on Tuist is not much different from the base project handled natively by Xcode in general. In this section I will try to discuss what needs to be done to migrate an existing project into Tuist completely.</p><h4>1. Init New Tuist Project</h4><p>First, as explained in Part 1, we need to initiate a new project using Tuist, for details on how to create a new project with Tuist, you can refer back to the Part 1 article. Here I have created a new Tuist project with the same name <strong>“Pokepedia”</strong> and here is the default generated manifest file <strong>“Project.swift”</strong>.</p><pre>import ProjectDescription<br><br>let project = Project(<br>    name: &quot;Pokepedia&quot;,<br>    targets: [<br>        .target(<br>            name: &quot;Pokepedia&quot;,<br>            destinations: .iOS,<br>            product: .app,<br>            bundleId: &quot;io.tuist.Pokepedia&quot;,<br>            infoPlist: .extendingDefault(<br>                with: [<br>                    &quot;UILaunchScreen&quot;: [<br>                        &quot;UIColorName&quot;: &quot;&quot;,<br>                        &quot;UIImageName&quot;: &quot;&quot;,<br>                    ],<br>                ]<br>            ),<br>            sources: [&quot;Pokepedia/Sources/**&quot;],<br>            resources: [&quot;Pokepedia/Resources/**&quot;],<br>            dependencies: []<br>        ),<br>        .target(<br>            name: &quot;PokepediaTests&quot;,<br>            destinations: .iOS,<br>            product: .unitTests,<br>            bundleId: &quot;io.tuist.PokepediaTests&quot;,<br>            infoPlist: .default,<br>            sources: [&quot;Pokepedia/Tests/**&quot;],<br>            resources: [],<br>            dependencies: [.target(name: &quot;Pokepedia&quot;)]<br>        ),<br>    ]<br>)</pre><h4>2. Change App Name &amp; Bundle Identifier</h4><p>Let’s focus on implementing the main target of Pokepedia app and leave the test module aside, maybe we will discuss it in another article. For that we can delete the “PokepediaTests” target. The main thing to note is the naming of the application and the bundle identifier, so adjust it to the name and bundle of your project. For this case, I use the name<strong> “Pokepedia” </strong>and the bundle id <strong>“com.rivaldofez.pokepedia”</strong></p><p>Here is the current adjusted manifest</p><pre>import ProjectDescription<br><br>let project = Project(<br>    name: &quot;Pokepedia&quot;,<br>    targets: [<br>        .target(<br>            name: &quot;Pokepedia&quot;,<br>            destinations: .iOS,<br>            product: .app,<br>            bundleId: &quot;com.rivaldofez.pokepedia&quot;,<br>            infoPlist: .extendingDefault(<br>                with: [<br>                    &quot;UILaunchScreen&quot;: [<br>                        &quot;UIColorName&quot;: &quot;&quot;,<br>                        &quot;UIImageName&quot;: &quot;&quot;,<br>                    ],<br>                ]<br>            ),<br>            sources: [&quot;Pokepedia/Sources/**&quot;],<br>            resources: [&quot;Pokepedia/Resources/**&quot;],<br>            dependencies: []<br>        )<br>    ]<br>)</pre><h4>3. Manage Dependency Sources</h4><p>We need to set the dependencies of the project that we need. As you can see in the Pokepedia sample project and the diagram. Pokepedia depends on two types of packages, remote and local packages, for that we need to include all dependencies in the manifest dependency tuist in “Package.swift”.</p><p>To add a local package source, you can add the source to “Package.swift” by referencing the path where the package folder is located. I highly recommend you use a relative path like the following.</p><pre> .package(path: &quot;../Module/PokepediaCommon&quot;)</pre><p>The relative path above refers to the “Module/Pokemon” folder which is located one level above the root folder where “Package.swift” is located. Don’t forget to move the local module folder from the Pokepedia sample project to the project created by Tuist.</p><p>Next, we also need to add a remote package from an external source, to add this source you only need to enter the package url along with its version or branch if needed. For example, Pokepedia uses the <strong>RxSwift</strong> package with minimum version “6.0.0”, so we add the RxSwift package as follows</p><pre>dependencies: [<br>  .package(url: &quot;https://github.com/ReactiveX/RxSwift.git&quot;, from: &quot;6.0.0&quot;)<br>]</pre><p>Here is the current adjusted Package.swift manifest</p><pre>// swift-tools-version: 5.9<br>import PackageDescription<br><br>#if TUIST<br>    import ProjectDescription<br><br>    let packageSettings = PackageSettings(<br>        // Customize the product types for specific package product<br>        // Default is .staticFramework<br>        // productTypes: [&quot;Alamofire&quot;: .framework,]<br>        productTypes: [:]<br>    )<br>#endif<br><br>let package = Package(<br>    name: &quot;Pokepedia&quot;,<br>    dependencies: [<br>        // Add your own dependencies here:<br>        // .package(url: &quot;https://github.com/Alamofire/Alamofire&quot;, from: &quot;5.0.0&quot;),<br>        // You can read more about dependencies here: https://docs.tuist.io/documentation/tuist/dependencies<br>        .package(path: &quot;../Module/PokepediaCommon&quot;),<br>        .package(path: &quot;../Module/PokepediaPokemon&quot;),<br>        .package(path: &quot;../Module/PokepediaSpecies&quot;),<br>        .package(url: &quot;https://github.com/airbnb/lottie-spm.git&quot;, from: &quot;4.0.0&quot;),<br>        .package(url: &quot;https://github.com/SDWebImage/SDWebImage.git&quot;, from: &quot;5.0.0&quot;),<br>        .package(url: &quot;https://github.com/ChartsOrg/Charts.git&quot;, from: &quot;5.0.0&quot;),<br>        .package(url: &quot;https://github.com/ReactiveX/RxSwift.git&quot;, from: &quot;6.0.0&quot;),<br>        .package(url: &quot;https://github.com/realm/realm-swift.git&quot;, from: &quot;10.45.0&quot;)<br>    ]<br>)</pre><h4>3. Adding Dependencies to Targets</h4><p>Next, the thing to do after adding the dependency source, you also have to register which Targets need it in Project.swift, if you have multiple targets, you need to register one by one for each target. To add a dependency to your target you can use the following syntax</p><pre>dependencies: [<br>  .external(name: &quot;PokepediaCommon&quot;)<br>]</pre><p>Here is the current adjusted Project.swift manifest</p><pre>import ProjectDescription<br><br>let project = Project(<br>    name: &quot;Pokepedia&quot;,<br>    targets: [<br>        .target(<br>            name: &quot;Pokepedia&quot;,<br>            destinations: .iOS,<br>            product: .app,<br>            bundleId: &quot;com.rivaldofez.pokepedia&quot;,<br>            infoPlist: .extendingDefault(<br>                with: [<br>                    &quot;UILaunchScreen&quot;: [<br>                        &quot;UIColorName&quot;: &quot;&quot;,<br>                        &quot;UIImageName&quot;: &quot;&quot;,<br>                    ],<br>                ]<br>            ),<br>            sources: [&quot;Pokepedia/Sources/**&quot;],<br>            resources: [&quot;Pokepedia/Resources/**&quot;],<br>            dependencies: [<br>                .external(name: &quot;PokepediaCommon&quot;),<br>                .external(name: &quot;PokepediaPokemon&quot;),<br>                .external(name: &quot;PokepediaSpecies&quot;),<br>                .external(name: &quot;Lottie&quot;),<br>                .external(name: &quot;SDWebImage&quot;),<br>                .external(name: &quot;DGCharts&quot;),<br>                .external(name: &quot;RxSwift&quot;),<br>                .external(name: &quot;RealmSwift&quot;),<br>                .external(name: &quot;Realm&quot;)]<br>        )<br>    ]<br>)</pre><h4>4. Resolving Dependencies</h4><p>After adding dependencies, you can resolve and download the dependencies defined in the manifest with the following syntax</p><pre>tuist install</pre><p>Tuist supports cache, so you don’t have to keep fetching the same package from the remote. However, if you have a problem with the cache, you can clear it with the syntax</p><pre>tuist clean</pre><p>Magically, after you resolved all dependencies, with Tuist you can also generate dependency diagrams using this syntax</p><pre>tuist graph</pre><p>The result will be like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4BP8yjPSjIFPycxkpw1oFg.png" /><figcaption>Dependency Diagram generated from Tuist</figcaption></figure><h4>5. Moving Project Files &amp; Assets</h4><p>After setting the project dependency, we need to move all the modules, files, and assets in the old project into the new project generated by Tuist. We can move files manually, but pay attention to the placement of the files, for files that contain swift code, put them in the “Sources” folder, while for assets and others put them in the “Resources” folder.</p><p>The result will be like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yohQS-g5-0KkUuUNGCgwvA.png" /><figcaption>Folder Structure Results in Pokepedia project by Tuist</figcaption></figure><h4>5. Setup Info.plist</h4><p>In <strong>Tuist</strong>, specifying the <strong>Info.plist</strong> file in the project manifest (Project.swift) is necessary because it allows Tuist to explicitly manage and configure the app&#39;s or target&#39;s properties in a centralized, predictable way.</p><p>The <strong>Info.plist</strong> file contains essential metadata such as the bundle identifier, app display name, supported platforms, versioning, and permissions. By defining the Info.plist file in Project.swift, Tuist knows which file to associate with the target, ensuring that the generated Xcode project has the correct path to the file. This also promotes consistency and automation, as Tuist can dynamically generate or modify the Info.plist file based on environment or configuration settings, reducing the need for manual updates. Additionally, for projects with multiple targets (like apps, widgets, or extensions), each target typically requires its own Info.plist file, and specifying it in the manifest ensures each target uses the correct configuration. This setup also simplifies the management of different environments (e.g., staging, production) and avoids the risk of misconfiguration in Xcode, making the project easier to maintain, share, and regenerate. Ultimately, setting up the <strong>Info.plist</strong> in Tuist ensures a more maintainable and predictable project structure, aligning with Tuist&#39;s goal of simplifying project management.</p><p>For the Pokepedia sample project, there are several important <strong>Info.plist</strong> configurations that must be registered in the manifest. First, we must adjust the LaunchScreen configuration and the Scene — SceneDelegate configuration so that the root view controller can be called.</p><pre>infoPlist: .extendingDefault(<br>                with: [<br>                    &quot;UILaunchStoryboardName&quot;: &quot;LaunchScreen&quot;,<br>                    &quot;UIApplicationSceneManifest&quot;: [<br>                        &quot;UISceneConfigurations&quot;: [<br>                            &quot;UIWindowSceneSessionRoleApplication&quot;: [<br>                                [<br>                                    &quot;UISceneConfigurationName&quot;: &quot;Default Configuration&quot;,<br>                                    &quot;UISceneDelegateClassName&quot;: &quot;$(PRODUCT_MODULE_NAME).SceneDelegate&quot;<br>                                ]<br>                            ]<br>                        ]<br>                    ]<br>                ]<br>            )<br>....</pre><p>Next, Pokepedia uses a custom font, for that we need to add the name of the custom font that will be used in the application as follows.</p><pre>infoPlist: .extendingDefault(<br>                with: [<br>                    &quot;UIAppFonts&quot;: [<br>                        &quot;Poppins-Black.ttf&quot;,<br>                        &quot;Poppins-BlackItalic.ttf&quot;,<br>                        &quot;Poppins-Bold.ttf&quot;,<br>                        &quot;Poppins-BoldItalic.ttf&quot;,<br>                        &quot;Poppins-ExtraBold.ttf&quot;,<br>                        &quot;Poppins-ExtraLight.ttf&quot;,<br>                        &quot;Poppins-ExtraLightItalic.ttf&quot;,<br>                        &quot;Poppins-Italic.ttf&quot;,<br>                        &quot;Poppins-Light.ttf&quot;,<br>                        &quot;Poppins-Medium.ttf&quot;,<br>                        &quot;Poppins-MediumItalic.ttf&quot;,<br>                        &quot;Poppins-Regular.ttf&quot;,<br>                        &quot;Poppins-SemiBold.ttf&quot;,<br>                        &quot;Poppins-SemiBoldItalic.ttf&quot;,<br>                        &quot;Poppins-Thin.ttf&quot;,<br>                        &quot;Poppins-ThinItalic.ttf&quot;,<br>                        &quot;Comfortaa-Bold.ttf&quot;,<br>                        &quot;Comfortaa-Light.ttf&quot;,<br>                        &quot;Comfortaa-Medium.ttf&quot;,<br>                        &quot;Comfortaa-Regular.ttf&quot;,<br>                        &quot;Comfortaa-SemiBold.ttf&quot;<br>                    ]<br>                ]<br>            )</pre><p>Here is the current adjusted Project.swift manifest</p><pre>import ProjectDescription<br><br>let project = Project(<br>    name: &quot;Pokepedia&quot;,<br>    targets: [<br>        .target(<br>            name: &quot;Pokepedia&quot;,<br>            destinations: .iOS,<br>            product: .app,<br>            bundleId: &quot;com.rivaldofez.pokepedia&quot;,<br>            infoPlist: .extendingDefault(<br>                with: [<br>                    &quot;UIAppFonts&quot;: [<br>                        &quot;Poppins-Black.ttf&quot;,<br>                        &quot;Poppins-BlackItalic.ttf&quot;,<br>                        &quot;Poppins-Bold.ttf&quot;,<br>                        &quot;Poppins-BoldItalic.ttf&quot;,<br>                        &quot;Poppins-ExtraBold.ttf&quot;,<br>                        &quot;Poppins-ExtraLight.ttf&quot;,<br>                        &quot;Poppins-ExtraLightItalic.ttf&quot;,<br>                        &quot;Poppins-Italic.ttf&quot;,<br>                        &quot;Poppins-Light.ttf&quot;,<br>                        &quot;Poppins-Medium.ttf&quot;,<br>                        &quot;Poppins-MediumItalic.ttf&quot;,<br>                        &quot;Poppins-Regular.ttf&quot;,<br>                        &quot;Poppins-SemiBold.ttf&quot;,<br>                        &quot;Poppins-SemiBoldItalic.ttf&quot;,<br>                        &quot;Poppins-Thin.ttf&quot;,<br>                        &quot;Poppins-ThinItalic.ttf&quot;,<br>                        &quot;Comfortaa-Bold.ttf&quot;,<br>                        &quot;Comfortaa-Light.ttf&quot;,<br>                        &quot;Comfortaa-Medium.ttf&quot;,<br>                        &quot;Comfortaa-Regular.ttf&quot;,<br>                        &quot;Comfortaa-SemiBold.ttf&quot;<br>                    ],<br>                    &quot;UILaunchStoryboardName&quot;: &quot;LaunchScreen&quot;,<br>                    &quot;UIApplicationSceneManifest&quot;: [<br>                        &quot;UISceneConfigurations&quot;: [<br>                            &quot;UIWindowSceneSessionRoleApplication&quot;: [<br>                                [<br>                                    &quot;UISceneConfigurationName&quot;: &quot;Default Configuration&quot;,<br>                                    &quot;UISceneDelegateClassName&quot;: &quot;$(PRODUCT_MODULE_NAME).SceneDelegate&quot;<br>                                ]<br>                            ]<br>                        ]<br>                    ]<br>                ]<br>            ),<br>            sources: [&quot;Pokepedia/Sources/**&quot;],<br>            resources: [&quot;Pokepedia/Resources/**&quot;],<br>            dependencies: [<br>                .external(name: &quot;PokepediaCommon&quot;),<br>                .external(name: &quot;PokepediaPokemon&quot;),<br>                .external(name: &quot;PokepediaSpecies&quot;),<br>                .external(name: &quot;Lottie&quot;),<br>                .external(name: &quot;SDWebImage&quot;),<br>                .external(name: &quot;DGCharts&quot;),<br>                .external(name: &quot;RxSwift&quot;),<br>                .external(name: &quot;RealmSwift&quot;),<br>                .external(name: &quot;Realm&quot;)<br>            ]<br>        ),<br>    ]<br>)</pre><h4>5. Setup Settings / Build Settings</h4><p>Another important thing that needs to be adjusted is that Pokepedia uses a library made with Objective-C language, namely SDWebImage, so it is necessary to add a linker flag so that the application can run properly. In Tuist we also need to add configurations related to settings &amp; build settings in the manifest as follows</p><pre>settings: .settings(<br>    base: [<br>        &quot;OTHER_LDFLAGS&quot;: &quot;-ObjC&quot;<br>    ]<br>)</pre><p>The final manifest looks like this</p><pre>import ProjectDescription<br><br>let project = Project(<br>    name: &quot;Pokepedia&quot;,<br>    targets: [<br>        .target(<br>            name: &quot;Pokepedia&quot;,<br>            destinations: .iOS,<br>            product: .app,<br>            bundleId: &quot;com.rivaldofez.pokepedia&quot;,<br>            infoPlist: .extendingDefault(<br>                with: [<br>                    &quot;UIAppFonts&quot;: [<br>                        &quot;Poppins-Black.ttf&quot;,<br>                        &quot;Poppins-BlackItalic.ttf&quot;,<br>                        &quot;Poppins-Bold.ttf&quot;,<br>                        &quot;Poppins-BoldItalic.ttf&quot;,<br>                        &quot;Poppins-ExtraBold.ttf&quot;,<br>                        &quot;Poppins-ExtraLight.ttf&quot;,<br>                        &quot;Poppins-ExtraLightItalic.ttf&quot;,<br>                        &quot;Poppins-Italic.ttf&quot;,<br>                        &quot;Poppins-Light.ttf&quot;,<br>                        &quot;Poppins-Medium.ttf&quot;,<br>                        &quot;Poppins-MediumItalic.ttf&quot;,<br>                        &quot;Poppins-Regular.ttf&quot;,<br>                        &quot;Poppins-SemiBold.ttf&quot;,<br>                        &quot;Poppins-SemiBoldItalic.ttf&quot;,<br>                        &quot;Poppins-Thin.ttf&quot;,<br>                        &quot;Poppins-ThinItalic.ttf&quot;,<br>                        &quot;Comfortaa-Bold.ttf&quot;,<br>                        &quot;Comfortaa-Light.ttf&quot;,<br>                        &quot;Comfortaa-Medium.ttf&quot;,<br>                        &quot;Comfortaa-Regular.ttf&quot;,<br>                        &quot;Comfortaa-SemiBold.ttf&quot;<br>                    ],<br>                    &quot;UILaunchStoryboardName&quot;: &quot;LaunchScreen&quot;,<br>                    &quot;UIApplicationSceneManifest&quot;: [<br>                        &quot;UISceneConfigurations&quot;: [<br>                            &quot;UIWindowSceneSessionRoleApplication&quot;: [<br>                                [<br>                                    &quot;UISceneConfigurationName&quot;: &quot;Default Configuration&quot;,<br>                                    &quot;UISceneDelegateClassName&quot;: &quot;$(PRODUCT_MODULE_NAME).SceneDelegate&quot;<br>                                ]<br>                            ]<br>                        ]<br>                    ]<br>                ]<br>            ),<br>            sources: [&quot;Pokepedia/Sources/**&quot;],<br>            resources: [&quot;Pokepedia/Resources/**&quot;],<br>            dependencies: [<br>                .external(name: &quot;PokepediaCommon&quot;),<br>                .external(name: &quot;PokepediaPokemon&quot;),<br>                .external(name: &quot;PokepediaSpecies&quot;),<br>                .external(name: &quot;Lottie&quot;),<br>                .external(name: &quot;SDWebImage&quot;),<br>                .external(name: &quot;DGCharts&quot;),<br>                .external(name: &quot;RxSwift&quot;),<br>                .external(name: &quot;RealmSwift&quot;),<br>                .external(name: &quot;Realm&quot;)<br>            ],<br>            settings: .settings(<br>                base: [<br>                    &quot;OTHER_LDFLAGS&quot;: &quot;-ObjC&quot;<br>                ]<br>            )<br>        ),<br>    ]<br>)</pre><h4>6. Test Run</h4><p>After all the setup is done, it’s time to do a test run. First, fetch all the packages and their dependencies using the syntax</p><pre>tuist install</pre><p>Make sure there are no problems, at the end use the following syntax to generate the project and Tuist will automatically open Xcode, and you can run the project as usual.</p><pre>tuist generate</pre><p>Voila, you can run the project as usual, and of course your project will be easier to manage with Tuist!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5RNN5rkq9BBxgY_zgtRe2Q.png" /><figcaption>Running Test Pokepedia project by Tuist</figcaption></figure><h4>7. Setup Git Ignore</h4><p>Don’t forget to setup <strong>.gitignore</strong> and make sure to exclude all generated files and components from Tuist. Here is my sample .gitignore</p><pre># Tuist Generated Files<br>/.build/<br>/Generated/<br>/tuist/<br>Derived/<br><br># Xcode project files<br>*.xcodeproj<br>*.xcworkspace<br>*.xcuserdata<br>*.xccheckout<br>*.xcscmblueprint<br>*.pbxproj<br>*.xcscheme</pre><p>For the final result, you can access it at</p><p><a href="https://github.com/rivaldofez/Tuist-Pokepedia/tree/main">GitHub - rivaldofez/Tuist-Pokepedia</a></p><p>With its powerful features and flexibility, Tuist has the potential to revolutionize how you manage and scale iOS projects. From handling dependency targets to simplifying build configurations, Tuist empowers you to focus on what truly matters — building great apps.</p><h3>References:</h3><p><a href="https://docs.tuist.dev/en/">https://docs.tuist.dev/en/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a4f8921ad618" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From Chaos to Clarity: Resolving Xcode Project Conflicts with Tuist Part 1]]></title>
            <link>https://medium.com/@rivaldofez/from-chaos-to-clarity-resolving-xcode-project-conflicts-with-tuist-part-1-8a8cc25f3f84?source=rss-391d363fd29c------2</link>
            <guid isPermaLink="false">https://medium.com/p/8a8cc25f3f84</guid>
            <category><![CDATA[tuist]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[productivity]]></category>
            <dc:creator><![CDATA[Rivaldo Fernandes]]></dc:creator>
            <pubDate>Sun, 17 Nov 2024 17:58:29 GMT</pubDate>
            <atom:updated>2024-11-17T17:58:29.466Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wS0VIlNQS1kcWwXnn6aYyA.png" /><figcaption>Tuist — Command Line Interface tool for managing iOS Project</figcaption></figure><p>As an iOS Developer who has worked on a large native iOS project using Xcode, you must know what to do in general when collaborating with many people, of course, it is not about personal, but this is related to code versioning and merging. As usual, we are merging changes, resolving conflicts of unreadable project files, and parsing project settings. This is a productivity hole that any iOS developer hates. But what if there was a solution to overcome this chaos completely? Tuist is here, a tool that changes the way iOS developers manage and maintain Xcode projects.</p><p>In this article, we will discuss how Tuist can turn frequent merging conflicts into something easy so that developers can focus on other more important things.</p><h3>What is Tuist?</h3><p>Before we discuss more about Tuist, for those of you who still don’t know, reported from the official website “Tuist is a toolchain designed to accelerate and enhance app development. Tuist integrates seamlessly with official tools and systems, meeting developers in familiar territory. By shouldering the burden of tool and system integration, Tuist enables teams to channel their energy into feature development and improve the overall developer experience.”</p><p>In Part 1, I want to introduce and highlight the role of Tuist in managing Xcode projects including generating Xcode projects, solving dependencies, and speeding up the project-building process with the cache feature.</p><h3>Why using Tuist?</h3><h4>1. Declarative Project Configuration</h4><ul><li><strong>Simplifies Project Setup</strong>: Traditionally, Xcode project settings are managed through an XML-based .xcodeproj file. These files can quickly become bloated, complex, and prone to conflicts as team members make changes. Tuist allows developers to define project settings declaratively in a Swift format file (Project.swift) also with its dependency in (Package.swift). This approach is easier to read, write, and understand compared to XML, and as iOS Developer, swift is more friendly compared to other</li><li><strong>Consistency Across Teams</strong>: The declarative format means every developer working on the project has a consistent, single source of truth for how the project is structured and built. This makes it easier to keep the project in sync, collaborate, versioning code and reduces the risk of configuration drift.</li></ul><h4>2. Minimizes Merge Conflicts</h4><ul><li><strong>Reduces .xcodeproj Conflicts</strong>: In traditional Xcode projects, changes in the .xcodeproj file often lead to frustrating merge conflicts when multiple developers work on different branches. This so annoying since .xcodeproj is not readable by human sometimes haha. Tuist avoids this problem by generating the project file using code defined in Project.swift or other manifests. This means source control focuses on changes to the Swift manifests, making conflicts less likely and easier to resolve.</li><li><strong>Better Collaboration</strong>: Teams can focus on collaborating without worrying as much about breaking or corrupting the project file structure, which is particularly useful for teams with frequent merges or feature branching strategies.</li></ul><h4>3. Automation and Scalability</h4><ul><li><strong>Code Generation and Consistency</strong>: Tuist can automatically generate files, structures, and configurations. This level of automation ensures consistent project setups, minimizes human errors, and speeds up the onboarding process for new developers.</li><li><strong>Scales Well for Complex Projects</strong>: As projects grow larger with many targets, dependencies, and frameworks, managing the project structure manually becomes cumbersome. Tuist’s approach of breaking down a project into modules, dependencies, and targets makes large projects more maintainable and understandable.</li></ul><h4>4. Built-In Dependency Management</h4><ul><li><strong>Integration with CocoaPods and Swift Package Manager</strong>: Tuist can simplify how you add dependencies, ensuring they’re integrated consistently across targets. This eliminates the need to manually configure dependencies in the Xcode GUI, making the process more predictable and streamlined.</li><li><strong>Dependency Graph Management</strong>: For large projects with multiple dependencies, understanding and managing the dependency graph can be tricky. Tuist provides visualizations and tools that make understanding dependencies much easier.</li></ul><h4>5. Environment Customization</h4><ul><li><strong>Multiple Build Configurations</strong>: Tuist makes it straightforward to create different build configurations (e.g., Debug, Release, Custom Environment Configurations) within a project. This helps developers quickly test different setups without manually managing build schemes.</li><li><strong>Automation for Build Settings</strong>: Using Tuist, developers can automate and consistently enforce specific build settings, reducing manual configuration work and potential errors.</li></ul><h4>6. Improved Onboarding Experience</h4><ul><li><strong>Easy Project Initialization</strong>: With Tuist, new developers on a project can run a single command to generate the project locally with all the necessary configurations and dependencies in place. This eliminates the often lengthy and error-prone setup process that typically accompanies new projects.</li><li><strong>Clear Project Structure</strong>: The declarative nature of Project.swift and related manifests offers a clear overview of the project’s structure, targets, and dependencies, helping new developers quickly get up to speed.</li></ul><h4>7. Support for Modular Architectures</h4><ul><li><strong>Easier Management of Modules</strong>: Tuist excels in defining and managing modular projects. By splitting a project into modules, teams can work more independently on different features or components, improving collaboration and reducing build times for individual developers.</li><li><strong>Enhanced Reusability</strong>: Tuist enables defining and reusing components across different targets or projects, which fosters code reuse and improves maintainability.</li></ul><h4>8. Community Support</h4><ul><li><strong>Open-Source Flexibility</strong>: As an open-source tool, Tuist has an active and supportive community, which means issues are often quickly addressed, and new features and improvements are frequently contributed. You just simply look through official community portal on <a href="https://community.tuist.io/">https://community.tuist.io/</a></li></ul><h3>Setup New Project Using Tuist</h3><p>After knowing about Tuist, then how to create an iOS project with Tuist?.</p><h4>1. Install Tuist</h4><p>Before we started to create project, first of all you need to install Tuist. You can refer to official documentation on <a href="https://docs.tuist.dev/en/guides/quick-start/install-tuist">https://docs.tuist.dev/en/guides/quick-start/install-tuist</a></p><p>I want to highlight my personal preference install Tuist. Since the recommendation using Mise, but i use homebrew, just to test and experiment haha. You can install it using this</p><pre>brew tap tuist/tuist<br>brew install --formula tuist<br>brew install --formula tuist@x.y.z</pre><p>Note for Mac that use Apple Silicon, you may need to add <em>arch -arm64</em> before brew command like this</p><pre>brew tap tuist/tuist<br>arch -arm64 brew install --formula tuist<br>arch -arm64 brew install --formula tuist@x.y.z</pre><h4>2. Create Project</h4><p>If you already have Tuist installed on your terminal, then you can use Tuist to initiate your new project, for more detail you can refer to <a href="https://docs.tuist.dev/en/guides/start/new-project">https://docs.tuist.dev/en/guides/start/new-project</a></p><ul><li>Make New Empty folder, you are free to choose the method for creating empty folder like using finder or terminal. Using terminal, you can put this command</li></ul><pre>mkdir Pokedex<br>cd Pokedex</pre><ul><li>Init your iOS Project using this command, after a moment, you will see that Tuist generate some files and folder</li></ul><pre>tuist init --platform ios</pre><ul><li>After initialized project, you also and edit project configuration in Project.swift and other manifest files. To edit Tuist configuration, you just simply using this command. Terminal will be open your Xcode after executing this command</li></ul><pre>tuist edit</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sxLVXRefCwvdpZfmTdxYVQ.png" /></figure><ul><li>After you setup and update the Project.swift configuration, you can start to fetch dependency and resolve configuration using this command</li></ul><pre>tuist install</pre><ul><li>If the plugins, library and other dependency resolved successfully, you can start generating project workspace using this command</li></ul><pre>tuist generate</pre><ul><li>After executing that command, terminal will be open your workspace project, in that you will see the full of project generate beautifully.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G1qN7oYp9OmKJFXougX6lQ.png" /></figure><p>Wohoo, now you can run the project as usual. It’s effortless when your project is managed using Tuist. Now the question is, how do we migrate a project that was previously manual with .xcodeproj to Tuist? Wait for the next article Part 2, we will discuss more advanced Tuist capability. Hopefully you like this article :)</p><h3>References:</h3><p><a href="https://docs.tuist.dev/en/">https://docs.tuist.dev/en/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8a8cc25f3f84" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create & Export Excel File in iOS SwiftUI]]></title>
            <link>https://medium.com/@rivaldofez/export-to-excel-files-in-ios-swiftui-c8497e6324e0?source=rss-391d363fd29c------2</link>
            <guid isPermaLink="false">https://medium.com/p/c8497e6324e0</guid>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[xlsx]]></category>
            <category><![CDATA[excel]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[spreadsheets]]></category>
            <dc:creator><![CDATA[Rivaldo Fernandes]]></dc:creator>
            <pubDate>Thu, 13 Jul 2023 17:46:44 GMT</pubDate>
            <atom:updated>2023-07-13T17:53:16.792Z</atom:updated>
            <content:encoded><![CDATA[<p>Membuat fitur export ke document excel pada aplikasi iOS SwiftUI bukanlah hal yang mudah, terlebih dokumen excel tidak didukung resmi oleh SwiftUI sehingga perlu menggunakan library pihak ketiga. Salah satu library yang dapat digunakan adalah <strong>libxlsxwriter</strong> yang dapat melakukan beberapa operasi layaknya pada Microsoft Excel seperti membuat cell sampai melakukan styling dan menyisipkan gambar.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/192/1*P5TZyzSl_qE9RyQKblxC6w.png" /><figcaption>SwiftUI</figcaption></figure><p>Untuk melakukannya, kamu perlu melakukan setup pada project dan mengimpor library Untuk menambahkan library kedalam project, kamu bisa gunakan cocoapods dengan cara sebagai berikut</p><h3>Setup Project</h3><p><strong>Buat Podfile<br></strong>Podfile diperlukan ketika kamu sudah membuat project dari awal dan file ini berisi seluruh dependency pada project kamu. Untuk membuatnya kamu bisa copy kode berikut pada terminal yang aktif di root directory project kamu ya</p><pre>pod init</pre><p><strong>Edit Podfile<br></strong>Setelah podfile dibuat, ia hanya akn berisi kode bawaan, disini kamu perlu edit file ini dan menambahkan library <strong>libxlsxwriter</strong> seperti berikut ini</p><pre>target &#39;ExcelSwiftUI&#39; do<br>  # Comment the next line if you don&#39;t want to use dynamic frameworks<br>  use_frameworks!<br><br>  pod &#39;libxlsxwriter&#39;<br>   <br>end</pre><p><strong>Install library pada Podfile</strong><br>Setelah Podfile disesuaikan dan ditambahkan library yang diinginkan, selanjutnya kamu perlu menginstall dan mengaplikasikan library yang tertera pada Podfile, proses ini dilakukan secara otomatis dengan perintah berikut</p><pre>pod install</pre><p><strong>Open project via xcworkspace<br></strong>Setelah proses install selesai, akan terbentuk workspace document ditandai dengan extensi <strong>.xcworkspace, </strong>untuk selanjutnya bukalah project dengan cara membuka file ini pada XCode.</p><p><strong>Mengimpor library </strong><br>Setelah project berhasil terbuka tanpa ada error, kamu bisa gunakan library tersebut dengan melakukan impor terlebih dahulu dengan cara menuliskan</p><pre>import xlsxwriter</pre><h3>Setup Data</h3><p><strong>Membuat Model Data</strong><br>Untuk melakukan export data kedalam document excel, kamu perlu memiliki base data dan model yang nanti menjadi struktur table pada spreadsheet excel. Sebagai contoh saya akan mencontohkan dengan data kontak dengan 4 properti yaitu nama, jenis kelamin, alamat, dan foto profile. Berikut contoh model data tersebut</p><pre>import SwiftUI<br><br>struct Contact {<br>    var name: String<br>    var gender: String<br>    var address: String<br>    var image: String<br>}</pre><p><strong>Menambahkan Dummy Data</strong><br>Setelah model data dibuat, kamu juga perlu menambahkan baris demi baris pada spreadsheet, untuk itu disini saya akan membuat dummy data yang akan dimasukkan pada document excel nantinya, seperti berikut ini</p><pre>class DummyData {<br>    let contact1 = Contact(name: &quot;Normal&quot;, gender: &quot;Male&quot;, address: &quot;Address 1&quot;, image: &quot;person.fill&quot;)<br>    <br>    let contact2 = Contact(name: &quot;Right&quot;, gender: &quot;Male&quot;, address: &quot;Address 2&quot;, image: &quot;person.fill.turn.right&quot;)<br>    <br>    let contact3 = Contact(name: &quot;Left&quot;, gender: &quot;Female&quot;, address: &quot;Address 3&quot;, image: &quot;person.fill.turn.left&quot;)<br>    <br>    let contact4 = Contact(name: &quot;Bottom&quot;, gender: &quot;Female&quot;, address: &quot;Address 4&quot;, image: &quot;person.fill.turn.down&quot;)<br>    <br>    lazy var contacts: [Contact] =<br>    [ contact1, contact2, contact3, contact4 ]<br>}</pre><h3>Membuat Excel Document</h3><p><strong>Setup Workbook</strong><br>Hal pertama yang harus dilakukan adalah membuat sebuah workbook dan menyimpannya pada folder temporary dimana folder ini diizinkan untuk diakses sementara saat kamu nanti melakukan perubahan pada workbook. Setelah workbook dibuat, kamu juga bisa menambahkan worksheet sama seperti document excel pada umumnya, satu workbook dapat memuat banyak worksheet. Untuk membuat workbook, sederhana kamu dapat mendeklarasikannya layaknya sebuah variable seperti berikut</p><pre>func generateExcelFile(){<br>        let fileName = &quot;DummyExcel.xlsx&quot;<br>        let filePath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0].appending(&quot;/\(fileName)&quot;)<br>        <br>        var workbook = workbook_new(filePath)<br>        <br>}</pre><p><strong>Add Worksheet</strong><br>Selanjutnya, kamu perlu menambahkan worksheet untuk memasukkan data seperti berikut</p><pre>func generateExcelFile(){<br>        .....<br><br>        var worksheet = workbook_add_worksheet(workbook, nil)<br>        <br>}</pre><p><strong>Menambahkan Data, Mengatur Style dan Mengatur Ukuran Cell<br></strong>Untuk menambahkan data, mengatur style cell serta mengubah ukuran cell, kamu dapat melakukannya dengan mengakses beberapa method pada xlsxwriter seperti berikut</p><pre>func generateExcelFile(contacts: [Contact]){<br>        .......<br><br>        // Setup Style<br>        let format_header = workbook_add_format(workbook)<br>        format_set_bold(format_header)<br>        let format_1 = workbook_add_format(workbook)<br>        format_set_bg_color(format_1, 0xDDDDDD)<br><br>        //Create Header<br>        var writingLine = 0<br>        let format = format_header<br>        format_set_bold(format)<br>        worksheet_write_string(worksheet, writingLine, 0, &quot;No&quot;, format)<br>        worksheet_write_string(worksheet, writingLine, 1, &quot;Image&quot;, format)<br>        worksheet_write_string(worksheet, writingLine, 2, &quot;Name&quot;, format)<br>        worksheet_write_string(worksheet, writingLine, 3, &quot;Gender&quot;, format)<br>        worksheet_write_string(worksheet, writingLine, 4, &quot;Address&quot;, format)<br>        <br>        for contact in contacts {<br>            writingLine += 1<br>            <br>            worksheet_write_string(worksheet, writingLine, 0, &quot;\(writingLine)&quot;, nil)<br>            worksheet_write_string(worksheet, writingLine, 2, contact.name, nil)<br>            worksheet_write_string(worksheet, writingLine, 3, contact.gender, nil)<br>            worksheet_write_string(worksheet, writingLine, 4, contact.address, nil)<br>            <br>        }<br><br>        //Define Cell Size<br>        let cell_width: Double = 50<br>        let cell_height: Double = 50<br>        <br>        for (index, contact) in contacts.enumerated() {<br>            let row = UInt32(index + 1)<br>            worksheet_set_row(worksheet, row, Double(cell_height), nil)<br>            let image = UIImage(systemName: contact.image)!<br>            var options = lxw_image_options()<br>            <br>            // Pixel size is Point size x image scale<br>            let imageScale = image.scale<br>            let uiimageSizeInPixel = (Double(image.size.width * imageScale), Double(image.size.height * imageScale))<br>            let scale = Helper.minRatio(left: (cell_width, cell_height),<br>                                        right: uiimageSizeInPixel )<br>            options.x_offset = 10<br>            options.y_offset = 1<br>            options.x_scale = scale<br>            options.y_scale = scale<br>            options.object_position = 1<br>            <br>            if let nsdata = image.jpegData(compressionQuality: 0.9) as NSData? {<br>                let buffer = Helper.getArrayOfBytesFromImage(imageData: nsdata)<br>                worksheet_insert_image_buffer_opt(worksheet, row, 1, buffer, buffer.count, &amp;options)<br>            }<br>            <br>        }<br>        workbook_close(workbook)<br>        <br>        let docURL = URL(fileURLWithPath: filePath)<br>        self.documentItemsExport = [docURL as Any]<br>    }<br><br>class Helper {<br>    /// Update NSData to buffer for xlsxwriter<br>    static func getArrayOfBytesFromImage(imageData: NSData) -&gt; [UInt8] {<br>        //Determine array size<br>        let count = imageData.length / MemoryLayout.size(ofValue: UInt8())<br>        //Create an array of the appropriate size<br>        var bytes = [UInt8](repeating: 0, count: count)<br>        //Copy image data as bytes into the array<br>        imageData.getBytes(&amp;bytes, length:count * MemoryLayout.size(ofValue: UInt8()))<br><br>        return bytes<br>    }<br>    <br>    static func minRatio(left: (Double, Double), right: (Double, Double)) -&gt; Double {<br>        min(left.0 / right.0, left.1 / right.1)<br>    }<br>    <br>}</pre><p><strong>Membuat Custom Share Sheet<br></strong>Untuk menyimpan dan share document excel yang sudah dibuat, kamu dapat memanfaatkan UIActivityController</p><pre>struct ShareSheetView: UIViewControllerRepresentable {<br>    typealias UIViewControllerType = UIActivityViewController<br>    <br>    @Binding var items: [Any]<br>    <br>    func makeUIViewController(context: UIViewControllerRepresentableContext&lt;ShareSheetView&gt;) -&gt; UIActivityViewController {<br>        <br>        let controller = UIActivityViewController(activityItems: items, applicationActivities: nil)<br>        <br>        controller.completionWithItemsHandler = { (activityType: UIActivity.ActivityType?, completed: Bool, returnedItems: [Any]?, error: Error?) -&gt; Void in<br>            if let url = items.first as? URL {<br>                try! FileManager.default.removeItem(at: url)<br>                items.removeAll()<br>            }<br>        }<br>        return controller<br>    }<br>    <br>    func updateUIViewController(_ uiViewController: UIActivityViewController, context: UIViewControllerRepresentableContext&lt;ShareSheetView&gt;) {<br>        <br>    }<br>}</pre><p>Finally, Implementasi ke View</p><pre>import SwiftUI<br>import xlsxwriter<br><br>struct ContentView: View {<br>    @State var documentItemsExport: [Any] = []<br>    @State private var showShareSheet: Bool = false<br>    <br>    <br>    var body: some View {<br>        VStack {<br>            ScrollView {<br>                ForEach(DummyData().contacts, id: \.name) { contact in<br>                    VStack {<br>                        Text(contact.name)<br>                            .font(.system(.title3).bold())<br>                        Text(contact.address)<br>                            .font(.system(.body))<br>                    }<br>                    .padding()<br>                }<br>            }<br>            <br>            Button(&quot;Export&quot;){<br>                generateExcelFile(contacts: DummyData().contacts)<br>                self.showShareSheet.toggle()<br>            }<br>            <br>        }<br>        .padding()<br>        .sheet(isPresented: self.$showShareSheet) {<br>            ShareSheetView(items: self.$documentItemsExport)<br>        }<br>    }</pre><p>Berikut hasil nya 👏🏻👏🏻</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*hCEjfBIWjoOQ1X0OnlS_CQ.gif" /><figcaption>Hasil Implementasi pada Iphone 14 Pro</figcaption></figure><p>Akhir kata selamat kamu sudah berhasil 🎉, jangan lupa cek post menarik mengenai iOS Development ya</p><p>Kamu bisa cek full project nya disini : <a href="https://github.com/rivaldofez/Medium-ExcelSwiftUI">rivaldofez/Medium-ExcelSwiftUI (github.com)</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c8497e6324e0" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>