Goodies - forceUnwrap https://forceunwrap.com Lift your Swift skills & career to the next level Fri, 09 Jun 2023 09:26:57 +0000 en-US hourly 1 https://wordpress.org/?v=7.0 https://forceunwrap.com/wp-content/uploads/2023/03/cropped-ForceUnwrap-32x32.jpg Goodies - forceUnwrap https://forceunwrap.com 32 32 Xcode 14 not showing errors https://forceunwrap.com/xcode-14-not-showing-errors/ https://forceunwrap.com/xcode-14-not-showing-errors/#respond Fri, 09 Jun 2023 09:26:56 +0000 https://forceunwrap.com/?p=443 As a passionate advocate for Apple products, I am thoroughly convinced that the Macs with the M1 chip have sparked a technological revolution. This is primarily because, for the second time, we have a Mac model that doesn’t necessitate annual replacement with a newer version. The Apple engineering team consistently strives to deliver the best software experience possible. However, my supposition is that they’re likely under pressure from Product teams and the ceaseless demand for rapid feature introductions. Consequently, due to this accelerated pace, we as software users sometimes experience the unintended consequences of features not functioning as optimally as they should.

Case in point, Xcode versions 14.3 and 14.3.1 appear to have compromised live issue functionality. This results in false errors being displayed, while genuine errors flicker briefly before vanishing. Unfortunately, I haven’t found the ideal solution for this, but I have discovered a viable temporary fix, at least until Apple addresses the issue.

The immediate workaround involves disabling the “Show live issues” feature.

Here’s how to do it:
– navigate to Xcode,
– select Settings,
– go to General, and then
– deselect the “Show live issues” checkbox.

This should serve as a provisional remedy, pending a permanent fix from Apple.

The post Xcode 14 not showing errors first appeared on forceUnwrap.

]]>
https://forceunwrap.com/xcode-14-not-showing-errors/feed/ 0
Undo the most recent local commits in Git https://forceunwrap.com/undo-the-most-recent-local-commits-in-git/ https://forceunwrap.com/undo-the-most-recent-local-commits-in-git/#respond Fri, 21 Apr 2023 12:03:29 +0000 https://forceunwrap.com/?p=402 In software development, Git is a vital tool for tracking changes, collaborating with others, and managing code versions. Maintaining good coding practices is crucial to ensuring that the codebase remains organized and updated. However, developers sometimes forget to rebase their feature branch with the main/develop branch, resulting in multiple conflicts during code integration. This article will guide you through the steps to rebase your feature branch and squash all the changes into a single commit, simplifying the rebase process and avoiding the need to resolve conflicts in every conflicting commit.

The post Undo the most recent local commits in Git first appeared on forceUnwrap.

]]>
Git is an essential tool for software development, allowing developers to track changes, collaborate with others, and manage code versions. One of the critical practices in Git is regularly updating your feature branch with the changes made in the main/develop branch. Doing so minimizes conflicts during code integration and ensures that your code stays up-to-date with the latest changes.

However, it’s not uncommon for developers to forget to rebase their feature branch and end up with multiple conflicts. So, what should you do in such a situation?

Here are the steps to rebase and skip conflict-solving in every conflicting commit:

Step 1: Ensure Your Local Develop Branch is Up-to-Date

Before starting, make sure that your local develop branch is up-to-date with the remote repository’s develop branch by using the following commands:

git checkout develop
git pull

This ensures that you have the latest changes made to the main/develop branch on your local machine.

Step 2: Reset the Feature Branch

Next, you need to reset your feature branch to a single commit, which will make the rebase process simpler. You can use the following command to reset your feature branch:

git checkout feature/newFeature
git reset --soft HEAD~<n>

Here, <n> is the number of commits you want to squash into a single commit. For example, if you want to squash the last 21 commits into a single commit, you can use git reset --soft HEAD~21.

Step 3: Create a New Commit

After resetting the branch, you can now create a new commit that represents all the changes made in the previous commits. You can use the following command to create a new commit:

git commit -m "New feature implementation"

Here, the commit message can be anything that describes the changes made in the feature branch.

Step 4: Rebase the Feature Branch

Now that you have a single commit representing all the changes made in the feature branch, you can rebase it onto the main/develop branch. Use the following command to do this:

git rebase develop

This will apply the changes made in the main/develop branch onto your feature branch.

Step 5: Resolve Conflicts

If there are any conflicts during the rebase process, Git will pause and prompt you to resolve them. However, since you have squashed all the changes into a single commit, you will only need to resolve conflicts once, instead of resolving conflicts in every conflicting commit.

Once you have resolved the conflicts, use the following command to continue the rebase process:

git rebase --continue

Step 6: Push Changes

After completing the rebase process, you can now push your changes to the remote repository. Use the following command to do this:

git push --force

The --force flag is required because you have rewritten the history of your feature branch.

