Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Useful 3 techniques developing in iOS Apps

yashigani
April 18, 2015

Useful 3 techniques developing in iOS Apps

Cocoa study Kansai #61

yashigani

April 18, 2015
Tweet

More Decks by yashigani

Other Decks in Programming

Transcript

  1. ͓໾ཱͪςΫχοΫ࿈ൃ
    @yashigani
    Cocoaษڧձؔ੢ #61

    View full-size slide

  2. yashigani
    id:yashigani_w @yashigani
    Mobile Application Engineer
    http://yashigani.hatenablog.com
    Hatena

    View full-size slide

  3. IUUQDPOOQBTTDPNFWFOU

    View full-size slide

  4. IUUQDPOOQBTTDPNFWFOU

    View full-size slide

  5. IUUQDPOOQBTTDPN
    FWFOU

    View full-size slide

  6. ը໘αΠζʹ߹Θͤͯ
    6*4DSPMM7JFXΛ
    ͍͍͔Μ͡ʹ͢Δ
    @yashigani
    Cocoaษڧձؔ੢ #61

    View full-size slide

  7. ͜Ε4ͩͱͲ͏ͳΔΜͰ͔͢ʁ
    ͏ʔΜɼεΫϩʔϧ͠·͢

    View full-size slide

  8. ը໘αΠζຖʹϨΠΞ΢τ
    • ߴղ૾౓୺຤
    • ը໘ϐολϦʹ޿͛ͯηϯλϦϯά͢Δ
    • ௿ղ૾౓୺຤
    • ্Լʹద੾ͳϚʔδϯΛͱͬͯεΫϩʔϧ͢Δ

    View full-size slide

  9. Ṝ͍ΑΔ஍ࠈ
    • UIScrollView + Auto Layout
    • ୭΋͕ϋϚΔϙΠϯτ
    • Mixed Approach or Pure Auto Layout Aploach
    • https://developer.apple.com/library/ios/
    technotes/tn2154/_index.html
    • ઈରstoryboard͚ͩͰղܾ͍ͨ͠

    View full-size slide

  10. ཱͪ͸͔ͩΔ2ͭͷ՝୊
    • ը໘ʹೖΓ͖Βͳ͍ͱ͖͚ͩεΫϩʔϧ͍ͨ͠
    • ্Լʹ࠷௿ݶͷϚʔδϯΛઃ͚͍͕ͨɼ༨༟͕͋Δ
    ৔߹͸ແࢹͯ͠ηϯλϦϯά͍ͨ͠

    View full-size slide

  11. DPOUFOUTJ[F͸TVCWJFXͷ
    ੍໿ʹΑܾͬͯ·Δ

    View full-size slide

  12. ηϯλϦϯάͰ͖ͨ

    View full-size slide

  13. িಥ੍ͨ͠໿Λ
    ௥Ճ͢Δ

    View full-size slide

  14. ੍໿ʹ
    QSJPSJUZΛ͚ͭΔ

    View full-size slide

  15. ͜͏ͯ͠
    ৺ʹฏԺ͕๚Εͨ

    View full-size slide

  16. 6*5BCMF7JFX%BUB4PVSDF
    ࣮૷ύλʔϯ
    @yashigani
    Cocoaษڧձؔ੢ #61

    View full-size slide

  17. ͳͥ෼཭͢Δͷ͔
    • ϙʔλϏϦςΟ
    • ςετ༰қੑ
    • storyboardʹஔ͚Δ
    • view controllerΛdata sourceʹґଘͤ͞Δ
    • prepareForSegueͰϓϦϛςΟϒͳσʔλΛ΍Γͱ
    Γͨ͘͠ͳ͍

    View full-size slide

  18. TVCTDSJQUΛ࣮૷͢Δ

    View full-size slide

  19. class DataSource: NSObject {
    var models: [Model] = []
    subscript(indexPath: NSIndexPath) -> Model? {
    return models.isEmpty ? nil
    : models[indexPath.row]
    }
    }
    extension DataSource: UITableViewDataSource {
    func tableView(tableView: UITableView,
    cellForRowAtIndexPath indexPath: NSIndexPath)
    -> UITableViewCell {
    switch self[indexPath] {
    case .Some(let m):
    let cell =
    tableView.dequeueReusableCellWithIdentifier("Cell",
    forIndexPath: indexPath) as! ModelCell
    cell.configure(m)
    return cell
    default: abort()
    }
    }
    func tableView(tableView: UITableView,
    numberOfRowsInSection section: Int) -> Int {
    return models.count
    }
    }

    View full-size slide

  20. TFDUJPOΛ௥Ճ͢Δ

    View full-size slide

  21. enum Section: Int {
    case SectionA = 0
    case SectionB = 1
    var title: String {
    switch self {
    case .SectionA: return "SectionA"
    case .SectionB: return "SectionB"
    default: return ""
    }
    }
    }
    class DataSource: NSObject {
    var sectionA: [Model] = []
    var sectionB: [Model] = []
    }

    View full-size slide

  22. class DataSource: NSObject {
    subscript(section: Int) -> [Model]? {
    if let section = Section(rawValue: section) {
    let models: [Model]
    switch section {
    case .SectionA: models = sectionA
    case .SectionB: models = sectionB
    }
    return models
    } else {
    return nil
    }
    }
    subscript(indexPath: NSIndexPath) -> Model? {
    if let models = self[indexPath.section] {
    return models.isEmpty ? nil
    : models[indexPath.row]
    } else {
    return nil
    }
    }
    }

    View full-size slide

  23. extension DataSource: UITableViewDataSource {
    func tableView(tableView: UITableView,
    cellForRowAtIndexPath indexPath: NSIndexPath)
    -> UITableViewCell {
    switch self[indexPath] {
    case .Some(let m):
    let cell =
    tableView.dequeueReusableCellWithIdentifier("Cell",
    forIndexPath: indexPath) as! ModelCell
    cell.configure(m)
    return cell
    default: abort()
    }
    }
    func tableView(tableView: UITableView,
    numberOfRowsInSection section: Int) -> Int {
    return self[section]?.count ?? 0
    }
    }

    View full-size slide

  24. ઃܭ΋Α͘ͳͬͨ͠
    ܕ҆શʹͳͬͨ

    View full-size slide

  25. 8,8FC7JFXΛ
    γϡοͱ࢖͏།Ұͷํ๏
    @yashigani
    Cocoaษڧձؔ੢ #61

    View full-size slide

  26. ͓ͳ΍ΈϙΠϯτ
    • WKUIDelegateͷ࣮૷
    • ΞϥʔτΛॲཧ͢Δ͚ͩ
    • webView(_:createWebViewWithConfiguration:forNa
    vigationAction:windowFeatures:) -> WKWebView!
    • ΋͏KVO͸ॻ͖ͨ͘ͳ͍
    • storyboard͔Β௥ՃͰ͖ͳ͍

    View full-size slide

  27. 8FC,JU1MVT
    IUUQTHJUIVCDPNZBTIJHBOJ8FC,JU1MVT

    View full-size slide

  28. 8,6*%FMFHBUF1MVT

    View full-size slide

  29. • alert()ͷσϑΥϧτ࣮૷
    • ຖ౓ಉ͡΋ͷΛ࣮૷͠ͳͯ͘΋͍͍
    • target=“_blank”ͳϦϯΫ΋ϩʔυͰ͖Δ
    • ΋ͪΖΜ৔߹ʹΑͬͯ͸ผͷWKWebViewʹ
    • ࠩ͠ସ͑Δ͜ͱ΋Մೳ

    View full-size slide

  30. lazy var UIDelegate =
    WKUIDelegatePlus(self)
    override public func viewDidLoad()
    {
    super.viewDidLoad()
    webView.UIDelegate = UIDelegate
    }

    View full-size slide

  31. 8FC7JFX0CTFSWFS

    View full-size slide

  32. • WKWebView͸KVO compliantͳproperty͕ଟ͍
    • ͔͠͠KVOͳͲॻ͖ͨ͘͸ͳ͍
    • ؔ਺ͰobserveͰ͖ΔΑ͏ʹαϙʔτ

    View full-size slide

  33. lazy var observer =
    WebViewObserver(self.webView)
    override public func viewDidLoad()
    {
    super.viewDidLoad()
    observer.onTitleChanged =
    { [weak self] in
    self?.title = $0 }
    observer.onProgressChanged =
    { [weak self] in
    self?.progressbar.progress = $0
    }
    }

    View full-size slide

  34. ;FO8FC7JFX$POUSPMMFS

    View full-size slide

  35. • Zen = “ષ”
    • viewͷ࠷Լ૚ʹWKWebViewΛࠩ͠ࠐΉ
    • WKWebViewૢ࡞ͷͨΊͷIBAction
    • goBack/goForward/reload/stopLoading
    • WKUIDelegatePlus, WebViewObserverΛ࣮૷
    • storyboard͔Β࢖͑Δͧʂʂʂ

    View full-size slide

  36. %FNP4JNQMF#SPXTFS

    View full-size slide

  37. ͱʹ͔͘
    ͍·͙͢࢖ͬͯ͘Ε

    View full-size slide

  38. ࡶஊίʔφʔ
    @yashigani
    Cocoaษڧձؔ੢ #61

    View full-size slide

  39. • AFNetworking͕CarthageରԠڋ൱ͬͯΔ
    • https://github.com/AFNetworking/
    AFNetworking/pull/2552
    • LlamaKit͕ResultʹऔΓࠐ·ΕΔͷͭΒ͍
    • https://github.com/LlamaKit/LlamaKit
    • https://github.com/antitypical/Result
    • Xcode 6.3࠷ߴ͗͢Δ

    View full-size slide

  40. ͋Γ͕ͱ͏͍͟͝·ͨ͠

    View full-size slide