Thunderhead ONE Search Results
Version 1.2.0
ThunderheadOneSearchResults is a simple module for displaying a list of top google search results for Thunderhead ONE. It utilizes Google's Custom Search JSON API to fetch top google search results for Thunderhead ONE.
Requirements
- iOS 12.0+
- Swift 5.0
Cocoapods
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '12.0'
use_frameworks!
target '<Your Target Name>' do
pod 'ThunderheadOneSearchResults', '1.2.0'
end
Getting Started
The simplest way to get started is by attaching a SearchResultsView to your UIViewController view property.
There are 2 ways you can do this.
- Through interface builder, by adding a UIView of class type SearchResultsView to your UIViewController view property.
import UIKit
import ThunderheadOneSearchResults
class SearchResultsController: UIViewController {
@IBOutlet weak private var searchResultsView: SearchResultsView!
override func viewDidLoad() {
super.viewDidLoad()
searchResultsView.configure(
viewModel: SearchResultsViewModel(
searchServices: GoogleSearchServices(key: "AIzaSyCwDCCzK1a9ePx34ayA15Q8WKuiomJ58IE", searchEngineId: "014048833371632418532:eldqtbklbnq"),
amount: 10))
}
}
Add a UIView to your UIViewController and set the class type to SearchResultsView like so:
- Instantiate the SearchResultsView programmatically and add it as a subview to your UIViewController view property.
import UIKit
import ThunderheadOneSearchResults
class ProgrammaticSearchResultsController: UIViewController {
private var searchResultsView: SearchResultsView!
override func viewDidLoad() {
super.viewDidLoad()
searchResultsView = SearchResultsView(frame: view.bounds)
view.addSubview(searchResultsView)
searchResultsView.configure(
viewModel: SearchResultsViewModel(
searchServices: GoogleSearchServices(key: "AIzaSyCwDCCzK1a9ePx34ayA15Q8WKuiomJ58IE", searchEngineId: "014048833371632418532:eldqtbklbnq"),
amount: 10))
}
}
Next, you will need to provide a SearchResultsViewModel to your SearchResultsView by calling configure on your SearchResultsView.
SearchResultsViewModel takes a service that conforms to SearchServicesProtocol.
The service you will use for the SearchResultsViewModel is GoogleSearchServices. In order to use GoogleSearchServices you will need to first create a custom search engine and obtain a search engine id and google key for accessing their JSON API. Both the key and searchEngineId are required for initializing GoogleSearchServices.
Refer to Google Custom Search JSON API here for creating a custom search engine and key: https://developers.google.com/custom-search/v1/overview.
GoogleSearchServices will query google's JSON API using "Thunderhead ONE" and provide the top search results to SearchResultsView.
For testing, feel free to use the same "key" and "searchEngineId" from the example project. You can also use a service provided by this framework called MockGoogleSearchServices which will return some dummy SearchResult objects.