Learn Courses My Dashboard

TabView Slider / Image Slider Issues

Hi! I have some issues with my code. Im here to see what I did wrong and hopefully learn from it.

So I have this problem where the code says one thing and the preview shows the exact same thing that the code is saying. For example.

.frame(width: proxy.size.width, height: proxy.size.height / 3). .ignoresSafeArea(.all, edges: .top)

But the simulator don’t show that the image is ignoring the safe area on top?

So what’s up with that?

Second encounter.

I´m using a TabView in form of a slider since I don’t know how to do a slider otherwise.
BUT this brings to problems.

  1. Since the slider is on a timer, the timer never resets except when it goes to 5 seconds to start over. But when I interact with the slider and switch from the first picture to the second on like 3 seconds then the slider automatically skips the second picture since the timer went to 5 and goes to the third picture. I would like it to reset when I interact with the slider.

This is the code for the slider.

Import SwiftUI 

struct Tab1: View { 
      private var numberOfImages = 3 
      private let timer = Timer.publish(every: 10, on: .main, in: .common).autoconnect() 

     @State private var currentIndex = 0 
     var body: some View { 
          GeometryReader { proxy in 
                        TabView(selection:$currentIndex) { 
                        ForEach(0..<numberOfImages) { num in 
                       .frame(width: proxy.size.width, height: proxy.size.height / 3). .ignoresSafeArea(.all, edges: .top) 
                        .onReceive(timer, perform: { _ in  
                              withAnimation { 
                              currentIndex = currentIndex < numberOfImages ?  
                                    currentIndex + 1 : 0 
struct Tab1_Previews: PreviewProvider { 
static var previews: some View { 

As you can see I have my slider in a frame, is this the only way to do it or is it the smartest way?

Thanks for every kind of response since this helps me evolve into coding.