From 7062123b0fe7be9721d717c09a764918a9f1fd34 Mon Sep 17 00:00:00 2001 From: Himalaiah Date: Thu, 19 Feb 2015 14:19:40 -0200 Subject: [PATCH 1/5] Adicao de comentario --- ContaPessoas/Contador.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ContaPessoas/Contador.m b/ContaPessoas/Contador.m index fa64ad8..0bea3f2 100644 --- a/ContaPessoas/Contador.m +++ b/ContaPessoas/Contador.m @@ -1,7 +1,7 @@ // // Contador.m // ContaPessoas -// +// C // Created by Vinicius Miana on 2/18/15. // Copyright (c) 2015 Vinicius Miana. All rights reserved. // From 4e8da8977935fa545aa062fdd3f1c8d6d22f2637 Mon Sep 17 00:00:00 2001 From: Himalaiah Date: Thu, 19 Feb 2015 14:22:18 -0200 Subject: [PATCH 2/5] Outro comentario --- ContaPessoas/Contador.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ContaPessoas/Contador.m b/ContaPessoas/Contador.m index 0bea3f2..02d9286 100644 --- a/ContaPessoas/Contador.m +++ b/ContaPessoas/Contador.m @@ -1,7 +1,7 @@ // // Contador.m // ContaPessoas -// C +// lalalalaLALALALALALA // Created by Vinicius Miana on 2/18/15. // Copyright (c) 2015 Vinicius Miana. All rights reserved. // From 4d211380f8e8e95e17994a2e6a666c7e6cb54b5c Mon Sep 17 00:00:00 2001 From: Himalaiah Date: Thu, 19 Feb 2015 14:29:54 -0200 Subject: [PATCH 3/5] Oi --- ContaPessoas/Contador.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ContaPessoas/Contador.m b/ContaPessoas/Contador.m index 02d9286..346074b 100644 --- a/ContaPessoas/Contador.m +++ b/ContaPessoas/Contador.m @@ -1,7 +1,7 @@ // // Contador.m // ContaPessoas -// lalalalaLALALALALALA +// Sem comentários // Created by Vinicius Miana on 2/18/15. // Copyright (c) 2015 Vinicius Miana. All rights reserved. // From 8564c1defe23291e7d70c8780f179b8b494c277e Mon Sep 17 00:00:00 2001 From: Himalaiah Date: Thu, 19 Feb 2015 15:56:19 -0200 Subject: [PATCH 4/5] =?UTF-8?q?C=C3=B3digo=20melhorado?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ContaPessoas/Contador.h | 5 ++++- ContaPessoas/Contador.m | 17 ++++++++++++++--- ContaPessoas/FirstViewController.m | 2 +- ContaPessoas/SecondViewController.m | 4 ++-- ContaPessoasTests/ContaPessoasTests.m | 8 ++++++++ ContaPessoasTests/ContadorTests.m | 1 + 6 files changed, 30 insertions(+), 7 deletions(-) diff --git a/ContaPessoas/Contador.h b/ContaPessoas/Contador.h index 18b7c16..14f8e9c 100644 --- a/ContaPessoas/Contador.h +++ b/ContaPessoas/Contador.h @@ -6,13 +6,16 @@ // Copyright (c) 2015 Vinicius Miana. All rights reserved. // -@interface Contador : NSObject +@interface Contador : NSObject - (void)maisUmCueca; - (void)maisUmaGata; -(int)getBoys; -(int)getGirls; +-(int)getTotal; +-(id)init; ++(Contador *) instancia; @end diff --git a/ContaPessoas/Contador.m b/ContaPessoas/Contador.m index 346074b..0972ffd 100644 --- a/ContaPessoas/Contador.m +++ b/ContaPessoas/Contador.m @@ -11,12 +11,19 @@ @implementation Contador { - int boy; - int girl; + int boy; + int girl; + } +static Contador *_instancia; + ++(Contador *) instancia{ + if(_instancia == nil){ + _instancia = [[Contador alloc] init]; + } + return _instancia; } -(id)init { - self = [super init]; if (self) { boy = 0; girl = 0; @@ -39,6 +46,10 @@ -(int)getGirls { return girl; } +-(int)getTotal{ + return girl + boy; +} + @end diff --git a/ContaPessoas/FirstViewController.m b/ContaPessoas/FirstViewController.m index fc70dd5..128e95a 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 instancia]; // Do any additional setup after loading the view, typically from a nib. } diff --git a/ContaPessoas/SecondViewController.m b/ContaPessoas/SecondViewController.m index a2a66f5..6fb1b21 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 instancia]; } @@ -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..ae83307 100644 --- a/ContaPessoasTests/ContaPessoasTests.m +++ b/ContaPessoasTests/ContaPessoasTests.m @@ -21,6 +21,7 @@ - (void)testContaMeninos { Contador *c = [[Contador alloc] init]; [c maisUmCueca]; XCTAssert(([c getBoys] == 1), @"Pass"); + XCTAssert(([c getGirls] == 0), @"Pass"); } - (void)testContaMeninas { @@ -30,5 +31,12 @@ - (void)testContaMeninas { XCTAssert(([c getBoys] == 0), @"Pass"); } +- (void)testContaTotal{ + Contador *c = [[Contador alloc] init]; + [c maisUmaGata]; + [c maisUmCueca]; + + XCTAssert(([c getTotal] == 2), @"Pass"); +} @end diff --git a/ContaPessoasTests/ContadorTests.m b/ContaPessoasTests/ContadorTests.m index 67c06ac..5151fbd 100644 --- a/ContaPessoasTests/ContadorTests.m +++ b/ContaPessoasTests/ContadorTests.m @@ -37,4 +37,5 @@ - (void)testPerformanceExample { }]; } + @end From eedda71f507952b1b3866665f18972ff22ef5acc Mon Sep 17 00:00:00 2001 From: Himalaiah Date: Fri, 20 Feb 2015 13:46:31 -0200 Subject: [PATCH 5/5] Adicao de viewDidAppear --- ContaPessoas/SecondViewController.m | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ContaPessoas/SecondViewController.m b/ContaPessoas/SecondViewController.m index 6fb1b21..15e9bb0 100644 --- a/ContaPessoas/SecondViewController.m +++ b/ContaPessoas/SecondViewController.m @@ -22,6 +22,9 @@ - (void)viewDidLoad { contador = [Contador instancia]; } +- (void)viewDidAppear:(BOOL)animated{ + [self click:self]; +} - (void)didReceiveMemoryWarning {