Slide 1

Slide 1 text

J04ΞϓϦ࡞੒ೖ໳ ,.$OPOZMFOF

Slide 2

Slide 2 text

͜ͷεϥΠυʹ͍ͭͯ w य़߹॓Ͱൃදͨ͠΋ͷ w "OESPJEฤʢ຅εϥΠυʣ΋͋Γ·ͪ͢͜Β

Slide 3

Slide 3 text

ࣗݾ঺հ w OPOZMFOF ͷʹΕΜ w ,.$ೋճੜSPPU w (JU)VCIBUFOBFUDʜ w QZUIPO KBWB "OESPJE 
 ,PUMJOFUDʜ

Slide 4

Slide 4 text

࿩͢͜ͱ

Slide 5

Slide 5 text

J04ͷجຊ

Slide 6

Slide 6 text

J04ΞϓϦ࣮૷

Slide 7

Slide 7 text

࡞੒͢ΔΞϓϦ

Slide 8

Slide 8 text

4UBDL0WFSqPXݕࡧ

Slide 9

Slide 9 text

4UBDLFS

Slide 10

Slide 10 text

."%&*/ )"/"4&

Slide 11

Slide 11 text

࢖͏"1* w 4UBDL0WFSqPX"1* w ΈΜͳେ޷͖ɺϓϩάϥϛϯάͷ2"αΠτ w QVCMJD"1*Ͱݕࡧ΍ৄࡉ͕औΕΔ

Slide 12

Slide 12 text

4UBDL0WFSqPX"1* w υΩϡϝϯτ w IUUQTBQJTUBDLFYDIBOHFDPNEPDT w TFBSDI"1* ྫλΠτϧʹ4XJGU w IUUQTBQJTUBDLFYDIBOHFDPNTFBSDI PSEFSEFTDTPSUBDUJWJUZJOUJUMFTXJGUTJUF TUBDLPWFSqPXpMUFSGQO[U%1

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

(JU)VC IUUQTHJUIVCDPN OPOZMFOF4UBDLFSJ04

Slide 15

Slide 15 text

8IZJ04 w "OESPJEΛͯ͠Δͱત·͘͠ͳΔ w TXJGU࠷ߴͦ͏ w ΤϛϡϨʔλૣͦ͏ w όʔδϣϯ໰୊ͳͦ͞͏ w ؀ڥྑͦ͞͏ w ྡࣳ੨໰୊

Slide 16

Slide 16 text

໨࣍ w J04ͱ͸ w ηοτΞοϓɾ)FMMP8PSME w ΞϓϦΛ࡞Δ w ײ૝

Slide 17

Slide 17 text

J04

Slide 18

Slide 18 text

J04ͱ͸ w "QQMFͷ04 w .BD049Λ࠶ߏ੒ͨ͠΋ͷ w J1IPOFJ1PEUPVDIJ1BE w ೔ຊʹ͓͚ΔγΣΞ͸ w ࠷৽͸

Slide 19

Slide 19 text

։ൃ؀ڥ w 0CK$4XJGU w ݩʑ0CK$ͷΈ͕ͩͬͨɺ
 ೥ʹ৽ݴޠ4XJGU͕ొ৔ w ࠓճ͸4XJGUΛ࢖͍·͢

Slide 20

Slide 20 text

։ൃ؀ڥ w 9DPEF w "QQMFͷ04༻ͷ*%& w "QQMF੡ɺNBDݶఆ w ࣮࣭ແྉ NBDΛങ͑͹

Slide 21

Slide 21 text

4XJGUͷจ๏ʢܰ͘ʣ class Piyo : Foo { var text: String? func makeHoge(str: String) -> Bar { self.text = str let hoge = Hoge(text: str) return home as! Bar } func printText() { print("text: " + text!) } } Optional
 (Nullable) Unwrap
 (NonNull) ఆ਺ ม਺ ֎෦Ҿ਺໊ Ωϟετ

