SlideShare a Scribd company logo
RestKitの紹介 - Webサービスのクライアント実装補助フレームワーク -
永島 次朗 / Jiro Nagashima

iOS Developer @ nana music, inc.




           @hedjirog
RestKit / Examples / RKTwitter
サンプルプロジェクト
• 動作手順
   • リポジトリを複製 (masterブランチ)
   • Examplesディレクトリ下のプロジェクトを開く
   • Build & Run
$ git clone -b master --recursive git://github.com/RestKit/RestKit.git

$ open RestKit/Examples/RKTwitter/RKTwitter.xcodeproj


              ※ 同時に複数のサンプルプロジェクトを開くと、
           (サブプロジェクトとして含まれるRestKitの参照に失敗して)
                 ビルドエラーになる場合があるので注意
サンプルプロジェクト(補足)
           Submoduleを含むリポジトリ複製



               recursiveオプションを付与
             (clone後のsubmodule更新)
$ git clone -b master --recursive git://github.com/RestKit/RestKit.git

$ open RestKit/Examples/RKTwitter/RKTwitter.xcodeproj
Agenda
• RestKitとは
 • 導入手順
 • 注意点
• 基本的な使い方
 • Networking, Object Mapping, Core Data
RestKitとは
RestKitとは



                           Networking
Object Mapping
                 RestKit
                             Core Data
RestKitとは
   Webサービスのクライアント実装を
          強力にサポート!!


                           Networking
Object Mapping
                 RestKit
                             Core Data
RestKitとは
           • RestKit
            • http://restkit.org/
           • Github project page
            • https://github.com/RestKit/
              RestKit
RestKit
導入手順
• CocoaPodsを利用(推奨)
 • https://github.com/RestKit/RestKit#via-
   cocoapods
 • http://cocoapods.org/?q=RestKit
注意点
• iOS 5.0 以上が必須
• ARC
• 最新バージョンに pre の表記 (2013.01.26現在)
 • https://github.com/RestKit/RestKit/tags
• Apache License 2.0
Agenda
  RestKitとは
    導入手順
    注意点

• 基本的な使い方
 • Networking, Object Mapping, Core Data
基本的な使い方
※ サンプルプロジェクト(RKTwitter, RKTwitterCoreData)から抜粋
Networking (1/6)
      • RKObjectManager
         • 通信処理の共通設定

NSURL *baseURL = [NSURL URLWithString:@"http://twitter.com"];

RKObjectManager *objectManager = [RKObjectManager managerWithBaseURL:baseURL];
Networking (2/6)
      • RKObjectManager
         • 共通設定からリクエストを作成

RKObjectManager *objectManager = [RKObjectManager sharedManager];

[objectManager getObjectsAtPath:@"/status/user_timeline/RestKit"
                     parameters:nil
                        success:^(RKObjectRequestOperation *operation,
                                  RKMappingResult *mappingResult) {
                            NSArray* statuses = [mappingResult array];
                            NSLog(@"Loaded statuses: %@", statuses);
                        }
                        failure:^(RKObjectRequestOperation *operation,
                                  NSError *error) {
                            NSLog(@"Hit error: %@", error);
                        }];
Object Mapping (3/6)
      • RKObjectMapping
         • マッピング対象のクラスを指定
         • レスポンスで受け取るJSONデータのキーと、
              クラスのプロパティをマッピング
RKObjectMapping *statusMapping;
statusMapping = [RKObjectMapping mappingForClass:[RKTweet class]];

[statusMapping addAttributeMappingsFromDictionary:@{
 @"id" : @"statusID",
 @"created_at" : @"createdAt",
 @"text" : @"text",
 @"url" : @"urlString",
 @"in_reply_to_screen_name" : @"inReplyToScreenName",
 @"favorited" : @"isFavorited",
 }];

                   ※ CoreData利用時のマッピングは後述(RKEntityMapping)
Object Mapping (4/6)
      • RKObjectMapping
         • マッピングを適用するレスポンスの状態を
              RKResponseDescriptorで設定
         • RKObjectManagerへ設定内容を引き渡し
