-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPokemonSearchViewController.swift
More file actions
49 lines (31 loc) · 1.22 KB
/
PokemonSearchViewController.swift
File metadata and controls
49 lines (31 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//
// PokemonSearchViewController.swift
// Pokedex
//
// Created by Sean Gleason on 10/18/16.
// Copyright © 2016 SeanGleason. All rights reserved.
//
import UIKit
class PokemonSearchViewController: UIViewController, UISearchBarDelegate {
@IBOutlet weak var searchBar: UISearchBar!
@IBOutlet weak var nameLabel: UILabel!
@IBOutlet weak var idLabel: UILabel!
@IBOutlet weak var abilityLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
// Get search text from search bar
guard let searchTerm = searchBar.text else { return }
// Fetch Pokemon details
PokemonController.fetchPokemon(for: searchTerm) { (pokemon) in
DispatchQueue.main.async {
guard let pokemon = pokemon else { return }
self.nameLabel.text = " Name: \(pokemon.name)"
self.idLabel.text = "ID: \(pokemon.id)"
self.abilityLabel.text = "Abilities: \(pokemon.abilities.joined(separator: ", "))"
}
}
}
}