Your SlideShare is downloading. ×
Xcode 6の新機能
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Saving this for later?

Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Text the download link to your phone

Standard text messaging rates apply

We'd love to hear what you think

By taking this short survey, you'll help us make SlideShare better. It shouldn't take more than a few minutes.

Start Survey

Xcode 6の新機能

18,555
views

Published on

Xcode 6の新機能 …

Xcode 6の新機能
2014.10.18
iOS 8/Swift エンジニア勉強会@ヤフー

Published in: Technology

0 Comments
31 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
18,555
On Slideshare
0
From Embeds
0
Number of Embeds
12
Actions
Shares
0
Downloads
70
Comments
0
Likes
31
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Xcode 6の新機能 2014.10.18 iOS 8/Swift エンジニア勉強会@ヤフー 佐藤 新悟 @gonsee
  • 2. 自己紹介 • 佐藤 新悟 • iOSアプリ開発4年半ほど • 現在は電子母子手帳 kazoc
  • 3. アジェンダ • Xcode 6の新機能概要 • Viewのデバッグ機能 • Interface Builderでライブレンダリング • 非同期テスト
  • 4. Xcode 6の新機能概要
  • 5. • Swift対応 - 全部swfitでも、Obj-Cと同居でもOK Playground - テスト、学習 • XCTest・ 非同期テスト、パフォーマンステスト • Interface Builder・ カスタムビュークラスのライブレンダリング、 カスタムフォント
  • 6. • Debugger・ viewの階層構造を3D表示、 queueに積まれたblockの表示 • SpriteKit、SceneKit向け改善 • Extension、Frameworkのサポート
  • 7. 詳しくは… • What’s New in Xcode https://developer.apple.com/library/ios/documentation/DeveloperTools/ Conceptual/WhatsNewXcode/Articles/Introduction.html
  • 8. 本日取り上げるもの 1. Viewのデバッグ機能 2. Interface Builderでライブレンダリング 3. 非同期テスト
  • 9. 1. Viewのデバッグ機能
  • 10. Viewの階層構造を3D表示 Debugエリア上部のツールバー Debug View Hierarchy
  • 11. 階層構造やプロパティの表示 Debug navigator Object inspector Size inspector
  • 12. Viewのデバッグ機能 Demo
  • 13. 2. Interface Builderで ライブレンダリング
  • 14. • 自前viewクラスをIB上で描画できる • 自前viewクラスのプロパティをIBから 設定できる ※ Framework化は必須ではない
  • 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. IB上に配置 Viewを配置してCustom Classに独自viewクラスを指定 IB上に独自viewが描画され コード修正も自動で反映される
  • 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. IB上で設定可能なプロパティの追加 指定したプロパティをIBから設定可能になる
  • 19. IB上で設定可能なプロパティの追加 他にも様々なタイプで利用可能 • NSInteger • CGFloat • double • BOOL • NSString • CGPoint • CGSize • CGRect • UIColor • UIImage
  • 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. IBでライブレンダリング Demo
  • 22. 3. 非同期テスト
  • 23. 非同期なAPIが当たり前 • Block呼び出し • デリゲートコールバック • ネットワークリクエスト • バックグラウンド処理
  • 24. • Xcode 5からユニットテストのフレー ムワークとしてXCTestが導入された • Xcode 6から標準で非同期テストが可 能になった • 旧バージョン(iOS 6以降)をサポート
  • 25. 非同期メソッドのテスト テスト対象のメソッド @interface ViewController : UIViewController ! // a + b の結果を非同期で返す - (void)addA:(NSInteger)a toB:(NSInteger)b withCompletion:(void (^)(NSInteger result))completion; ! @end
  • 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. 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. 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. 非同期テスト Demo
  • 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