RKResponseDescriptor *responseDescriptor;
responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:statusMapping
                                           pathPattern:@"/status/user_timeline/:username"
                                           keyPath:nil
                                           statusCodes:[NSIndexSet indexSetWithIndex:200]];

RKObjectManager *objectManager = [RKObjectManager sharedManager];
[objectManager addResponseDescriptor:responseDescriptor];
Core Data (5/6)
      • RKManagedObjectStore
         • Core Dataスタックの管理

NSManagedObjectModel *managedObjectModel;
managedObjectModel = [NSManagedObjectModel mergedModelFromBundles:nil];

RKManagedObjectStore *managedObjectStore;
managedObjectStore = [[RKManagedObjectStore alloc]
                       initWithManagedObjectModel:managedObjectModel];

RKObjectManager *objectManager = [RKObjectManager sharedManager];
objectManager.managedObjectStore = managedObjectStore;
Core Data (6/6)
      • RKEntityMapping
         • マッピング対象のエンティティと、
              RKManagedObjectSotreインスタンスを指定
         • 値が一意となる属性を指定(オブジェクト更新時
              に利用される)
RKEntityMapping *tweetMapping;
tweetMapping = [RKEntityMapping mappingForEntityForName:@"Tweet"
                                inManagedObjectStore:managedObjectStore];

tweetMapping.identificationAttributes = @[ @"statusID" ];
[tweetMapping addAttributeMappingsFromDictionary:@{
 @"id": @"statusID",
 @"created_at": @"createdAt",
 @"text": @"text",
 @"url": @"urlString",
 @"in_reply_to_screen_name": @"inReplyToScreenName",
 @"favorited": @"isFavorited",
 }];
Agenda
RestKitとは
 導入手順
 注意点

基本的な使い方
 Networking, Object Mapping, Core Data
関連
• API Reference
 • https://github.com/RestKit/RestKit#api-
   quickstart
 • http://restkit.org/api/latest/
• Wiki
 • https://github.com/RestKit/RestKit/wiki

More Related Content

PDF
CoreData 非同期データ処理
PDF
第8回KPF発表資料
PPT
Mongodb
PPTX
Domino Query Language (DQL)
PDF
Embulk 20150411
PDF
PHP 2大 web フレームワークの徹底比較!
PDF
今からでも大丈夫!Firebase入門
PPTX
FIWAREシステム内の短期履歴の管理
CoreData 非同期データ処理
第8回KPF発表資料
Mongodb
Domino Query Language (DQL)
Embulk 20150411
PHP 2大 web フレームワークの徹底比較!
今からでも大丈夫!Firebase入門
FIWAREシステム内の短期履歴の管理

What's hot (19)

PPTX
コア・コンテキスト管理 - FIWARE WednesdayWebinars
PPTX
コンテキストデータの永続化のための戦略
PPTX
「書ける」から「できる」になれる! ~Javaメモリ節約ノウハウ話~
PDF
明日から使える Java SE 7
PDF
Babelfish Compatibility
PDF
DBスキーマもバージョン管理したい!
PDF
OpenStack API
PDF
CRAN Task Views でパッケージ管理
PDF
Slub alloc and free
PDF
Pro aspnetmvc3framework chap19
PDF
Migr8.rb チュートリアル
PDF
Webサーバ勉強会03
PDF
これからのコンピューティングの変化とJava-JJUG CCC 2015 Fall
PPT
実行時のために最適なデータ構造を作成しよう
PPTX
JavaでインメモリSQLエンジンを作ってみた
PPTX
IoT Agents をデバッグする方法 - FIWARE WednesdayWebinars
PDF
プロジェクト2B 最終発表
PDF
EDB Postgres Vision 2019
PDF
Slub data structure
コア・コンテキスト管理 - FIWARE WednesdayWebinars
コンテキストデータの永続化のための戦略
「書ける」から「できる」になれる! ~Javaメモリ節約ノウハウ話~
明日から使える Java SE 7
Babelfish Compatibility
DBスキーマもバージョン管理したい!
OpenStack API
CRAN Task Views でパッケージ管理
Slub alloc and free
Pro aspnetmvc3framework chap19
Migr8.rb チュートリアル
Webサーバ勉強会03
これからのコンピューティングの変化とJava-JJUG CCC 2015 Fall
実行時のために最適なデータ構造を作成しよう
JavaでインメモリSQLエンジンを作ってみた
IoT Agents をデバッグする方法 - FIWARE WednesdayWebinars
プロジェクト2B 最終発表
EDB Postgres Vision 2019
Slub data structure
Ad

