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

Useful 3 techniques developing in iOS Apps

07236dd218acc51812c47f92cd6bba19?s=47 yashigani
April 18, 2015

Useful 3 techniques developing in iOS Apps

Cocoa study Kansai #61

07236dd218acc51812c47f92cd6bba19?s=128

yashigani

April 18, 2015
Tweet

Transcript

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

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

  3. એ఻

  4. IUUQDPOOQBTTDPNFWFOU

  5. IUUQDPOOQBTTDPNFWFOU

  6. IUUQDPOOQBTTDPN FWFOU

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

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

  11. None
  12. None
  13. ࠔͬͨ

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

  15. Ṝ͍ΑΔ஍ࠈ • UIScrollView + Auto Layout • ୭΋͕ϋϚΔϙΠϯτ • Mixed

    Approach or Pure Auto Layout Aploach • https://developer.apple.com/library/ios/ technotes/tn2154/_index.html • ઈରstoryboard͚ͩͰղܾ͍ͨ͠
  16. ཱͪ͸͔ͩΔ2ͭͷ՝୊ • ը໘ʹೖΓ͖Βͳ͍ͱ͖͚ͩεΫϩʔϧ͍ͨ͠ • ্Լʹ࠷௿ݶͷϚʔδϯΛઃ͚͍͕ͨɼ༨༟͕͋Δ ৔߹͸ແࢹͯ͠ηϯλϦϯά͍ͨ͠

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

  18. None
  19. ηϯλϦϯάͰ͖ͨ

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

  21. None
  22. ੍໿ʹ QSJPSJUZΛ͚ͭΔ

  23. None
  24. None
  25. ͜͏ͯ͠ ৺ʹฏԺ͕๚Εͨ

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

  27. ͳͥ෼཭͢Δͷ͔ • ϙʔλϏϦςΟ • ςετ༰қੑ • storyboardʹஔ͚Δ • view controllerΛdata

    sourceʹґଘͤ͞Δ • prepareForSegueͰϓϦϛςΟϒͳσʔλΛ΍Γͱ Γͨ͘͠ͳ͍
  28. TVCTDSJQUΛ࣮૷͢Δ

  29. 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 } }
  30. TFDUJPOΛ௥Ճ͢Δ

  31. 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] = [] }
  32. 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 } } }
  33. 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 } }
  34. ઃܭ΋Α͘ͳͬͨ͠ ܕ҆શʹͳͬͨ

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

  36. ͓ͳ΍ΈϙΠϯτ • WKUIDelegateͷ࣮૷ • ΞϥʔτΛॲཧ͢Δ͚ͩ • webView(_:createWebViewWithConfiguration:forNa vigationAction:windowFeatures:) -> WKWebView!

    • ΋͏KVO͸ॻ͖ͨ͘ͳ͍ • storyboard͔Β௥ՃͰ͖ͳ͍
  37. 8FC,JU1MVT IUUQTHJUIVCDPNZBTIJHBOJ8FC,JU1MVT

  38. 8,6*%FMFHBUF1MVT

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

  40. lazy var UIDelegate = WKUIDelegatePlus(self) override public func viewDidLoad() {

    super.viewDidLoad() webView.UIDelegate = UIDelegate }
  41. 8FC7JFX0CTFSWFS

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

  43. 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 } }
  44. ;FO8FC7JFX$POUSPMMFS

  45. • Zen = “ષ” • viewͷ࠷Լ૚ʹWKWebViewΛࠩ͠ࠐΉ • WKWebViewૢ࡞ͷͨΊͷIBAction • goBack/goForward/reload/stopLoading

    • WKUIDelegatePlus, WebViewObserverΛ࣮૷ • storyboard͔Β࢖͑Δͧʂʂʂ
  46. %FNP4JNQMF#SPXTFS

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

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

  49. • AFNetworking͕CarthageରԠڋ൱ͬͯΔ • https://github.com/AFNetworking/ AFNetworking/pull/2552 • LlamaKit͕ResultʹऔΓࠐ·ΕΔͷͭΒ͍ • https://github.com/LlamaKit/LlamaKit •

    https://github.com/antitypical/Result • Xcode 6.3࠷ߴ͗͢Δ
  50. ͋Γ͕ͱ͏͍͟͝·ͨ͠