From 2726ce619a71c31c58e345ab9da668254574b646 Mon Sep 17 00:00:00 2001 From: Fernando Baptista Date: Thu, 19 Feb 2015 14:25:51 -0200 Subject: [PATCH 1/5] oi --- ContaPessoas/SecondViewController.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ContaPessoas/SecondViewController.h b/ContaPessoas/SecondViewController.h index f907831..85a36be 100644 --- a/ContaPessoas/SecondViewController.h +++ b/ContaPessoas/SecondViewController.h @@ -13,7 +13,8 @@ @property (weak, nonatomic) IBOutlet UILabel *totalBoys; @property (weak, nonatomic) IBOutlet UILabel *totalGirls; @property (weak, nonatomic) IBOutlet UILabel *total; -- (IBAction)click:(id)sender; +- (IBAction)click:(id)sender; // oi? + @end From 2fb382f19cdaa9635c4e08f50d0e7c1ea4d240c6 Mon Sep 17 00:00:00 2001 From: Fernando Baptista Date: Thu, 19 Feb 2015 15:38:55 -0200 Subject: [PATCH 2/5] segunda view funcionando singleton criado --- ContaPessoas/Contador.h | 1 + ContaPessoas/Contador.m | 9 +++++++++ ContaPessoas/FirstViewController.m | 2 +- ContaPessoas/SecondViewController.m | 2 +- 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/ContaPessoas/Contador.h b/ContaPessoas/Contador.h index 18b7c16..3583f57 100644 --- a/ContaPessoas/Contador.h +++ b/ContaPessoas/Contador.h @@ -8,6 +8,7 @@ @interface Contador : NSObject ++ (Contador *) contador; - (void)maisUmCueca; - (void)maisUmaGata; diff --git a/ContaPessoas/Contador.m b/ContaPessoas/Contador.m index fa64ad8..35842bd 100644 --- a/ContaPessoas/Contador.m +++ b/ContaPessoas/Contador.m @@ -39,6 +39,15 @@ -(int)getGirls { return girl; } +static Contador *contador = nil; + ++ (Contador *) contador { + + if (contador == nil) { + contador = [[Contador alloc]init]; + } + return contador; +} @end diff --git a/ContaPessoas/FirstViewController.m b/ContaPessoas/FirstViewController.m index fc70dd5..1c538f5 100644 --- a/ContaPessoas/FirstViewController.m +++ b/ContaPessoas/FirstViewController.m @@ -19,7 +19,7 @@ @implementation FirstViewController { - (void)viewDidLoad { [super viewDidLoad]; - contador = [[Contador alloc] init]; + contador = [Contador contador]; // Do any additional setup after loading the view, typically from a nib. } diff --git a/ContaPessoas/SecondViewController.m b/ContaPessoas/SecondViewController.m index a2a66f5..d57b042 100644 --- a/ContaPessoas/SecondViewController.m +++ b/ContaPessoas/SecondViewController.m @@ -19,7 +19,7 @@ @implementation SecondViewController - (void)viewDidLoad { [super viewDidLoad]; - contador = [[Contador alloc] init]; + contador = [Contador contador]; } From a6192f472bc37be9053b31919a3ee547dfc934d5 Mon Sep 17 00:00:00 2001 From: Fernando Baptista Date: Thu, 19 Feb 2015 15:52:35 -0200 Subject: [PATCH 3/5] GetTotal criado e Teste pass --- ContaPessoas/Contador.h | 2 +- ContaPessoas/Contador.m | 5 +++++ ContaPessoas/SecondViewController.m | 2 +- ContaPessoasTests/ContaPessoasTests.m | 11 +++++++++++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/ContaPessoas/Contador.h b/ContaPessoas/Contador.h index 3583f57..8f27002 100644 --- a/ContaPessoas/Contador.h +++ b/ContaPessoas/Contador.h @@ -14,6 +14,6 @@ -(int)getBoys; -(int)getGirls; - +-(int)getTotal; @end diff --git a/ContaPessoas/Contador.m b/ContaPessoas/Contador.m index 35842bd..9edd885 100644 --- a/ContaPessoas/Contador.m +++ b/ContaPessoas/Contador.m @@ -49,6 +49,11 @@ + (Contador *) contador { return contador; } +-(int)getTotal{ + return boy + girl; + +} + @end diff --git a/ContaPessoas/SecondViewController.m b/ContaPessoas/SecondViewController.m index d57b042..a1a3473 100644 --- a/ContaPessoas/SecondViewController.m +++ b/ContaPessoas/SecondViewController.m @@ -32,7 +32,7 @@ - (void)didReceiveMemoryWarning { - (IBAction)click:(id)sender { _totalBoys.text = [NSString stringWithFormat: @"%d", [contador getBoys]]; _totalGirls.text = [NSString stringWithFormat: @"%d", [contador getGirls]]; - _total.text = [NSString stringWithFormat:@"%d", [contador getGirls] + [contador getBoys] ]; + _total.text = [NSString stringWithFormat:@"%d", [contador getTotal]]; } diff --git a/ContaPessoasTests/ContaPessoasTests.m b/ContaPessoasTests/ContaPessoasTests.m index 579bb3f..f3d6cd0 100644 --- a/ContaPessoasTests/ContaPessoasTests.m +++ b/ContaPessoasTests/ContaPessoasTests.m @@ -21,6 +21,8 @@ - (void)testContaMeninos { Contador *c = [[Contador alloc] init]; [c maisUmCueca]; XCTAssert(([c getBoys] == 1), @"Pass"); + XCTAssert(([c getGirls] == 0), @"Pass"); + XCTAssert(([c getTotal] == 1), @"Pass"); } - (void)testContaMeninas { @@ -28,7 +30,16 @@ - (void)testContaMeninas { [c maisUmaGata]; XCTAssert(([c getGirls] == 1), @"Pass"); XCTAssert(([c getBoys] == 0), @"Pass"); + XCTAssert(([c getTotal] == 1), @"Pass"); } +- (void)testContaTotal { + Contador *c = [[Contador alloc] init]; + [c maisUmaGata]; + [c maisUmCueca]; + XCTAssert(([c getGirls] == 1), @"Pass"); + XCTAssert(([c getBoys] == 1), @"Pass"); + XCTAssert(([c getTotal] == 2), @"Pass"); +} @end From fd1f7fcff8ba99bacf820331b192c5ea7a2e03f8 Mon Sep 17 00:00:00 2001 From: Fernando Baptista Date: Thu, 19 Feb 2015 17:32:05 -0200 Subject: [PATCH 4/5] teste total --- ContaPessoasTests/ContaPessoasTests.m | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ContaPessoasTests/ContaPessoasTests.m b/ContaPessoasTests/ContaPessoasTests.m index f3d6cd0..68903b3 100644 --- a/ContaPessoasTests/ContaPessoasTests.m +++ b/ContaPessoasTests/ContaPessoasTests.m @@ -37,9 +37,11 @@ - (void)testContaTotal { Contador *c = [[Contador alloc] init]; [c maisUmaGata]; [c maisUmCueca]; + [c maisUmCueca]; + [c maisUmCueca]; XCTAssert(([c getGirls] == 1), @"Pass"); - XCTAssert(([c getBoys] == 1), @"Pass"); - XCTAssert(([c getTotal] == 2), @"Pass"); + XCTAssert(([c getBoys] == 3), @"Pass"); + XCTAssert(([c getTotal] == 4), @"Pass"); } @end From 113175cfc003950373564f16d27097077a753c9c Mon Sep 17 00:00:00 2001 From: Fernando Baptista Date: Sat, 21 Feb 2015 19:49:52 -0200 Subject: [PATCH 5/5] Delegate funcionando, como ja mostrado em aula na apple tv --- ContaPessoas/Contador.h | 10 ++++++++++ ContaPessoas/Contador.m | 2 ++ ContaPessoas/SecondViewController.h | 4 ++-- ContaPessoas/SecondViewController.m | 11 +++++++++++ 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/ContaPessoas/Contador.h b/ContaPessoas/Contador.h index 8f27002..c31ee69 100644 --- a/ContaPessoas/Contador.h +++ b/ContaPessoas/Contador.h @@ -5,6 +5,14 @@ // Created by Vinicius Miana on 2/18/15. // Copyright (c) 2015 Vinicius Miana. All rights reserved. // +#import + + +@protocol Mostrador + +-(void) atualiza; + +@end @interface Contador : NSObject @@ -12,6 +20,8 @@ - (void)maisUmCueca; - (void)maisUmaGata; +@property (nonatomic,weak) id delegate; + -(int)getBoys; -(int)getGirls; -(int)getTotal; diff --git a/ContaPessoas/Contador.m b/ContaPessoas/Contador.m index 9edd885..00d9d43 100644 --- a/ContaPessoas/Contador.m +++ b/ContaPessoas/Contador.m @@ -26,9 +26,11 @@ -(id)init { - (void)maisUmCueca { boy = boy + 1; + [_delegate atualiza]; } - (void)maisUmaGata { girl++; + [_delegate atualiza]; } -(int)getBoys { diff --git a/ContaPessoas/SecondViewController.h b/ContaPessoas/SecondViewController.h index 85a36be..7bf9e08 100644 --- a/ContaPessoas/SecondViewController.h +++ b/ContaPessoas/SecondViewController.h @@ -5,10 +5,10 @@ // Created by Vinicius Miana on 2/18/15. // Copyright (c) 2015 Vinicius Miana. All rights reserved. // - +#import "Contador.h" #import -@interface SecondViewController : UIViewController +@interface SecondViewController : UIViewController @property (weak, nonatomic) IBOutlet UILabel *totalBoys; @property (weak, nonatomic) IBOutlet UILabel *totalGirls; diff --git a/ContaPessoas/SecondViewController.m b/ContaPessoas/SecondViewController.m index a1a3473..8f96fab 100644 --- a/ContaPessoas/SecondViewController.m +++ b/ContaPessoas/SecondViewController.m @@ -20,8 +20,13 @@ @implementation SecondViewController - (void)viewDidLoad { [super viewDidLoad]; contador = [Contador contador]; + contador.delegate = self; + [self atualiza]; } +// -(void) viewDidAppear:(BOOL)animated{ +// [self atualiza]; +// } - (void)didReceiveMemoryWarning { @@ -29,6 +34,12 @@ - (void)didReceiveMemoryWarning { // Dispose of any resources that can be recreated. } +-(void)atualiza{ + _totalBoys.text = [NSString stringWithFormat: @"%d", [contador getBoys]]; + _totalGirls.text = [NSString stringWithFormat: @"%d", [contador getGirls]]; + _total.text = [NSString stringWithFormat:@"%d", [contador getTotal]]; +} + - (IBAction)click:(id)sender { _totalBoys.text = [NSString stringWithFormat: @"%d", [contador getBoys]]; _totalGirls.text = [NSString stringWithFormat: @"%d", [contador getGirls]];