I want to open Google search page for a given query using swift. Here is my code that opens the google web page on my default browser but i need it to open search results for a given query. How to go about it? I am new to swift.
if let url = URL(string: "https://www.google.com"), NSWorkspace.shared.open(url) {
print("default browser was successfully opened")
}
Try using this code:
The “search” constant would be whatever you want to search. This won’t work for spaces however. For a space you would want to have a “+” in between each word instead of a space.