I am trying to make an ios app that simply open a URL. So basically a webview app. I am using XCode 12.4 and that's what I did:
- Create new project->iOS App --> (see image below)
- Create a new file:
ViewController.swift
-->
import WebKit
class WebViewController: UIViewController, WKNavigationDelegate {
var webView: WKWebView!
override func loadView() {
webView = WKWebView()
webView.navigationDelegate = self
view = webView
}
override func viewDidLoad() {
super.viewDidLoad()
let url = URL(string: "https://developer.apple.com")!
webView.load(URLRequest(url: url))
}
}
- Build and Run.
The issue is that the app continues to open on "Hello World" and I imagine the reason is that the MyappApp.swift
file is calling ContentView
instead of ViewController
import SwiftUI
@main
struct myappApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
How can I fix this?
Disclaimer: This is my first iOS app and I know little to nothing about iOS dev.
You are very close... Wrap your
WebViewController
in aUIViewControllerRepresentable
to make it compatible with SwiftUIAnd then reference your new SwiftUI
UIViewControllerRepresentable
in a SwiftUIstruct
. For example...Or...