Posts

Post not yet marked as solved
2 Replies
7.0k Views
Hi,create macOS project and I try to make UIViewRepresentable but get this error.import SwiftUI struct WebView: UIViewRepresentable { //Error: Use of undeclared type 'UIViewRepresentable' }What can I do with it or how can I make my own UIViewRepresentable for macOS to use WKWebView in my project?struct WebView: UIViewRepresentable { func makeUIView(context: Context) -> WKWebView { WKWebView() } func updateUIView(_ uiView: WKWebView, context: Context) { } }My question on stackoverflow
Posted
by filimo.
Last updated
.
Post not yet marked as solved
1 Replies
800 Views
I don't understand when I try to remove all items by calling viewContext.execute(deleteRequest) SwiftUI doesn't redraw UI. I see items from sqlite are gone. swift struct CloudKitTestView: View { @Environment(\.managedObjectContext) private var viewContext @FetchRequest( sortDescriptors: [NSSortDescriptor(keyPath: \Item.timestamp, ascending: true)], animation: .default) private var items: FetchedResultsItem var body: some View { VStack { Button("Remove all") { let fetchRequest = NSFetchRequestNSFetchRequestResult(entityName: "Item") let deleteRequest = NSBatchDeleteRequest(fetchRequest: fetchRequest) do { try viewContext.execute(deleteRequest) } catch { // Replace this implementation with code to handle the error appropriately. // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. let nsError = error as NSError fatalError("Unresolved error \(nsError), \(nsError.userInfo)") } } List { ForEach(items) { item in Text("Item at \(item.timestamp!, formatter: itemFormatter)") } .onDelete(perform: deleteItems) } .toolbar { #if os(iOS) EditButton() #endif Button(action: addItem) { Label("Add Item", systemImage: "plus") } } } } private func addItem() { withAnimation { let newItem = Item(context: viewContext) newItem.timestamp = Date() do { try viewContext.save() } catch { // Replace this implementation with code to handle the error appropriately. // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. let nsError = error as NSError fatalError("Unresolved error \(nsError), \(nsError.userInfo)") } } } private func deleteItems(offsets: IndexSet) { withAnimation { offsets.map { items[$0] }.forEach(viewContext.delete) do { try viewContext.save() } catch { // Replace this implementation with code to handle the error appropriately. // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. let nsError = error as NSError fatalError("Unresolved error \(nsError), \(nsError.userInfo)") } } } }
Posted
by filimo.
Last updated
.
Post not yet marked as solved
2 Replies
5k Views
I face an issue when I put WKWebView to View. As you can see Web page doesn't show from the begin.When I change the app window size the page shows correctly.What could be the problem?import SwiftUI import WebKit struct WebView: NSViewRepresentable { func makeNSView(context: Context) -> WKWebView { let view = WKWebView() guard let url = URL(string: "https://github.com/filimo/ReaderTranslator") else { return view } view.load(URLRequest(url: url)) return view } func updateNSView(_ view: WKWebView, context: Context) { } } struct WKWebViewDemo: View { var body: some View { WebView() } }I left the link with images on https://stackoverflow.com/q/58491837/4067700If I added Text with multiple lines then WebView is trunced of the top.var body: some View { VStack { Text("line\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\n") WebView() } }
Posted
by filimo.
Last updated
.