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. Ṝ͍ΑΔ஍ࠈ • UIScrollView + Auto Layout • ୭΋͕ϋϚΔϙΠϯτ • Mixed

    Approach or Pure Auto Layout Aploach • https://developer.apple.com/library/ios/ technotes/tn2154/_index.html • ઈରstoryboard͚ͩͰղܾ͍ͨ͠
  2. ͳͥ෼཭͢Δͷ͔ • ϙʔλϏϦςΟ • ςετ༰қੑ • storyboardʹஔ͚Δ • view controllerΛdata

    sourceʹґଘͤ͞Δ • prepareForSegueͰϓϦϛςΟϒͳσʔλΛ΍Γͱ Γͨ͘͠ͳ͍
  3. 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 } }
  4. 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] = [] }
  5. 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 } } }
  6. 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 } }
  7. lazy var UIDelegate = WKUIDelegatePlus(self) override public func viewDidLoad() {

    super.viewDidLoad() webView.UIDelegate = UIDelegate }
  8. 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 } }