Successfully reported this slideshow.
Your SlideShare is downloading. ×

Xcode 6の新機能

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Loading in …3
×

Check these out next

1 of 31 Ad

More Related Content

Slideshows for you (20)

Similar to Xcode 6の新機能 (20)

Advertisement

Recently uploaded (20)

Xcode 6の新機能

  1. 1. Xcode 6の新機能 2014.10.18 iOS 8/Swift エンジニア勉強会@ヤフー 佐藤 新悟 @gonsee
  2. 2. 自己紹介 • 佐藤 新悟 • iOSアプリ開発4年半ほど • 現在は電子母子手帳 kazoc
  3. 3. アジェンダ • Xcode 6の新機能概要 • Viewのデバッグ機能 • Interface Builderでライブレンダリング • 非同期テスト
  4. 4. Xcode 6の新機能概要
  5. 5. • Swift対応 - 全部swfitでも、Obj-Cと同居でもOK Playground - テスト、学習 • XCTest・ 非同期テスト、パフォーマンステスト • Interface Builder・ カスタムビュークラスのライブレンダリング、 カスタムフォント
  6. 6. • Debugger・ viewの階層構造を3D表示、 queueに積まれたblockの表示 • SpriteKit、SceneKit向け改善 • Extension、Frameworkのサポート
  7. 7. 詳しくは… • What’s New in Xcode https://developer.apple.com/library/ios/documentation/DeveloperTools/ Conceptual/WhatsNewXcode/Articles/Introduction.html
  8. 8. 本日取り上げるもの 1. Viewのデバッグ機能 2. Interface Builderでライブレンダリング 3. 非同期テスト
  9. 9. 1. Viewのデバッグ機能
  10. 10. Viewの階層構造を3D表示 Debugエリア上部のツールバー Debug View Hierarchy
  11. 11. 階層構造やプロパティの表示 Debug navigator Object inspector Size inspector
  12. 12. Viewのデバッグ機能 Demo
  13. 13. 2. Interface Builderで ライブレンダリング
  14. 14. • 自前viewクラスをIB上で描画できる • 自前viewクラスのプロパティをIBから 設定できる ※ Framework化は必須ではない
  15. 15. Viewクラスの実装 // MyCustomView.h ! IB_DESIGNABLE @interface MyCustomView : UIView ! @end // MyCustomView.m ! - (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetLineWidth(context, 2.0f); [[UIColor blueColor] setStroke]; CGRect strokeRect = CGRectInset(self.bounds, self.lineWidth/2.0f, self.lineWidth/2.0f); CGContextStrokeEllipseInRect(context, strokeRect); }
  16. 16. IB上に配置 Viewを配置してCustom Classに独自viewクラスを指定 IB上に独自viewが描画され コード修正も自動で反映される
  17. 17. IB上で設定可能なプロパティの追加 // MyCustomView.h ! IB_DESIGNABLE @interface MyCustomView : UIView ! @property (nonatomic, assign) IBInspectable CGFloat lineWidth; ! @property (nonatomic, strong) IBInspectable UIColor *borderColor; ! @end // MyCustomView.m ! - (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetLineWidth(context, self.lineWidth); [self.borderColor setStroke]; CGRect strokeRect = CGRectInset(self.bounds, self.lineWidth/2.0f, self.lineWidth/2.0f); CGContextStrokeEllipseInRect(context, strokeRect); }
  18. 18. IB上で設定可能なプロパティの追加 指定したプロパティをIBから設定可能になる
  19. 19. IB上で設定可能なプロパティの追加 他にも様々なタイプで利用可能 • NSInteger • CGFloat • double • BOOL • NSString • CGPoint • CGSize • CGRect • UIColor • UIImage
  20. 20. Swiftの場合 @IBDesignable class SwiftCustomView: UIView { ! @IBInspectable var lineWidth: CGFloat = 1.0 @IBInspectable var borderColor: UIColor = UIColor.blueColor() override func drawRect(rect: CGRect) { let context = UIGraphicsGetCurrentContext() CGContextSetLineWidth(context, self.lineWidth) borderColor.setStroke() let strokeRect = CGRectInset(bounds, lineWidth/2.0, lineWidth/2.0); CGContextStrokeEllipseInRect(context, strokeRect); } ! }
  21. 21. IBでライブレンダリング Demo
  22. 22. 3. 非同期テスト
  23. 23. 非同期なAPIが当たり前 • Block呼び出し • デリゲートコールバック • ネットワークリクエスト • バックグラウンド処理
  24. 24. • Xcode 5からユニットテストのフレー ムワークとしてXCTestが導入された • Xcode 6から標準で非同期テストが可 能になった • 旧バージョン(iOS 6以降)をサポート
  25. 25. 非同期メソッドのテスト テスト対象のメソッド @interface ViewController : UIViewController ! // a + b の結果を非同期で返す - (void)addA:(NSInteger)a toB:(NSInteger)b withCompletion:(void (^)(NSInteger result))completion; ! @end
  26. 26. 非同期メソッドのテスト // AsyncTestDemoTests.m - (void)testAsyncAddition { // descriptionはログに出力される XCTestExpectation *expectation = [self expectationWithDescription:@"Addition"]; // テスト対象の非同期メソッドを呼ぶ ViewController *vc = [[ViewController alloc] init]; [vc addA:1 toB:1 withCompletion:^(NSInteger result) { XCTAssertEqual(result, 2); // 計算結果の検証 [expectation fulfill]; }]; [self waitForExpectationsWithTimeout:1.0 handler:^(NSError *error) { NSLog(@"Error: %@", error); }]; } テストコード(XCTestCaseのサブクラス)
  27. 27. KVOのテスト // ViewController.h ! @property (assign, readonly) ViewControllerState state; - (void)changeState; // ViewControllerState1 -> ViewControllerState2 テストコード - (void)testStateChangesFromState1ToState2 { ViewController *vc = [[ViewController alloc] init]; XCTAssertEqual(vc.state, ViewControllerState1); [self keyValueObservingExpectationForObject:vc keyPath:@"state" expectedValue:@(ViewControllerState2)]; [vc changeState]; [self waitForExpectationsWithTimeout:1.0 handler:nil]; }
  28. 28. Notificationのテスト テストコード - (void)testNotification { [self expectationForNotification:ViewControllerSomeNotification object:nil handler:^BOOL(NSNotification *notification) { NSLog(@"%@", notification); // テストの成否をYES,NOで返す return YES; }]; ViewController *vc = [[ViewController alloc] init]; [vc notify]; // ViewControllerSomeNotificationをpostするメソッド [self waitForExpectationsWithTimeout:1.0 handler:nil]; }
  29. 29. 非同期テスト Demo
  30. 30. 参考資料 • WWDC 2014 Session Videos • What’s New in Xcode 6 • Debugging in Xcode 6 • Testing in Xcode 6 • New Features in Xcode 6 https://developer.apple.com/library/ios/documentation/DeveloperTools/Conceptual/ WhatsNewXcode/Articles/xcode_6_0.html • Creating a Custom View that Renders in Interface Builder https://developer.apple.com/library/ios/recipes/xcode_help-IB_objects_media/chapters/ CreatingaLiveViewofaCustomObject.html

×