diff --git a/apple/OmnivoreKit/Sources/App/Views/Home/LibraryAddLinkView.swift b/apple/OmnivoreKit/Sources/App/Views/Home/LibraryAddLinkView.swift index a66d668dd..7fb03a786 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Home/LibraryAddLinkView.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Home/LibraryAddLinkView.swift @@ -60,7 +60,7 @@ struct LibraryAddLinkView: View { var pasteboardString: String? { #if os(iOS) - UIPasteboard.general.url.absoluteString + UIPasteboard.general.url?.absoluteString #else NSPasteboard.general.string(forType: NSPasteboard.PasteboardType.URL) #endif diff --git a/apple/OmnivoreKit/Sources/Views/MacSearchBar.swift b/apple/OmnivoreKit/Sources/Views/MacSearchBar.swift index aeea28ee3..1dc915a9b 100644 --- a/apple/OmnivoreKit/Sources/Views/MacSearchBar.swift +++ b/apple/OmnivoreKit/Sources/Views/MacSearchBar.swift @@ -1,55 +1,57 @@ import SwiftUI -public struct MacSearchBar: NSViewRepresentable { - @Binding var searchTerm: String +#if os(macOS) + public struct MacSearchBar: NSViewRepresentable { + @Binding var searchTerm: String - public init( - searchTerm: Binding - ) { - self._searchTerm = searchTerm - } - - public func makeNSView(context _: Context) -> NSSearchField { - let searchField = NSSearchField(frame: .zero) - searchField.translatesAutoresizingMaskIntoConstraints = false - searchField.heightAnchor.constraint(greaterThanOrEqualToConstant: 28).isActive = true - searchField.resignFirstResponder() - - return searchField - } - - func changeSearchFieldItem(searchField: NSSearchField, sender: AnyObject) -> NSSearchField { - // Based on the Menu item selection in the search field the placeholder string is set - (searchField.cell as? NSSearchFieldCell)?.placeholderString = sender.title - return searchField - } - - public func updateNSView(_ searchField: NSSearchField, context: Context) { - searchField.font = searchField.font?.withSize(14) - searchField.stringValue = searchTerm - searchField.delegate = context.coordinator - searchField.resignFirstResponder() - } - - public func makeCoordinator() -> Coordinator { - let coordinator = Coordinator(searchTerm: $searchTerm) - return coordinator - } - - public class Coordinator: NSObject, NSSearchFieldDelegate { - var searchTerm: Binding - - init(searchTerm: Binding) { - self.searchTerm = searchTerm - super.init() + public init( + searchTerm: Binding + ) { + self._searchTerm = searchTerm } - public func controlTextDidChange(_ notification: Notification) { - guard let searchField = notification.object as? NSSearchField else { - // log.error("Unexpected control in update notification", source: .ui) - return + public func makeNSView(context _: Context) -> NSSearchField { + let searchField = NSSearchField(frame: .zero) + searchField.translatesAutoresizingMaskIntoConstraints = false + searchField.heightAnchor.constraint(greaterThanOrEqualToConstant: 28).isActive = true + searchField.resignFirstResponder() + + return searchField + } + + func changeSearchFieldItem(searchField: NSSearchField, sender: AnyObject) -> NSSearchField { + // Based on the Menu item selection in the search field the placeholder string is set + (searchField.cell as? NSSearchFieldCell)?.placeholderString = sender.title + return searchField + } + + public func updateNSView(_ searchField: NSSearchField, context: Context) { + searchField.font = searchField.font?.withSize(14) + searchField.stringValue = searchTerm + searchField.delegate = context.coordinator + searchField.resignFirstResponder() + } + + public func makeCoordinator() -> Coordinator { + let coordinator = Coordinator(searchTerm: $searchTerm) + return coordinator + } + + public class Coordinator: NSObject, NSSearchFieldDelegate { + var searchTerm: Binding + + init(searchTerm: Binding) { + self.searchTerm = searchTerm + super.init() + } + + public func controlTextDidChange(_ notification: Notification) { + guard let searchField = notification.object as? NSSearchField else { + // log.error("Unexpected control in update notification", source: .ui) + return + } + searchTerm.wrappedValue = searchField.stringValue } - searchTerm.wrappedValue = searchField.stringValue } } -} +#endif