Xcode keeps giving me problems with this code

Xcode keeps saying

Invalid redeclaration of ‘ContentView’
Instance will be immediately deallocated because property ‘navigationDelegate’ is ‘weak’ * ‘weak’ may only be applied to class and class-bound protocol types, not ‘FilesView’ * Value of type ‘WebViewCoordinator’ has no member ‘getDocumentsDirectory’ * Value of type ‘WebViewCoordinator’ has no member ‘sanitizeFileName’
Value of type ‘[URLResourceKey: Any]’ has no member ‘totalFileAllocatedSize’

heres the code: l

`
import SwiftUI
import WebKit

@main
struct UDOWNLOADERZApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

struct ContentView: View {
    var body: some View {
        TabView {
            BrowserView()
                .tabItem {
                    Label("Browser", systemImage: "globe")
                }
            FilesView()
                .tabItem {
                    Label("Files", systemImage: "folder")
                }
            SettingsView()
                .tabItem {
                    Label("Settings", systemImage: "gearshape")
                }
        }
    }
}

struct BrowserView: View {
    @State private var webView = WKWebView()

    var body: some View {
        WebView(webView: $webView)
            .onAppear {
                let urls = ["https://youtube.com", "https://soundcloud.com"]
                for url in urls {
                    if let url = URL(string: url) {
                        let request = URLRequest(url: url)
                        webView.load(request)
                    }
                }
                webView.navigationDelegate = WebViewCoordinator(filesView: nil)
            }
    }
}

struct WebView: UIViewRepresentable {
    @Binding var webView: WKWebView

    func makeUIView(context: Context) -> WKWebView {
        return webView
    }

    func updateUIView(_ uiView: WKWebView, context: Context) {}
}

class WebViewCoordinator: NSObject, WKNavigationDelegate {
    weak var filesView: FilesView?

    init(filesView: FilesView?) {
        self.filesView = filesView
    }

    func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
        let jsCode = """
        (function() {
            var video = document.querySelector('video');
            var audio = document.querySelector('audio');
            var mediaElement = video || audio;
            if (mediaElement) {
                return {
                    src: mediaElement.src,
                    title: document.title || mediaElement.getAttribute('title') || 'Unknown'
                };
            }
            return null;
        })();
        """
        
        webView.evaluateJavaScript(jsCode) { [weak self] (result, error) in
            guard let resultDict = result as? [String: String], let urlString = resultDict["src"], let title = resultDict["title"], let url = URL(string: urlString) else { return }
            
            self?.downloadContent(url: url, title: title)
        }
    }

    func downloadContent(url: URL, title: String) {
        DispatchQueue.global().async {
            let destinationURL = getDocumentsDirectory().appendingPathComponent("(sanitizeFileName(fileName: title)).mp4")

            URLSession.shared.downloadTask(with: url) { [weak self] (tempURL, response, error) in
                guard let self = self, let tempURL = tempURL, error == nil else { return }
                do {
                    try FileManager.default.moveItem(at: tempURL, to: destinationURL)
                    DispatchQueue.main.async {
                        NotificationCenter.default.post(name: NSNotification.Name("DownloadCompleted"), object: nil)
                        self.filesView?.reloadFilesList()
                    }
                } catch {
                    print("Download failed: (error.localizedDescription)")
                }
            }.resume()
        }
    }
}

struct FilesView: View {
    @State private var downloadedFiles = [String]()
    @State private var storageTaken: String = ""

    var body: some View {
        VStack {
            List {
                ForEach(downloadedFiles, id: .self) { file in
                    Text(file)
                }
            }
            Text("Storage Taken: (storageTaken)")
        }
        .onAppear(perform: loadFiles)
        .onReceive(NotificationCenter.default.publisher(for: NSNotification.Name("DownloadCompleted"))) { _ in
            loadFiles()
        }
    }

    func loadFiles() {
        DispatchQueue.global().async {
            do {
                let files = try FileManager.default.contentsOfDirectory(at: getDocumentsDirectory(), includingPropertiesForKeys: nil, options: [])
                DispatchQueue.main.async {
                    downloadedFiles = files.map { $0.lastPathComponent }
                    calculateStorageTaken(files: files)
                }
            } catch {
                print("Failed to load files: (error.localizedDescription)")
            }
        }
    }

    func reloadFilesList() {
        loadFiles()
    }

    private func calculateStorageTaken(files: [URL]) {
        let size = files.reduce(0, { $0 + ($1 as NSURL).fileSize() })
        storageTaken = ByteCountFormatter.string(fromByteCount: Int64(size), countStyle: .file)
    }
}

struct SettingsView: View {
    var body: some View {
        VStack {
            Text("Contact: [email protected]")
            Text("Twitter: N/A")
        }
    }
}

func getDocumentsDirectory() -> URL {
    let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
    return paths[0]
}

func sanitizeFileName(fileName: String) -> String {
    let invalidCharacters = CharacterSet(charactersIn: "\/:*?"<>|")
    return fileName.components(separatedBy: invalidCharacters).joined(separator: "_")
}

extension NSURL {
    func fileSize() -> Int {
        guard`

`

I tried rejusting the code and it still didnt work.

New contributor

rights4a is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật