Conceitos e prática no desenvolvimento iOS - Mobile Conf 2014
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Conceitos e prática no desenvolvimento iOS - Mobile Conf 2014

on

  • 681 views

Slides da minha palestra na Mobile Conf 2014.

Slides da minha palestra na Mobile Conf 2014.

Statistics

Views

Total Views
681
Views on SlideShare
656
Embed Views
25

Actions

Likes
1
Downloads
13
Comments
0

3 Embeds 25

http://www.slideee.com 19
https://twitter.com 4
http://www.linkedin.com 2

Accessibility

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Conceitos e prática no desenvolvimento iOS - Mobile Conf 2014 Presentation Transcript

  • 1. Conceitos e prática no desenvolvimento iOS
  • 2. Desenvolvedor e instrutor (iOS, Android, Java e Ruby) Quem sou eu? @fabiopimentel github.com/fabiopimentel
  • 3. Vamos programar? Objective-C (OFICIAL) Ruby - RubyMotion C# - Xamarin
  • 4. iOS MVC Controller Model View
  • 5. iOS MVC Controller Model View -------------- --------------
  • 6. iOS MVC Controller Model View -------------- --------------
  • 7. iOS MVC Controller Model View -------------- -------------- Outlet
  • 8. iOS MVC Controller Model View -------------- -------------- Outlet Action
  • 9. Opções para View
  • 10. StoryBoard
  • 11. Xib
  • 12. Opções para View 1) StoryBoard 2) Xib 2) Programaticamente
  • 13. Ciclo de Vida
  • 14. ViewController A tela já existe?
  • 15. ViewController A tela já existe? viewWillAppear Não viewDidAppear Tela visível viewDidLoad F l u x o
  • 16. ViewController A tela já existe? Sim viewWillAppear Não viewDidAppear Tela visível viewDidLoad
  • 17. viewDidLoad viewWillAppear Tela visível viewWillDisappear Ciclo de vida - ViewController viewDidAppear viewDidDisappear Tela não visível
  • 18. Ciclo de Vida - App Aplicação não está rodando Usuário clica no ícone da app application:didFinishLauchingWithOptions: applicationDidBecomeActive: Aplicação rodando Usuário clica em Home, ou recebe chamada telefônica/ SMS applicationWillResignActive: applicationDidEnterBackground: Aplicação em backgroung Usuário clica no ícone da app applicationWillEnterForeground:
  • 19. Ciclo de Vida - App Aplicação não está rodando Usuário clica no ícone da app application:didFinishLauchingWithOptions: applicationDidBecomeActive: Aplicação rodando Usuário clica em Home, ou recebe chamada telefônica/ SMS applicationWillResignActive: applicationDidEnterBackground: Aplicação em backgroung Usuário clica no ícone da app applicationWillEnterForeground:
  • 20. Live Coding First Round
  • 21. Principal componente do iOS
  • 22. TableView https://developer.apple.com/library/ios/documentation/userexperience/conceptual/tableview_iphone/ AboutTableViewsiPhone/AboutTableViewsiPhone.html
  • 23. UITableViewStyleGrouped
  • 24. UITableViewStylePlain
  • 25. Section 0 Section 1 Section 2 Section 3 Section 4
  • 26. Row 0 Row 1
  • 27. Row 0 Row 1 Row 2
  • 28. NSIndexPath "The UIKit framework adds programming interfaces to the NSIndexPath class of the Foundation framework to facilitate the identification of rows and sections in UITableView objects and the identification of items and sections in UICollectionView objects." https://developer.apple.com/library/ios/documentation/uikit/reference/NSIndexPath_UIKitAdditions/Reference/ Reference.html
  • 29. NSIndexPath Row Section
  • 30. Row 2 Section 2 NSIndexPath
  • 31. UITableViewController https://developer.apple.com/library/ios/documentation/uikit/reference/UITableViewController_Class/ Reference/Reference.html
  • 32. Métodos para configuração – numberOfSectionsInTableView: - tableView:numberOfRowsInSection: – tableView:cellForRowAtIndexPath:
  • 33. Trabalhando em Background
  • 34. Opção 1 performSelectorInBackground:withObject: performSelectonOnMainThread:withObject: waitUntilDone
  • 35. Exemplo -(IBAction)carregaLista:(UIButton *) botao ! {
 ! [self performSelectorInBackground: @selector(buscaMotos) withObject: nil];! }
 

  • 36. Exemplo -(IBAction)carregaLista:(UIButton *) botao ! {
 ! [self performSelectorInBackground: @selector(buscaMotos) withObject: nil];! }
 
 -(void)buscaMotos! { //faz a comunicação com algum webservice [self performSelectorOnMainThread @selector(atualizaTabela:) withObject: arrayDeDados waitUntilDone: NO];! }
  • 37. Exemplo -(IBAction)carregaLista:(UIButton *) botao ! {
 ! [self performSelectorInBackground: @selector(buscaMotos) withObject: nil];! }
 
 -(void)buscaMotos! { //faz a comunicação com algum webservice [self performSelectorOnMainThread @selector(atualizaTabela:) withObject: nil waitUntilDone: NO];! }! -(void)atualizaTabela:(NSObject*) object! { ! ! [self.tableView reloadData];! }
  • 38. Opção 2 NSOperationQueue NSInvocationOperation ou NSBlockOperation
  • 39. Exemplo -(IBAction)carregaLista:(UIButton *) botao { NSOperationQueue * queue = [[NSOperationQueue alloc]init]; NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget: self selector: @selector(downloadMotos) object:nil]; ! [queue addOperation:operation]; } ! -(void)downloadPosts{ //faz a comunicação com algum webservice! [self performSelectorOnMainThread @selector(atualizaTabela:) withObject: arrayDeDados waitUntilDone: NO]; ! } ! -(void)atualizaTabela:(NSObject*) object{ //... [self.tableView reloadData]; }
  • 40. Opção 3 Grand Central Dispatch (GCD)
  • 41. Exemplo NSArray *images = @[@"http://example.com/image1.png", @"http://example.com/image2.png", @"http://example.com/image3.png", @"http://example.com/image4.png"]; ! dispatch_queue_t imageQueue = dispatch_queue_create("Image Queue",NULL); ! for (NSString *urlString in images) { dispatch_async(imageQueue, ^{ NSURL *url = [NSURL URLWithString:urlString]; NSData *imageData = [NSData dataWithContentsOfURL:url]; UIImage *image = [UIImage imageWithData:imageData]; ! NSUInteger imageIndex = [images indexOfObject:urlString]; UIImageView *imageVIew = (UIImageView *)[self.view viewWithTag:imageIndex]; if (!imageView) return; dispatch_async(dispatch_get_main_queue(), ^{ // Update the UI [imageVIew setImage:image]; }); }); }
  • 42. Conexão com webservices
  • 43. Opção 1 NSURLRequest e NSURLMutableRequest NSURLConnection
  • 44. Exemplo(GET) NSString * url = @“http://projetows.heroku.com/motos.json” ! NSURLRequest *request = [NSURLRequest requestWithURL: [NSURL URLWithString: url] ]; ! [NSURLConnection sendAsynchronousRequest:request queue: [NSOperationQueue mainQueue] completionHandler: ^(NSURLResponse *response, NSData *data, NSError *connectionError) { // manipula resposta } ];
  • 45. Opção 2 ! NSURLSession (iOS 7)
  • 46. Exemplo (GET) NSString * url = @“http://projetows.heroku.com/motos.json” ! NSURLSession *session = [NSURLSession sharedSession]; [session dataTaskWithURL: [NSURL URLWithString: url]completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { //manipula resposta! } ] resume];
  • 47. Interpretando resultados
  • 48. JSON projetows.heroku.com/motos.json [ { "marca":"Yamaha", "modelo":"R1", }, { "marca":"Honda", “modelo":"CBR 600 RR", } ]
  • 49. Opção da Apple NSJSONSerialization https://developer.apple.com/library/ios/documentation/ foundation/reference/ nsjsonserialization_class
  • 50. Exemplo NSString *url = @“http://projetows.heroku.com/motos.json";! ! NSData *jsonData = [NSData dataWithContentsOfURL: [NSURL URLWithString:url]];! ! NSError *error;! NSArray *resultados = [NSJSONSerialization JSONObjectWithData: jsonData options:NSJSONReadingMutableContainers error:&error];! if(!error) {! ! for(NSDictionary * moto in resultados){! ! ! NSString *marca = [moto objectForKey:@"marca"];! ! ! NSString *modelo = [moto objectForKey:@"modelo"];! ! ! NSLog(@"Marca: %@, modelo: %@", marca, modelo);! ! }! }!
  • 51. Opções de terceiros https://github.com/stig/json-framework/ JSON Framework https://github.com/TouchCode/TouchJSON TouchJSON
  • 52. Agora basta juntar tudo?
  • 53. https://github.com/AFNetworking/ AFNetworking
  • 54. Exemplo ! NSString * url = @“projetows.heroku.com/motos.json”! AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];! ! [manager GET:url parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {! ! ! ! self.json = responseObject;! ! for(NSDictionary * moto in self.json){! ! ! NSString *marca = [moto objectForKey:@"marca"];! ! ! NSString *modelo = [moto objectForKey:@"modelo"];! ! ! NSLog(@"Marca: %@, modelo: %@", marca, modelo);! ! }! } failure:^(AFHTTPRequestOperation *operation, NSError *error) {! NSLog(@"Error: %@", error);! ! }];! }!
  • 55. Como usá-lo no projeto?
  • 56. CocoaPods http://cocoapods.org/ Gerenciador de dependências
  • 57. Instalação gem install cocoapods
  • 58. Instalação gem install cocoa-pods Podfile
  • 59. Podfile platform :ios , '7.1'! ! pod 'AFNetworking', '> 2.0'
  • 60. Instalação gem install cocoa-pods Podfile pod install
  • 61. Saída(Terminal) Fabios-MacBook-Pro:MobileConf fabiopimentel$ pod install Analyzing dependencies Downloading dependencies Installing AFNetworking (2.2.4) Generating Pods project Integrating client project ! [!] From now on use `MobileConf.xcworkspace`.
  • 62. Estrutura do projeto
  • 63. Live Coding econd Round
  • 64. Mais bibliotecas …
  • 65. Testes Kiwi https://github.com/kiwi-bdd/Kiwi BDD style describe(@"Team", ^{ context(@"when newly created", ^{ it(@"should have a name", ^{ id team = [Team team]; [[team.name should] equal:@"Black Hawks"]; }); ! it(@"should have 11 players", ^{ id team = [Team team]; [[[team should] have:11] players]; }); }); });
  • 66. Testes KIF https://github.com/kif-framework/KIF Acceptance Tests Kiwi https://github.com/kiwi-bdd/Kiwi BDD style
  • 67. KIF Acceptance Tests @implementation LoginTests ! - (void)beforeEach { [tester navigateToLoginPage]; } ! - (void)afterEach { [tester returnToLoggedOutHomeScreen]; } ! - (void)testSuccessfulLogin { [tester enterText:@"user@example.com" intoViewWithAccessibilityLabel:@"Login User Name"]; [tester enterText:@"thisismypassword" intoViewWithAccessibilityLabel:@"Login Password"]; [tester tapViewWithAccessibilityLabel:@"Log In"]; ! // Verify that the login succeeded [tester waitForTappableViewWithAccessibilityLabel:@"Welcome"]; } ! @end
  • 68. Ainda mais…
  • 69. https://www.testflightapp.com/
  • 70. AppCode (IDE)
  • 71. E agora?
  • 72. http://www.caelum.com.br/curso-ios-iphone-ipad/
  • 73. https://developer.apple.com/programs/ios/
  • 74. Obrigado! @fabiopimentel