Post

Replies

Boosts

Views

Activity

Closure containing a declaration cannot be used with result builder 'ViewBuilder
hello I have followed a video on how to add back, forward and a home button to a web view app as it was rejected for not being interactive enough. however I'm getting an 2 error messages while trying to run simulator in the content view page I'm getting Closure containing a declaration cannot be used with result builder 'ViewBuilder' at the end and in main page it says cannot find content view in scope code-block // import SwiftUI import WebKit import UIKit 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)     }     struct ContentView: View {         let webView = WebView(request: URLRequest(url: URL(string: "https://*****.com")!))             var body: some View {             VStack {                 webView                HStack {                     Button(action: {                         self.webView.goBack()                     }) {                         Image(systemName: "LeftArrow")                             .font(.title)                             .foregroundColor(.blue)                             .padding()                     }                     Spacer()                        Button(action: {                         self.webView.goHome()                     }) {                         Image(systemName: "Home")                             .font(.title)                             .foregroundColor(.blue)                             .padding()                     }                     Spacer()                         Button(action: {                         self.webView.goForward()                     }) {                         Image(systemName: "RightArrow")                             .font(.title)                             .foregroundColor(.blue)                             .padding()                     }                 }                 struct ContentView_Previews: PreviewProvider { ***error is here***)                     static var previews: some View {                         ContentView()                     }                 }             }         }     } } and then the main page import SwiftUI import WebKit @main struct BEMCO_iOSApp: App {     var body: some Scene {         WindowGroup {             ContentView() ***error is here***         }     } }
2
0
612
Feb ’23
PhotoPicker and WebView
Hi, I have created a web view app but it has been rejected as it wasn't "interactive and exciting" enough so I want to put a photo picker option in as well. I have entered the code and there are no errors however I can't see or access the photos as the only menu that appears is the one on the web view. Is there anything I can do to add this option somewhere so people can view the images? There is also back, home & forward buttons on the app.
0
0
407
Feb ’23
adding slideshow to app
hello I am trying to add a slideshow to my app but I am getting 2 error messages and 1 warning the code is as follows: // 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 MainView : View { var body : some View { VStack { } } struct MainViewController : UIViewControllerRepresentable { func makeUIViewController(context: UIViewControllerRepresentableContext<MainViewController>) -> UIHostingController<MainView> { return UIHostingController(rootView: MainView()) } func updateUIViewController(_ uiViewController: UIHostingController<MainView>, context: UIViewControllerRepresentableContext<MainViewController>) { let viewController = UIHostingController<MainViewController>(rootView:MainViewController())} } } struct ContentView: View { let webView = WebView(request: URLRequest(url: URL(string: "https://www.bemcouk.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 **{**2 errors are here _"UIViewRepresentable' requires the types 'some View' and 'Never' be equivalent _ and the other error is _"Type 'WebView' does not conform to protocol '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 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 var body : some View { VStack { Image(images[currentIndex]) .resizable() .scaledToFit() HStack{ ForEach(0..<imagesCount){ index in **warning is here. Non-constant range: argument must be an integer literal** Circle() .fill(self.currentIndex == index ? Color.gray : Color.blue) .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 } } } } } }
0
0
566
Mar ’23
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                 }             }         }     } }
4
0
993
Apr ’23