Similar to RestKitの紹介 - Webサービスのクライアント実装補助フレームワーク - (20)

KEY
Web Operations and Perl kansai.pm#14
PDF
Apache Torqueについて
PDF
scala+liftで遊ぼう
PDF
Spring Data in a Nutshell
PDF
Sc2009autumn s2robot
PPTX
Develop Web Application with Node.js + Express
PDF
基礎から見直す ASP.NET MVC の単体テスト自動化方法 ~ Windows Azure 関連もあるかも~
PDF
コンポーネント指向による、Reactのベストプラクティスとバッドプラクティス
PDF
Sansan様 登壇資料
PDF
PostgreSQL 12の話
PDF
Seasarプロジェクト徹底攻略
PPTX
Hadoop基盤上のETL構築実践例 ~多様なデータをどう扱う?~
PDF
Ssaw08 1028
PPTX
Selenium webdriver使ってみようず
PDF
Next2Dで始めるゲーム開発 - Game Development Starting with Next2D
PPTX
「Windows 8 ストア アプリ開発 tips」 hokuriku.net vol.11 (2013年1月26日)
PPTX
Dot netcore multiplatform 2
PPT
Springでdao 20070413
PDF
Grails 2.0.0.M1の話
PDF
Let's build a simple app with .net 6 asp.net core web api, react, and elasti...
Web Operations and Perl kansai.pm#14
Apache Torqueについて
scala+liftで遊ぼう
Spring Data in a Nutshell
Sc2009autumn s2robot
Develop Web Application with Node.js + Express
基礎から見直す ASP.NET MVC の単体テスト自動化方法 ~ Windows Azure 関連もあるかも~
コンポーネント指向による、Reactのベストプラクティスとバッドプラクティス
Sansan様 登壇資料
PostgreSQL 12の話
Seasarプロジェクト徹底攻略
Hadoop基盤上のETL構築実践例 ~多様なデータをどう扱う?~
Ssaw08 1028
Selenium webdriver使ってみようず
Next2Dで始めるゲーム開発 - Game Development Starting with Next2D
「Windows 8 ストア アプリ開発 tips」 hokuriku.net vol.11 (2013年1月26日)
Dot netcore multiplatform 2
Springでdao 20070413
Grails 2.0.0.M1の話
Let's build a simple app with .net 6 asp.net core web api, react, and elasti...
Ad

