How do I Setup my UISearchBar connected to my UIWebView to be able to search on google with a word instead of a url. For example search apple instead of http://www.apple.com
Heres my code so far
import UIKit
import WebKit
class ViewController: UIViewController, UISearchBarDelegate {
@IBOutlet weak var searchBar: UISearchBar!
@IBOutlet weak var webView: UIWebView!
func searchBarSearchButtonClicked(searchBar: UISearchBar!) {
searchBar.resignFirstResponder()
var text = searchBar.text
var url = NSURL(string: text) //type "http://www.apple.com"
var req = NSURLRequest(URL:url)
self.webView!.loadRequest(req)
}
override func viewDidLoad() {
super.viewDidLoad()
let url = NSURL(string: "http://google.com")
let request = NSURLRequest(URL: url)
webView.loadRequest(request)
self.searchBar.delegate = self
}
}