Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Himotoki: A type-safe JSON decoding library #関モバ

4,516 views

Published on

関西モバイルアプリ研究会 #2での発表スライドです。

Published in: Engineering
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download Full EPUB Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ACCESS WEBSITE for All Ebooks ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download EPUB Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download doc Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download Full EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ACCESS WEBSITE for All Ebooks ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download doc Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download Full EPUB Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ACCESS WEBSITE for All Ebooks ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download EPUB Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... Download doc Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download Full EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ACCESS WEBSITE for All Ebooks }} ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download doc Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Himotoki: A type-safe JSON decoding library #関モバ

  1. 1. Himotoki A"type'safe"JSON"decoding"library @ikesyo 関西モバイルアプリ研究会!#2,!2015(05(20!Wed #関モバ
  2. 2. @ikesyo いけしょー/池田翔 京都でフリーランスのiOSエンジニア (時々Android)しています 現在はフリュー㈱のモバイル開発の チームにジョイン中。 Swi$もReac)veCocoaも使ってます。
  3. 3. Reac%veCocoaのコミッター(Contributor)やってます
  4. 4. 閑話休題
  5. 5. Swi$でJSON(=>(オブジェクトの マッピングってどうしてますか?
  6. 6. 前回 Objec&ve(C時代の定番*=>*Mantle ObjectMapper
  7. 7. ObjectMapperもいいけど…… • オプショナルな"var"を使うのがいけてない class User: Mappable { var username: String? var age: Int? var array: [AnyObject]? var group: Gruop? // 別の`Mappable`な型 required init?(_ map: Map) { mapping(map) } func mapping(map: Map) { username <- map["username"] age <- map["age"] array <- map["array"] group <- map["group"] } } class Group: Mappable { ... } • inoutパラメータでRealmとの相性が悪い
  8. 8. もっとタイプセーフなJSONマッパーを
  9. 9. ということで作りました
  10. 10. Himotoki(紐解き)
  11. 11. Himotoki • h#ps://github.com/ikesyo/Himotoki • ObjectMapperとは違い、JSONのデコード(デシリアライズ) のみに特化 • Argo>(h#ps://github.com/thoughtbot/Argo)>と同じ方向性 • Argoよりもより簡潔にモデル定義が行えるように • 外部依存なし(今のところは)
  12. 12. Himotoki • プロトコルベースのAPI • 継承の必要なし • class%も%struct%も使える。 • let%なプロパティのモデルも安全に扱える。 • 必要なJSONの要素が%nil%であればその時点でデコードを失敗させられる。 • 型推論による簡潔なモデル定義 • Argoのようなカリー化した%create()%メソッドは不要。
  13. 13. Decodable public protocol Decodable { typealias DecodedType = Self static func decode(e: Extractor) -> DecodedType? }
  14. 14. サンプルコード struct Group: Decodable { let name: String let floor: Int let optional: [String]? // MARK: Decodable static func decode(e: Extractor) -> Group? { // 関数(クロージャ)としてのイニシャライザ // `let create: ((name: String, floor: Int, optional: [String]?)) -> Group` と推論される。 let create = { Group($0) } // リスト全体がオプショナルの引数リストを生成する(22引数まで対応)。 // 途中で非オプショナルな引数に対して `nil` が出てきたら引数リストが `nil` になる。 // その引数リスト全体を `Optional.map()` に渡す。 // この場合 `build(a: String?, b: Int?, c: [String]??) -> (String, Int, [String]?)?` と推論される。 return build( e <| "name", e <| "floor", e <||? "optional" ).map(create) } }
  15. 15. Argoだと struct Group: Decodable { let name: String let floor: Int let optional: [String]? static func create(name: String)(floor: Int)(optional: [String]?) -> Group { return Gruop(name: name, floor: floor, optional: optional) } // MARK: Decodable static func decode(j: JSON) -> Decoded<User> { return Gruop.create <^> j <| "name" <*> j <| "floor" <*> j <||? "optional" } }
  16. 16. サンプルコード func testGroup() { var JSON: [String: AnyObject] = [ "name": "Himotoki", "floor": 12 ] let g: Group? = decode(JSON) XCTAssert(g != nil) XCTAssert(g?.name == "Himotoki") XCTAssert(g?.floor == 12) XCTAssert(g?.optional == nil) JSON["name"] = nil let f: Group? = decode(JSON) XCTAssert(f == nil) }
  17. 17. Operators 演算子は以下の6種類 // 以下 T: Decodable <| // T <|? // T? <|| // [T] <||? // [T]? <|-| // [String: T] <|-|? // [String: T]?
  18. 18. Himotoki'0.2'is'released'today!
  19. 19. Welcome'your'contribu/ons!!'!

×