RestKitの紹介 - Webサービスのクライアント実装補助フレームワーク -

  • 2. 永島 次朗 / Jiro Nagashima iOS Developer @ nana music, inc. @hedjirog
  • 3. RestKit / Examples / RKTwitter
  • 4. サンプルプロジェクト • 動作手順 • リポジトリを複製 (masterブランチ) • Examplesディレクトリ下のプロジェクトを開く • Build & Run $ git clone -b master --recursive git://github.com/RestKit/RestKit.git $ open RestKit/Examples/RKTwitter/RKTwitter.xcodeproj ※ 同時に複数のサンプルプロジェクトを開くと、 (サブプロジェクトとして含まれるRestKitの参照に失敗して) ビルドエラーになる場合があるので注意
  • 5. サンプルプロジェクト(補足) Submoduleを含むリポジトリ複製 recursiveオプションを付与 (clone後のsubmodule更新) $ git clone -b master --recursive git://github.com/RestKit/RestKit.git $ open RestKit/Examples/RKTwitter/RKTwitter.xcodeproj
  • 6. Agenda • RestKitとは • 導入手順 • 注意点 • 基本的な使い方 • Networking, Object Mapping, Core Data
  • 8. RestKitとは Networking Object Mapping RestKit Core Data
  • 9. RestKitとは Webサービスのクライアント実装を 強力にサポート!! Networking Object Mapping RestKit Core Data
  • 10. RestKitとは • RestKit • http://restkit.org/ • Github project page • https://github.com/RestKit/ RestKit RestKit
  • 11. 導入手順 • CocoaPodsを利用(推奨) • https://github.com/RestKit/RestKit#via- cocoapods • http://cocoapods.org/?q=RestKit
  • 12. 注意点 • iOS 5.0 以上が必須 • ARC • 最新バージョンに pre の表記 (2013.01.26現在) • https://github.com/RestKit/RestKit/tags • Apache License 2.0
  • 13. Agenda RestKitとは 導入手順 注意点 • 基本的な使い方 • Networking, Object Mapping, Core Data
  • 15. Networking (1/6) • RKObjectManager • 通信処理の共通設定 NSURL *baseURL = [NSURL URLWithString:@"http://twitter.com"]; RKObjectManager *objectManager = [RKObjectManager managerWithBaseURL:baseURL];
  • 16. Networking (2/6) • RKObjectManager • 共通設定からリクエストを作成 RKObjectManager *objectManager = [RKObjectManager sharedManager]; [objectManager getObjectsAtPath:@"/status/user_timeline/RestKit" parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) { NSArray* statuses = [mappingResult array]; NSLog(@"Loaded statuses: %@", statuses); } failure:^(RKObjectRequestOperation *operation, NSError *error) { NSLog(@"Hit error: %@", error); }];
  • 17. Object Mapping (3/6) • RKObjectMapping • マッピング対象のクラスを指定 • レスポンスで受け取るJSONデータのキーと、 クラスのプロパティをマッピング RKObjectMapping *statusMapping; statusMapping = [RKObjectMapping mappingForClass:[RKTweet class]]; [statusMapping addAttributeMappingsFromDictionary:@{ @"id" : @"statusID", @"created_at" : @"createdAt", @"text" : @"text", @"url" : @"urlString", @"in_reply_to_screen_name" : @"inReplyToScreenName", @"favorited" : @"isFavorited", }]; ※ CoreData利用時のマッピングは後述(RKEntityMapping)
  • 18. Object Mapping (4/6) • RKObjectMapping • マッピングを適用するレスポンスの状態を RKResponseDescriptorで設定 • RKObjectManagerへ設定内容を引き渡し RKResponseDescriptor *responseDescriptor; responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:statusMapping pathPattern:@"/status/user_timeline/:username" keyPath:nil statusCodes:[NSIndexSet indexSetWithIndex:200]]; RKObjectManager *objectManager = [RKObjectManager sharedManager]; [objectManager addResponseDescriptor:responseDescriptor];
  • 19. Core Data (5/6) • RKManagedObjectStore • Core Dataスタックの管理 NSManagedObjectModel *managedObjectModel; managedObjectModel = [NSManagedObjectModel mergedModelFromBundles:nil]; RKManagedObjectStore *managedObjectStore; managedObjectStore = [[RKManagedObjectStore alloc] initWithManagedObjectModel:managedObjectModel]; RKObjectManager *objectManager = [RKObjectManager sharedManager]; objectManager.managedObjectStore = managedObjectStore;
  • 20. Core Data (6/6) • RKEntityMapping • マッピング対象のエンティティと、 RKManagedObjectSotreインスタンスを指定 • 値が一意となる属性を指定(オブジェクト更新時 に利用される) RKEntityMapping *tweetMapping; tweetMapping = [RKEntityMapping mappingForEntityForName:@"Tweet" inManagedObjectStore:managedObjectStore]; tweetMapping.identificationAttributes = @[ @"statusID" ]; [tweetMapping addAttributeMappingsFromDictionary:@{ @"id": @"statusID", @"created_at": @"createdAt", @"text": @"text", @"url": @"urlString", @"in_reply_to_screen_name": @"inReplyToScreenName", @"favorited": @"isFavorited", }];
  • 22. 関連 • API Reference • https://github.com/RestKit/RestKit#api- quickstart • http://restkit.org/api/latest/ • Wiki • https://github.com/RestKit/RestKit/wiki