Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove duplicate previews from XCode 12.2?

Tags:

xcode

swiftui

I'm a beginner in XCode and clicked on duplicate preview twice and now I can't find a way to delete the duplicates. I'm sure this is something pretty simple but I've been searching and trying everything for like an hour and can't find a solution for it...

Can somebody help me?

enter image description here

like image 270
dpascoa Avatar asked Nov 28 '20 16:11

dpascoa


People also ask

How do I remove SwiftUI preview?

Editor menu > Canvas Show/Hide SwiftUI Preview with command + option + return shortcut.

Why do I have Xcode previews?

Now Xcode Previews is a new feature of Xcode that allows you to - that institute - minimize the amount of time you spend building and running and configuring your views to verify the changes that you are making. And to - and lets you focus on the things that you love doing best, which is building great apps.

How to delete derived data in Xcode?

This article shows you 2 different ways to delete derived data in Xcode 12.x and 13.x. 1. Open Xcode and go to Xcode > Preferences… as follows: 2. Select the Locations tab from the menu bar. Focus on the Derived Data section. Here you will see the path of the DerivedData folder on your Mac.

How to clear Xcode cache manually?

How to clear Xcode cache manually #1. Clean the build #2. Clean out the build folder #3. Reset Simulator content and settings #4. Delete derived data #5. iOS device support #6. Use Terminal

Is it okay to delete a folder in Xcode?

If something’s not working right, it is okay to delete this folder. So if you’re still having problems or things are working slow, try deleting derived data, which will force Xcode to recreate it when you next run it. In the menu, choose Window, then Organizer. Now select Projects, and then click Select your project.

Why is XCode not working on my project?

Delete Xcode's derived data Derived Data is the place for all temporary build info and project indexes. If something’s not working right, it is okay to delete this folder. So if you’re still having problems or things are working slow, try deleting derived data, which will force Xcode to recreate it when you next run it.


Video Answer


1 Answers

Already found where the problem was! Every time duplicate preview is clicked, it adds one more view in the code.

The code below shows where my "problem" was:

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        Group {
            ContentView()
            ContentView()
            ContentView()
        }
    }
}

To fix this "problem", simply remove two ContentView() from the code:

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        Group {
            ContentView()
        }
    }
}
like image 56
dpascoa Avatar answered Oct 23 '22 08:10

dpascoa