Slide 22

Slide 22 text

ηοτΞοϓ

Slide 23

Slide 23 text

ςϯϓϨʔτ w 4JOHMF7JFX"QQMJDBUJPOΛબ୒

Slide 24

Slide 24 text

໊শઃఆ w "OESPJEͱಉ༷4UBDLFSʹ w ݴޠ͸4XJGU

Slide 25

Slide 25 text

όʔδϣϯ w J04͸ػछ͕"QQMF୺຤ͷΈ w ʢαϙʔτର৅ʣػछ͝ͱͷόʔδϣϯ͕ࠩͳ͍ w ࠷௿όʔδϣϯΛେ͖ΊʹઃఆͰ͖Δ

Slide 26

Slide 26 text

ΞϓϦΛىಈ w ୺຤Λ઀ଓɺ্ʹ͋Δl⾣z Λԡͯ͠ΞϓϦΛىಈ w J04͸ΤϛϡϨʔλ͕ૣ͍ w ࣮ػσόοά΋ແྉԽ

Slide 27

Slide 27 text

ॳظঢ়ଶΛோΊΔ

Slide 28

Slide 28 text

7JFX$POUSPMMFSTXJGU class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() } } w ը໘੍ޚ w ಛʹԿ΋͍ͯ͠ͳ͍

Slide 29

Slide 29 text

.BJOTUPSZCPBSE

Slide 30

Slide 30 text

4UPSZ#PBSE w ը໘ͷભҠ΍ϨΠΞ΢τͳͲΛܾఆ͢Δ w جຊతʹ͸9DPEFΛ௨ͯ͡࢖͏ w ࢖͍ํ͸ޙͰઆ໌ w ࣮ଶ͸YNM w ࠓ͸ViewController͕Ұͭ͋ΔͷΈ

Slide 31

Slide 31 text

1SPKFDU&EJUPS w ϓϩδΣΫτͷઃఆ w Ϗϧυ w ໊લ w όʔδϣϯ w FUDʜ

Slide 32

Slide 32 text

)FMMP8PSME

Slide 33

Slide 33 text

4UPSZ#PBSEΛ։͘

Slide 34

Slide 34 text

-BCFMΛυϥοάͯ͠഑ஔ https://gyazo.com/1ed1655e91611e4808c1f7b6dd71102a

Slide 35

Slide 35 text

)FMMP 8PSMEͱهೖ

Slide 36

Slide 36 text

ΞϓϦΛىಈ

Slide 37

Slide 37 text

J04 w ϨΠΞ΢τߏ੒͸͜ͷΑ͏ʹ4UPSZ#PBSEͰߦ͏ w Ϛ΢ε͕͋Δͱศར w ը໘͕େ͖͍ͱศར

Slide 38

Slide 38 text

ΞϓϦ࡞੒

Slide 39

Slide 39 text

ϑϩʔΛߟ͑Δ ᶃݕࡧϫʔυΛೖྗͤ͞Δ ᶅ"1*Λୟ͍ͯ݁ՌΛऔಘ ᶅ+40/Λॲཧ ᶆॲཧͨ݁͠ՌΛදࣔ͢Δ

Slide 40

Slide 40 text

ᶃݕࡧϫʔυΛೖྗ

Slide 41

Slide 41 text

ϨΠΞ΢τ࡞੒

Slide 42

Slide 42 text

ը໘Λ૊ΈཱͯΔ w ը໘ύʔπͷ͜ͱΛViewͱ͍͏ w ೖྗཝͱϦετදࣔͷύʔπΛ্Լʹฒ΂Δ

Slide 43

Slide 43 text

4FBSDI#BSͷઃஔ

Slide 44

Slide 44 text

5BCMF7JFXͷઃஔ

Slide 45

Slide 45 text

5BCMF7JFXΛ޿͛Δ

Slide 46

Slide 46 text

w 4FBSDI#BS w ݕࡧόʔ w 5BCMF7JFX w ಉ͡छྨͷ7JFXΛ܁Γฦ͠දࣔ͢Δ w ޙͰৄ͘͠આ໌ 5BCMF7JFX4FBSDI#BS

Slide 47

Slide 47 text

4FBSDI#BSͷઃఆ ೖྗώϯτ ςʔϚ

Slide 48

Slide 48 text

ϓϨϏϡʔ w "TTJTUBOU&EJUPSΛ࢖͏

Slide 49

Slide 49 text

ϓϨϏϡʔ w ӈଆදࣔʹ1SFWJFXΛબ୒

Slide 50

Slide 50 text

7JFX่յ

Slide 51

Slide 51 text

8IZ w ੲ͸J04͸ը໘αΠζ͕ಉͩͬͨ͡ w ͜ͷ࣌͸αΠζݻఆͰେৎ෉ͩͬͨ w ࠓ͸σόΠεʹΑͬͯҟͳΔ ˠ ಛఆͷը໘αΠζͰௐ੔͢ΔͱଞͰ߹Θͳ͍

Slide 52

Slide 52 text

"VUP-BZPVU w 7JFXͷҐஔɾαΠζΛ
 ʮ੍໿ $POTUSBJO ʯͰࢦఆ͢Δ w ࠓ·Ͱ͸ઈରతɺ͜Ε͸૬ରత

Slide 53

Slide 53 text

"VUP-BZPVU w ଞʢ਌ʣͷ7JFXͱͷʜ w ڑ཭Λࢦఆ͢Δ w 9Λἧ͑Δ w ෯Λἧ͑Δ w ॎԣൺΛࢦఆ͢ΔFUDʜ

Slide 54

Slide 54 text

"VUP-BZPVU w 7JFXΛબ୒ɺӈԼͷϘλϯ܈Ͱࢦఆ

Slide 55

Slide 55 text

4FBSDI#BSͷ੍໿ w ্Լࠨӈͷ7JFXͱ઀͢Δ ੍໿ͷ௥Ճ

Slide 56

Slide 56 text

4FBSDI#BSͷ੍໿ w ্Լࠨӈͷ7JFXͱ઀͢Δ

Slide 57

Slide 57 text

5BCMF7JFXͷ੍໿ w Լࠨӈͷ7JFXͱ઀͢Δ w ্͸4FBSDI#BSͳͷͰ ΋͏ܾఆ͍ͯ͠Δ

Slide 58

Slide 58 text

5BCMF7JFXͷ੍໿ w Լࠨӈͷ7JFXͱ઀͢Δ w ্͸4FBSDI#BSͳͷͰ ΋͏ܾఆ͍ͯ͠Δ

Slide 59

Slide 59 text

7JFX੒ޭ

Slide 60

Slide 60 text

ΞϓϦΛىಈ w Ϧετ෦෼͸ۭന w ԿΛදࣔͤ͞Δ͔Λ
 ·ܾͩΊ͍ͯͳ͍

Slide 61

Slide 61 text

4FBSDIˠจࣈྻऔಘ

Slide 62

Slide 62 text

