# StoreSearch: Error in code on page 97

**URL:** <https://forums.kodeco.com/t/storesearch-error-in-code-on-page-97/22760>\
**Category:** iOS Apprentice\
**Created:** [November 16, 2016, 4:43pm UTC](https://forums.kodeco.com/t/storesearch-error-in-code-on-page-97/22760 "2016-11-16T16:43:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kickinbahk](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/kickinbahk/32/50350_2.png) [@kickinbahk](https://forums.kodeco.com/u/kickinbahk)\
**Post date:** [November 16, 2016, 4:43pm UTC](https://forums.kodeco.com/t/storesearch-error-in-code-on-page-97/22760/1 "2016-11-16T16:43:56Z")

</div>

This is the code from the book on page 97:

```
 func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
   if !searchBar.text!.isEmpty {
    searchBar.resignFirstResponder()
  
    isLoading = true
    tableView.reloadData()
  
    searchResults = []
    hasSearched = true
  
    let queue = DispatchQueue.global()
  
    queue.async {
      let url = self.iTunesUrl(searchText: searchBar.text!)
    
      if let jsonString = self.performStoreRequest(with: url) {
        let jsonDictionary = self.parse(json: jsonString) {
        self.searchResults = self.parse(dictionary: jsonDictionary)
        self.searchResults.sort(by: <)
        print("DONE!")
        return
      }
        print("Error!")
     }
   }
 }

```

If you try to use the code above it will give an error as it is missing the ‘if’ keyword on the second `let jsonDictionary = self....`

Here is the correct code:

```
func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
  if !searchBar.text!.isEmpty {
    searchBar.resignFirstResponder()
  
    isLoading = true
    tableView.reloadData()
  
    searchResults = []
    hasSearched = true
  
    let queue = DispatchQueue.global()
  
    queue.async {
       let url = self.iTunesUrl(searchText: searchBar.text!)
    
       if let jsonString = self.performStoreRequest(with: url) {
         if let jsonDictionary = self.parse(json: jsonString) {
           self.searchResults = self.parse(dictionary: jsonDictionary)
           self.searchResults.sort(by: <)
           print("DONE!")
           return
         }
         print("Error!")
       }
    } 
}

```

Hope that helps

---

<div class="post-metadata">

**Author:** ![hollance](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/hollance/32/109009_2.png) [@hollance](https://forums.kodeco.com/u/hollance)\
**Post date:** [November 16, 2016, 5:44pm UTC](https://forums.kodeco.com/t/storesearch-error-in-code-on-page-97/22760/2 "2016-11-16T17:44:51Z")

</div>

What was intended is this:

> [@kickinbahk](#):
>
> if let jsonString = self.performStoreRequest(with: url),  
> let jsonDictionary = self.parse(json: jsonString) {

so instead of the `{` there should be a `,` comma.