In conclusion, by following these steps, you can rebase your feature branch and squash all the changes into a single commit, which will simplify the rebase process and help you avoid resolving conflicts in every conflicting commit. Remember to regularly update your feature branch with the changes made in the main/develop branch to.

The post Undo the most recent local commits in Git first appeared on forceUnwrap.

]]>
https://forceunwrap.com/undo-the-most-recent-local-commits-in-git/feed/ 0
Picker using struct in SwiftUI https://forceunwrap.com/picker-using-struct-in-swiftui/ https://forceunwrap.com/picker-using-struct-in-swiftui/#comments Sun, 07 Aug 2022 11:50:51 +0000 https://forceunwrap.com/?p=212 I have observed that there are numerous tutorials online that explain how to set up Picker in SwiftUI. However, most of them utilize a simple string array for data, which is not sufficient for more complex scenarios. Instead, you should use a struct or class. In this example, I will demonstrate how to use an array of custom structs.

Here is a sample code that shows how to create a Picker with custom struct data:

import SwiftUI

struct ContentView: View {
    private var cars = [
        Car(brand: "BMW", plates: "AAA111"),
        Car(brand: "Toyota", plates: "BBB222"),
        Car(brand: "Kia", plates: "CCC222")
    ]

    @State private var selectedCar = ""

    var body: some View {
        VStack {
            Picker("Car", selection: $selectedCar) {
                ForEach(cars, id: \.brand) {
                    Text("\($0.brand) \($0.plates)")
                }
            }
            Text("You selected: \(selectedCar)")
        }
    }
}

struct Car: Hashable, Identifiable {
    var id: String {
        return brand + plates
    }
    
    let brand: String
    let plates: String
}

In this example, the Car struct is used as the data source for the Picker. The selectedCar variable is now of type Car? to hold the selected car, instead of a String. Also, the id property has been removed from the Car struct because it is no longer necessary.

The accessibility modifier is used to provide an invisible label to the Picker for VoiceOver users. This ensures that the Picker is accessible to all users.

Finally, I removed the id argument in the ForEach because the Car struct is now identifiable by default. Therefore, you can use car directly instead of car.brand to reference the selected Car object.

            Picker("Car", selection: $selectedCar) {
                ForEach(cars) {
                    Text("\($0.brand) \($0.plates)")
                }
            }

The post Picker using struct in SwiftUI first appeared on forceUnwrap.

]]>
https://forceunwrap.com/picker-using-struct-in-swiftui/feed/ 2
SwiftUI TabView select any tab https://forceunwrap.com/swiftui-tabview-select-any-tab/ https://forceunwrap.com/swiftui-tabview-select-any-tab/#respond Sun, 10 Jul 2022 21:14:32 +0000 https://forceunwrap.com/?p=191

TabView sample with tabs from enum.

import SwiftUI

struct CustomTabBarView: View {
    @State var selectedTab: TabBarItem
    
    enum TabBarItem: String {
        case car
        case motorcycle
        
        var title: String {
            switch self {
            case .car:
                return "Car"
            case .motorcycle:
                return "Motorcycle"
            }
        }
        
        var imageName: String {
            switch self {
            case .car:
                return "car"
            case .motorcycle:
                return "bicycle"
            }
        }
    }
    
    var body: some View {
        TabView(selection: $selectedTab) {
            Text("Car 🚗🚗🚗")
                .tag(TabBarItem.car)
                .tabItem {
                    Label(TabBarItem.car.title, systemImage: TabBarItem.car.imageName)
                }
            
            Text("Motorcycle 🏍🏍🏍")
                .tag(TabBarItem.motorcycle)
                .tabItem {
                    Label(TabBarItem.motorcycle.title, systemImage: TabBarItem.motorcycle.imageName)
                }
        }
    }
}

You can now use the TabView in your navigation. This allows setting any tab as active tab.

import SwiftUI

struct ContentView: View {
    var body: some View {
        CustomTabBarView(selectedTab: .motorcycle)
    }
}

The post SwiftUI TabView select any tab first appeared on forceUnwrap.

]]>
https://forceunwrap.com/swiftui-tabview-select-any-tab/feed/ 0
Detect iOS/iPadOS app running on Mac https://forceunwrap.com/detect-ios-app-running-on-mac/ https://forceunwrap.com/detect-ios-app-running-on-mac/#respond Tue, 14 Jun 2022 10:05:49 +0000 https://forceunwrap.com/?p=163 Detect Mac Catalyst

    static var isMacCatalyst: Bool {
    #if targetEnvironment(macCatalyst)
        return true
    #else
        return false
    #endif
    }

Detect iOS/iPadOS running on Apple Silicon Mac

    static var isiOSAppOnMac: Bool {
        guard #available(iOS 14.0, *)
        else {
            return false
        }
        return ProcessInfo.processInfo.isiOSAppOnMac
    }

The post Detect iOS/iPadOS app running on Mac first appeared on forceUnwrap.

]]>
https://forceunwrap.com/detect-ios-app-running-on-mac/feed/ 0