ϑϩʔ w Ϣʔβʔ͕4FBSDIΛ࣮ߦ &OUFSΩʔ w ͦΕʹԠͯ͡(&5 3FRVFTUΛඈ͹͢ ᶄ

Slide 63

Slide 63 text

7JFX$POUSPMMFSͷ࡞੒ɾඥ෇͚

Slide 64

Slide 64 text

7JFX$POUSPMMFS w ViewΛ؅ཧ͢ΔΫϥε w ࠓ·Ͱ͸ViewControllerͷදࣔ͢ΔView Λઃఆ͍ͯͨ͠

Slide 65

Slide 65 text

.BJO7JFX$POUSPMMFS࡞੒ w ੍ޚͷͨΊʹMainViewControllerΛ࡞੒͢Δ

Slide 66

Slide 66 text

.BJO7JFX$POUSPMMFS࡞੒ w ੍ޚͷͨΊʹMainViewControllerΛ࡞੒͢Δ

Slide 67

Slide 67 text

7JFX$POUSPMMFSͷؔ࿈෇͚ w $VTUPN$MBTTʹઃఆ

Slide 68

Slide 68 text

7JFXͷඥ෇͚ w "TTJTUBOU&EJUPSӈʹMainViewController

Slide 69

Slide 69 text

7JFXͷඥ෇͚ w 7JFXΛબ୒$USMΛԡ͠ͳ͕Βυϥοά

Slide 70

Slide 70 text

7JFXͷඥ෇͚ w ૠೖ͍ͨ͠৔ॴʹΧʔιϧΛ߹ΘͤΔ

Slide 71

Slide 71 text

7JFXͷඥ෇͚ w ໊લΛೖྗ

Slide 72

Slide 72 text

7JFXͷඥ෇͚ w ඥ෇͚׬ྃʂʂʂ

Slide 73

Slide 73 text

https://gyazo.com/10b37a14a684630c5d176d95ca529180

Slide 74

Slide 74 text

Ωʔϫʔυऔಘ

Slide 75

Slide 75 text

Ωʔϫʔυऔಘ • Ϣʔβʔ͕ݕࡧΛ࣮ߦ͢Δ → func searchBarSearchButtonClicked
 (searchBar: UISearchBar)
 ͕ݺ͹ΕΔ → searchBar ͔ΒςΩετΛऔಘ͢Δ

Slide 76

Slide 76 text

import UIKit class MainViewController: UIViewController, UISearchBarDelegate { @IBOutlet weak var searchBar: UISearchBar! @IBOutlet weak var tableView: UITableView! override func viewDidLoad() { super.viewDidLoad() searchBar.delegate = self } } 6*4FBSDI#BS%FMFHBUF • UISearchBarDelegate Λ࣮૷
 (SearchBar ؔ܎ͷϝιουΛ࣮ߦͰ͖ΔΑ͏ʹ͢Δ)

Slide 77

Slide 77 text

import UIKit class MainViewController: UIViewController, UISearchBarDelegate { @IBOutlet weak var searchBar: UISearchBar! @IBOutlet weak var tableView: UITableView! override func viewDidLoad() { super.viewDidLoad() searchBar.delegate = self } } • searchBar ؔ܎ͷϝιουͷݺͼઌΛ self(ࣗ෼) ʹ 6*4FBSDI#BS%FMFHBUF

Slide 78

Slide 78 text

ϘλϯͷΫϦοΫ import UIKit class MainViewController: UIViewController, UISearchBarDelegate { … override func viewDidLoad() { super.viewDidLoad() searchBar.delegate = self } func searchBarSearchButtonClicked(searchBar: UISearchBar) { let searchText = searchBar.text } } • searchBarSearchButtonClicked ͕ݺ͹ΕΔͷͰɺ
 searchBar ͷςΩετΛऔಘ

Slide 79

Slide 79 text

"MFSUʹग़ͯ͠ΈΔ

Slide 80

Slide 80 text

ᶄ"1*Ͱ+40/औಘ

Slide 81

Slide 81 text

ωοτϫʔΫ w ࠓճ͸ϥΠϒϥϦΛ࢖Θͣʹੜ4XJGUͰ

Slide 82

Slide 82 text

func searchBarSearchButtonClicked(searchBar: UISearchBar) { let searchText = searchBar.text let encodedText = searchText!.
 stringByAddingPercentEncodingWithAllowedCharacters(
 .URLQueryAllowedCharacterSet())! let url = "https://api.stackexchange.com/2.2/search?~~~~" +
 encodedText + "&site=stackoverflow&filter=! 6JEajsykLFu3W" } 63-Λ࡞੒ w 63- Τϯίʔυ

Slide 83

Slide 83 text

ϦΫΤετΛ౤͛Δ w J04Ͱ͸6*ͷߋ৽ʹ࢖͏εϨου͸Ұͭ w ͜ͷεϨουҎ֎Ͱ6*ؔ܎Λ࿔ΔͱΤϥʔ w ωοτϫʔΫͷϦΫΤετ͸ɺ
 ϝΠϯεϨουͰߦ͏΂͖Ͱ͸ͳ͍ w ϦΫΤετʹ͕͔͔࣌ؒΔͱը໘͕ݻ·ΔͨΊ

Slide 84

Slide 84 text

ϦΫΤετΛ౤͛Δ • NSURLSession w όοΫάϥ΢ϯυͰ௨৴ͯ͘͠ΕΔ w J04ΑΓ࢖͏͜ͱ͕Ͱ͖Δ

Slide 85

Slide 85 text

NSURLSession.sharedSession().dataTaskWithURL(NSURL(string: url)!,
 completionHandler: {data, response, error in … dispatch_async(dispatch_get_main_queue(), { let message = NSString(data: data!, …)! as String let alert = UIAlertController(…, message: message, …) alert.addAction(UIAlertAction(title: "OK", …)) self.presentViewController(alert, …) }) }).resume() • ϥϜμࣜͷ಺෦͸ϝΠϯεϨουͰ͸ͳ͍ • ΞϥʔτΛग़͍͕ͨ͠མͪͯ͠·͏ /463-4FTTJPOΛ࢖ͬͨϦΫΤετ

Slide 86

Slide 86 text

NSURLSession.sharedSession().dataTaskWithURL(NSURL(string: url)!,
 completionHandler: {data, response, error in … dispatch_async(dispatch_get_main_queue(), { let message = NSString(data: data!, …)! as String let alert = UIAlertController(…, message: message, …) alert.addAction(UIAlertAction(title: "OK", …)) self.presentViewController(alert, …) }) }).resume() • dispatch_get_main_queue() Λ࢖ͬͯ
 ϝΠϯεϨουͰ࣮ߦ • ͜͜Ͱ͸ΞϥʔτΛग़͍ͯ͠Δ /463-4FTTJPOΛ࢖ͬͨϦΫΤετ

Slide 87

Slide 87 text

ᶅ+40/Λॲཧ

Slide 88

Slide 88 text

+40/Λύʔε try! NSJSONSerialization.JSONObjectWithData(data!, 
 options:NSJSONReadingOptions.MutableContainers) 
 as! NSDictionary as! [String: AnyObject] • KTPOΛΦϒδΣΫτʹม׵

Slide 89

Slide 89 text

+40/Λύʔε try! NSJSONSerialization.JSONObjectWithData(data!, 
 options:NSJSONReadingOptions.MutableContainers) 
 as! NSDictionary as! [String: AnyObject] • NSDictionary ʹม׵

Slide 90

Slide 90 text

+40/Λύʔε try! NSJSONSerialization.JSONObjectWithData(data!, 
 options:NSJSONReadingOptions.MutableContainers) 
 as! NSDictionary as! [String: AnyObject] • Swift ʹ͓͚Δ࿈૝഑ྻʹม׵

Slide 91

Slide 91 text

+40/Λύʔε try! NSJSONSerialization.JSONObjectWithData(data!, 
 options:NSJSONReadingOptions.MutableContainers) 
 as! NSDictionary as! [String: AnyObject] • ྫ֎Λແࢹ

Slide 92

Slide 92 text

σʔλอ࣋Ϋϥε

Slide 93

Slide 93 text

σʔλอ࣋Ϋϥε w ฦ͖ͬͯͨ+40/ΛಡΈࠐΈɺΫϥεʹ֨ೲ͢Δ w σʔλΛѻ͍΍͘͢͢ΔͨΊ

Slide 94

Slide 94 text

σʔλอ࣋Ϋϥε • Question ΫϥεΛ࡞Δ • Question.swift Λ࡞੒

Slide 95

Slide 95 text

import Foundation class Question { let isAnswered: Bool let ownerName: String let upVoteCount: Int let tags: [String] init(dict: [String: AnyObject]) { isAnswered = 
 dict["is_answered"] as! Bool upVoteCount = 
 dict["up_vote_count"] as! Int title = dict[“title"] as! String let owner = dict["owner"]
 as! [String: AnyObject] ownerName = owner["display_name"] as! String } }

Slide 96

Slide 96 text

import Foundation class Question { let isAnswered: Bool let ownerName: String let upVoteCount: Int let tags: [String] init(dict: [String: AnyObject]) { isAnswered = 
 dict["is_answered"] as! Bool upVoteCount = 
 dict["up_vote_count"] as! Int title = dict[“title"] as! String let owner = dict["owner"]
 as! [String: AnyObject] ownerName = owner["display_name"] as! String } }

Slide 97

Slide 97 text

import Foundation class Question { let isAnswered: Bool let ownerName: String let upVoteCount: Int let tags: [String] init(dict: [String: AnyObject]) { isAnswered = 
 dict["is_answered"] as! Bool upVoteCount = 
 dict["up_vote_count"] as! Int title = dict[“title"] as! String let owner = dict["owner"]
 as! [String: AnyObject] ownerName = owner["display_name"] as! String } }

Slide 98

Slide 98 text

KTPOΛ2VFTUJPOʹม׵ let dict = try! NSJSONSerialization.JSONObjectWithData(…)
 as! NSDictionary as! [String: AnyObject] let questions = (dict["items"] as! [[String: AnyObject]]).map{ item -> Question in Question(dict: item) }

Slide 99

Slide 99 text

RVFTUJPOT<>ͷUJUMFΛग़͢

Slide 100

Slide 100 text

ᶆॲཧͨ݁͠ՌΛදࣔ

Slide 101

Slide 101 text

5BCMF7JFX ಉ͡7JFXΛ܁Γฦ͠Ϧετදࣔ͢Δ7JFX

Slide 102

Slide 102 text

ී௨ʹ্͔ΒViewΛஔ͚͹͍͍͡ΌΜʁ

Slide 103

Slide 103 text

w ⚠ཁૉ͕ݸҎ্ʹͳΔ͜ͱ΋ w ྫ5XJUUFS w ͜ͷ࣌ݸಉ࣌ʹViewΛอ࣋ɾ؅ཧ͢Δʁ
 ˠ๲େͳϝϞϦɾॲཧΛফඅͯ͠͠·͏ 5BCMF7JFX

Slide 104

Slide 104 text

w Ϧετදࣔ͸ಉ͡ߏ଄ͷView͕࿈ͳΔ w จࣈྻ౳ͷ಺༰͕ҧ͏͚ͩ ˠɹอ࣋ɾ؅ཧ͸ը໘ʹදࣔ͞ΕΔViewͷΈ ˠɹҰ౓࡞ͬͨView͸࠶ར༻͠ɺ
 දࣔ࣌ʹ಺༰Λมߋ͢Δ 5BCMF7JFX

Slide 105

Slide 105 text

w ͢΂ͯΛอ࣋ɾ؅ཧ ී௨ͷ7JFX View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 ࣮ࡍͷදࣔྖҬ →

Slide 106

Slide 106 text

w อ࣋ɾ؅ཧ͸ը໘্ͷΈ 5BCMF7JFX TableView 3 4 5 6 7 8 9 10 11 ະੜ੒ ࣮ࡍͷදࣔྖҬ →

Slide 107

Slide 107 text

εΫϩʔϧ͞ΕΔͱʜ TableView 3 4 5 6 7 8 9 10 11 ະੜ੒ View ͷ࠶ར༻ දࣔྖҬ →

Slide 108

Slide 108 text

εΫϩʔϧ͞ΕΔͱʜ View 5 6 7 8 9 10 11 3 ->12 4 ->13 ະੜ੒ ← ৽͍͠஋Λઃఆ දࣔྖҬ →

Slide 109

Slide 109 text

Slide 110

Slide 110 text

Ϧετදࣔ ߲໨ͷViewΛ࡞੒ ˣ TableViewʹදࣔ

Slide 111

Slide 111 text

߲໨ͷ7JFX $FMM

Slide 112

Slide 112 text

࡞Γ·ͨ͠

Slide 113

Slide 113 text

*EFOUJpFSΛઃఆ w TableView͕CellΛ۠ผ͢Δͷʹඞཁ

Slide 114

Slide 114 text

w 2VFTUJPO5BCMF7JFX$FMMΛ࡞੒ w $FMMΛಠࣗΫϥεʹͯ͠؅ཧ $VTUPN7JFXΫϥε import UIKit class QuestionTableViewCell: UITableViewCell { }

Slide 115

Slide 115 text

$VTUPN7JFXʹඥ෇͚

Slide 116

Slide 116 text

$FMM಺ͷ7JFXΛඥ෇͚

Slide 117

Slide 117 text

$FMM಺ͷ7JFXΛඥ෇͚ import UIKit class QuestionTableViewCell: UITableViewCell { @IBOutlet weak var countLabel: UILabel! @IBOutlet weak var checkImageView: UIImageView! @IBOutlet weak var titleLabel: UILabel! @IBOutlet weak var tagLabel: UILabel! @IBOutlet weak var bodyLabel: UILabel! @IBOutlet weak var dateLabel: UILabel! @IBOutlet weak var authorLabel: UILabel! }

Slide 118

Slide 118 text

2VFTUJPOઃఆͰ6*ߋ৽ class QuestionTableViewCell: UITableViewCell { @IBOutlet weak var countLabel: UILabel! … var question: Question? { didSet { bindQuestion(question!) } } private func bindQuestion(question: Question) { countLabel.text = String(question.upVoteCount) checkImageView.hidden = !question.isAnswered … } } Setter

Slide 119

Slide 119 text

5BCMF7JFXʹදࣔ

Slide 120

Slide 120 text

class MainViewController: UIViewController, UISearchBarDelegate, 
 UITableViewDelegate, UITableViewDataSource { @IBOutlet weak var searchBar: UISearchBar! @IBOutlet weak var questionTableView: UITableView! override func viewDidLoad() { super.viewDidLoad() searchBar.delegate = self questionTableView.dataSource = self questionTableView.delegate = self } } w Delegate Λ࣮૷ 5BCMF7JFX

Slide 121

Slide 121 text

class MainViewController: UIViewController, UISearchBarDelegate, 
 UITableViewDelegate, UITableViewDataSource { @IBOutlet weak var searchBar: UISearchBar! @IBOutlet weak var questionTableView: UITableView! override func viewDidLoad() { super.viewDidLoad() searchBar.delegate = self questionTableView.dataSource = self questionTableView.delegate = self } } w UITableViewDelegateΫϦοΫ͞Εͨ࣌ͱ͔ w UITableViewDataSourceσʔλ͔Β$FMMΛ࡞Δ࣌ 5BCMF7JFX

Slide 122

Slide 122 text

• εΫϩʔϧͯ͠ Cell Λ࡞੒͢Δͱ͖ʹݺ͹ΕΔ • ৔ॴ͕Ҿ਺ͱͯ͠དྷΔ $FMMΛ࡞Δ func tableView(tableView: UITableView, cellForRowAtIndexPath 
 indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("questionCell",
 forIndexPath: indexPath) as! QuestionTableViewCell cell.question = self.questions[indexPath.row] return cell }

Slide 123

Slide 123 text

• ઌ΄Ͳࢦఆͨ͠ Identifier ΛೖΕͯ
 ࠶ར༻Մೳͳ Cell ΛಘΔ • ͳ͚Ε͹ࣗಈͰ࡞ͬͯ͘ΕΔ $FMMΛ࡞Δ func tableView(tableView: UITableView, cellForRowAtIndexPath 
 indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("questionCell",
 forIndexPath: indexPath) as! QuestionTableViewCell cell.question = self.questions[indexPath.row] return cell }

Slide 124

Slide 124 text

func tableView(tableView: UITableView, cellForRowAtIndexPath 
 indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("questionCell",
 forIndexPath: indexPath) as! QuestionTableViewCell cell.question = self.questions[indexPath.row] return cell } • ಘΒΕͨ Cell ͸ QuestionTableViewCell $FMMΛ࡞Δ

Slide 125

Slide 125 text

func tableView(tableView: UITableView, cellForRowAtIndexPath 
 indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("questionCell",
 forIndexPath: indexPath) as! QuestionTableViewCell cell.question = self.questions[indexPath.row] return cell } • อ͍࣋ͯ͠Δ Question Λ cell ʹηοτ $FMMΛ࡞Δ

Slide 126

Slide 126 text

w ηΫγϣϯͷ਺ • Cell ͷ਺ 5BCMF7JFXͷઃఆ func numberOfSectionsInTableView(tableView: 
 UITableView) -> Int { return 1 } func tableView(tableView: UITableView, 
 numberOfRowsInSection section: Int) -> Int { return self.questions.count }

Slide 127

Slide 127 text

5BCMF7JFXͷߋ৽ let dict = try! NSJSONSerialization.JSONObjectWithData(…)
 as! NSDictionary as! [String: AnyObject] self.questions = (dict["items"] as! [[String: AnyObject]]).map{ item -> Question in Question(dict: item) } self.questionTableView.reloadData() w tableViewʹσʔλͷߋ৽Λ఻͑Δ w ͜ΕͰCell͕࠶ಡΈࠐΈ͞ΕΔ

Slide 128

Slide 128 text

ΫϦοΫͯ͠4BGBSJΛ։͘ w tableViewͷCellΛΫϦοΫͨ࣌͠ʹݺ͹ΕΔ w CellΛ࡞Δؔ਺ͱ͸֎෦Ҿ਺໊͕ҧ͏ func tableView(tableView: UITableView, didSelectRowAtIndexPath 
 indexPath: NSIndexPath) { let question = questions[indexPath.row] let url = NSURL(string: question.link)! UIApplication.sharedApplication().openURL(url) }

Slide 129

Slide 129 text

w indexPath͔ΒQuestionΛऔಘ w question.linkΛSafariͰ։͘ ΫϦοΫͯ͠4BGBSJΛ։͘ func tableView(tableView: UITableView, didSelectRowAtIndexPath 
 indexPath: NSIndexPath) { let question = questions[indexPath.row] let url = NSURL(string: question.link)! UIApplication.sharedApplication().openURL(url) }

Slide 130

Slide 130 text

ΞϓϦΛىಈ

Slide 131

Slide 131 text

https://gyazo.com/d34d8f4caf0a48e1855c865cf1772748

Slide 132

Slide 132 text

ײ૝ w J04ྑ͍ w 4XJGU͸࠷ߴ w όʔδϣϯݹ͍ͷʹରԠ͠ͳͯ͘ྑ͍ w Ϗϧυૣ͍

Slide 133

Slide 133 text

ײ૝ w J04ͭΒ͍ w 0CKFDUJWF$ͷίʔυ͕ಡΊͳ͍ͱݫ͍͠ w ϥΠϒϥϦɾ4UBDL0WFS'MPX w υϥοάຖճ͢Δͷ໘౗ w 9DPEF͕Α͘མͪΔʢىಈ͸ૣ͍ʣ

Slide 134

Slide 134 text

͋Γ͕ͱ͏͍͟͝·ͨ͠

Slide 135

Slide 135 text

"OESPJEฤ͸ͪ͜Β