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

Swift Library

Swift Library

フェンリル ランチタイム勉強会 発表資料

USAMI Kosuke

May 15, 2015
Tweet

More Decks by USAMI Kosuke

Other Decks in Programming

Transcript

  1. APIKit • Swi%&Β͠͞Λଧͪग़ͨ͠ωοτϫʔΫ௨৴ϥΠϒϥϦ let request = GitHub.SearchRepositories(query: "APIKit", sort: .Stars)

    GitHub.sendRequest(request) { response in switch response { case .Success(let box): // SearchRepositories Ϋϥε͕ఆΊΔϨεϙϯεܕ println(box.value) case .Failure(let box): // NSError ܕ println(box.value) } }
  2. Result • ͖͞΄Ͳͷ"APIKit"͕಺෦Ͱ࢖͍ͬͯΔ enum Result<T, E> { case Success(Box<T>) case

    Failure(Box<E>) } result = someFunc() // Result<String, NSError> Λฦؔ͢਺ switch result { case .Success(let box): // box.value: String case .Failure(let box): // box.value: NSError }
  3. ิ଍ɿOp#onal(࠶ߟ • Op$onalɿ੒ޭ/ࣦഊͷҙຯ͚ͮ enum Optional<T> { case Some(T) case None

    } • Result(͸(nil((None)(ଆʹΤϥʔ஋Λ࣋ͨͤͨ΋ͷ • ʢHaskell(Ͱ͍͑͹ɺOp4onal(͸(Maybe(ϞφυɺResult(͸( Either(Ϟφυʣ
  4. Swi$yJSON • ͳ͍ͱ͖ let JSONObject: AnyObject? = NSJSONSerialization.JSONObjectWithData(data, options: nil,

    error: nil) if let statusesArray = JSONObject as? [AnyObject], let status = statusesArray[0] as? [String: AnyObject], let user = status["user"] as? [String: AnyObject], let userName = user["name"] as? String { // userName Λಘͨ } • ͋Δͱ͖ let json = JSON(data: dataFromNetworking) if let userName = json[0]["user"]["name"].string { // userName Λಘͨ }
  5. ObjectMapper • Mantle(͕(Swi,(Ͱ࢖͑ͳ͍ͱ͓୰͖ͷํ΁ struct Temperature: Mappable { var celcius: Double?

    var fahrenheit: Double? init(){} init?(_ map: Map) { mapping(map) } mutating func mapping(map: Map) { celcius <- map["celcius"] fahrenheit <- map["fahrenheit"] } }
  6. SnapKit • AutoLayout)هड़ϥΠϒϥϦ)Masonry)ͷ)Swi1)൛ let padding = UIEdgeInsetsMake(10, 10, 10, 10)

    view1.snp_makeConstraints { make in make.top.equalTo(superview.snp_top).with.offset(padding.top) make.left.equalTo(superview.snp_left).with.offset(padding.left) make.bottom.equalTo(superview.snp_bottom).with.offset(-padding.bottom) make.right.equalTo(superview.snp_right).with.offset(-padding.right) }