adding a slideshow to webview app

hello I have created a webview app but it got rejected for not being interactive enough or not using iOS features. so I want to put an image slideshow in. however I get an error code when trying to put the code in

code-block //

//  ContentView.swift

//  BEMCO iOS

//

//  Created by Lewis Dunn on 06/01/2023.

//

import SwiftUI

import WebKit

import UIKit

struct ContentView_Previews: PreviewProvider { 
    static var previews: some View {
        ContentView()
    }
}
struct ContentView: View {
    let webView = WebView(request: URLRequest(url: URL(string: "https://www.apple.com")!))
    var body: some View {
        VStack {
            webView
            HStack {
                Button(action: {
                    self.webView.goBack()
                }) {
                    Image(systemName: "arrowshape.left")
                        .font(.title)
                        .foregroundColor(.blue)
                    }
                Spacer()
                Button(action: {
                    self.webView.goHome()
                }) {
                    Image(systemName: "house.fill")
                        .font(.title)
                        .foregroundColor(.blue)
                }
                Spacer()
                Button(action: {
                    self.webView.goForward()
                }) {
                    Image(systemName: "arrowshape.right")
                        .font(.title)
                        .foregroundColor(.blue)
                }
            }
        }
    }
}
struct WebView: UIViewRepresentable {
    let request: URLRequest
    private var webView: WKWebView?
    init (request: URLRequest) {
        self.webView = WKWebView()
        self.request = request
    }
    func makeUIView(context: Context) -> WKWebView {
return webView!
    }
    func updateUIView(_ uiView: WKWebView, context: Context) {
        uiView.load(request)
    }
    func goBack() {
    webView?.goBack()
   }
    func goForward() {
   webView?.goForward()
    }
    func goHome() {
        webView?.load(request)
    }

}

@State private var currentIndex = 0 _**(error is here: property wrappers are not supported in top level code) **_

let images : [String] = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19"]
var body : some View {
    VStack {
        Image(images[currentIndex])
            .resizable()
            .scaledToFit()
        HStack{
            ForEach(0..<images.count){ index in
                Circle()
                    .fill(self.currentIndex == index ? Color.gray : Color.blue) _**(cannot find self in scope)**_
                    .frame(width: 10, height: 10)
            }
        }
        .onAppear{
            print("Appear")
            // We are going to use Timers
            Timer.scheduledTimer(withTimeInterval: 2, repeats: true){ timer in
                if self.currentIndex + 1 == self.images.count{
                    self.currentIndex = 0

                }else{

                    self.currentIndex += 1

                }

            }

        }

    }

}





@State private var currentIndex = 0 **(error is here: property wrappers are not supported in top level code) **

This should be inside a struct.

My guess is that you have a misplaced closing curly brace

    func goHome() {
        webView?.load(request)
    }
    
}  // <<-- TRY REMOVE THIS and  probably move at the end

That will also solve : (cannot find self in scope)

However, there is an error with

struct WebView: UIViewRepresentable {

if you define the body inside it.

You should separate ViewController and View.

Get details here: https://stackoverflow.com/questions/57905693/uiviewcontrollerrepresentable-requires-the-types-some-view-and-never-be-equi

You have also an error with:

                ForEach(0..<images.count){ index in

You should define:

    let images : [String] = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19"]
    let imagesCount = 19

And use as:

                ForEach(0..<imagesCount){ index in

Thanks for the reply it got rid of the scope and top code wrappers issue. I have a yellow warning now here

and also I'm not sure where to put the code to do with separating the view and view controller. Where it says

it has 2 errors saying: UIViewRepresentable requires the types some view and Never be equivalent Type WebVuew does not conform to protocol UIViewRepresentable

yellow warning:

 ForEach(0..<imagesCount){ index in

2 errors :

struct WebView: UIViewRepresentable { **error is here**

    let request: URLRequest

    private var webView: WKWebView?

    init (request: URLRequest) {

        self.webView = WKWebView()

        self.request = request

Any ideas?

adding a slideshow to webview app
 
 
Q