From 92fa27e56fa1c02ab5249d155fb7e7d2a168d2e2 Mon Sep 17 00:00:00 2001 From: dwarque Date: Thu, 19 Feb 2015 08:53:15 -0200 Subject: [PATCH 1/7] Add random comment line. --- ContaPessoas/FirstViewController.m | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ContaPessoas/FirstViewController.m b/ContaPessoas/FirstViewController.m index fc70dd5..8e3f4fe 100644 --- a/ContaPessoas/FirstViewController.m +++ b/ContaPessoas/FirstViewController.m @@ -2,7 +2,7 @@ // FirstViewController.m // ContaPessoas // -// Created by Vinicius Miana on 2/18/15. +// Created by Eduardo Quadros on 2/18/15. // Copyright (c) 2015 Vinicius Miana. All rights reserved. // @@ -38,4 +38,6 @@ - (IBAction)clickGirl:(id)sender { NSLog(@"Meninas - %i",[contador getGirls]); } +// RANDOM LINE :) + @end From 04d8ba110b858832aefdd682f1a6d3d235b49b6f Mon Sep 17 00:00:00 2001 From: dwarque Date: Thu, 19 Feb 2015 11:20:45 -0200 Subject: [PATCH 2/7] =?UTF-8?q?Adiciona=20um=20novo=20m=C3=A9todo=20para?= =?UTF-8?q?=20extrair=20o=20n=C3=BAmero=20total=20de=20pessoas=20e=20sua?= =?UTF-8?q?=20classe=20de=20teste.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ContaPessoas/Contador.h | 1 + ContaPessoas/Contador.m | 5 +++-- ContaPessoasTests/ContaPessoasTests.m | 9 +++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/ContaPessoas/Contador.h b/ContaPessoas/Contador.h index 18b7c16..136a659 100644 --- a/ContaPessoas/Contador.h +++ b/ContaPessoas/Contador.h @@ -13,6 +13,7 @@ -(int)getBoys; -(int)getGirls; +-(int)getTotal; @end diff --git a/ContaPessoas/Contador.m b/ContaPessoas/Contador.m index fa64ad8..0c12bf6 100644 --- a/ContaPessoas/Contador.m +++ b/ContaPessoas/Contador.m @@ -39,7 +39,8 @@ -(int)getGirls { return girl; } - +-(int)getTotal { + return boy + girl; +} @end - diff --git a/ContaPessoasTests/ContaPessoasTests.m b/ContaPessoasTests/ContaPessoasTests.m index 579bb3f..4e9662e 100644 --- a/ContaPessoasTests/ContaPessoasTests.m +++ b/ContaPessoasTests/ContaPessoasTests.m @@ -30,5 +30,14 @@ - (void)testContaMeninas { XCTAssert(([c getBoys] == 0), @"Pass"); } +- (void)testContarTodos { + Contador *c = [[Contador alloc] init]; + [c maisUmaGata]; + [c maisUmaGata]; + [c maisUmCueca]; + XCTAssert(([c getGirls] == 2), @"Pass"); + XCTAssert(([c getBoys] == 1), @"Pass"); + XCTAssert(([c getTotal] == 3), @"Pass"); +} @end From 8cd72ac07f3512c2cff70b9504dbb5e1a9f6d751 Mon Sep 17 00:00:00 2001 From: dwarque Date: Thu, 19 Feb 2015 11:50:50 -0200 Subject: [PATCH 3/7] Prepara o singleton e remove o "lixo". --- ContaPessoas/Contador.h | 2 ++ ContaPessoas/Contador.m | 12 ++++++++++-- ContaPessoas/FirstViewController.m | 2 -- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/ContaPessoas/Contador.h b/ContaPessoas/Contador.h index 136a659..179d1e0 100644 --- a/ContaPessoas/Contador.h +++ b/ContaPessoas/Contador.h @@ -8,6 +8,8 @@ @interface Contador : NSObject ++(Contador *)sharedCounter; + - (void)maisUmCueca; - (void)maisUmaGata; diff --git a/ContaPessoas/Contador.m b/ContaPessoas/Contador.m index 0c12bf6..10c0101 100644 --- a/ContaPessoas/Contador.m +++ b/ContaPessoas/Contador.m @@ -15,9 +15,17 @@ @implementation Contador { int girl; } +static Contador *contador = nil; + ++(Contador *)sharedCounter { + if (contador == nil) { + contador = [[super allocWithZone:NULL] init]; + } + return contador; +} + -(id)init { - self = [super init]; - if (self) { + if ((self = [super init])) { boy = 0; girl = 0; } diff --git a/ContaPessoas/FirstViewController.m b/ContaPessoas/FirstViewController.m index 8e3f4fe..8412505 100644 --- a/ContaPessoas/FirstViewController.m +++ b/ContaPessoas/FirstViewController.m @@ -38,6 +38,4 @@ - (IBAction)clickGirl:(id)sender { NSLog(@"Meninas - %i",[contador getGirls]); } -// RANDOM LINE :) - @end From 34070e9fcd6e4ad702a689c3926bfcb510cfd371 Mon Sep 17 00:00:00 2001 From: dwarque Date: Thu, 19 Feb 2015 12:00:12 -0200 Subject: [PATCH 4/7] Singleton pronto. --- ContaPessoas/Contador.m | 7 +++---- ContaPessoas/FirstViewController.h | 5 ++++- ContaPessoas/FirstViewController.m | 7 +++---- ContaPessoas/SecondViewController.h | 5 ++++- ContaPessoas/SecondViewController.m | 12 ++++-------- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/ContaPessoas/Contador.m b/ContaPessoas/Contador.m index 10c0101..aa51634 100644 --- a/ContaPessoas/Contador.m +++ b/ContaPessoas/Contador.m @@ -15,11 +15,10 @@ @implementation Contador { int girl; } -static Contador *contador = nil; - +(Contador *)sharedCounter { - if (contador == nil) { - contador = [[super allocWithZone:NULL] init]; + static Contador *contador = nil; + if (!contador) { + contador = [[Contador alloc] init]; } return contador; } diff --git a/ContaPessoas/FirstViewController.h b/ContaPessoas/FirstViewController.h index 59c8301..0012962 100644 --- a/ContaPessoas/FirstViewController.h +++ b/ContaPessoas/FirstViewController.h @@ -7,8 +7,11 @@ // #import +@class Contador; -@interface FirstViewController : UIViewController +@interface FirstViewController : UIViewController { + Contador *contador; +} - (IBAction)clickBoy:(id)sender; - (IBAction)clickGirl:(id)sender; diff --git a/ContaPessoas/FirstViewController.m b/ContaPessoas/FirstViewController.m index 8412505..e79045b 100644 --- a/ContaPessoas/FirstViewController.m +++ b/ContaPessoas/FirstViewController.m @@ -8,18 +8,17 @@ #import "FirstViewController.h" #import "Contador.h" +#import "SecondViewController.h" @interface FirstViewController () @end -@implementation FirstViewController { - Contador *contador; -} +@implementation FirstViewController - (void)viewDidLoad { [super viewDidLoad]; - contador = [[Contador alloc] init]; + contador = [Contador sharedCounter]; // Do any additional setup after loading the view, typically from a nib. } diff --git a/ContaPessoas/SecondViewController.h b/ContaPessoas/SecondViewController.h index f907831..e442c4a 100644 --- a/ContaPessoas/SecondViewController.h +++ b/ContaPessoas/SecondViewController.h @@ -7,8 +7,11 @@ // #import +@class Contador; -@interface SecondViewController : UIViewController +@interface SecondViewController : UIViewController { + Contador *contador; +} @property (weak, nonatomic) IBOutlet UILabel *totalBoys; @property (weak, nonatomic) IBOutlet UILabel *totalGirls; diff --git a/ContaPessoas/SecondViewController.m b/ContaPessoas/SecondViewController.m index a2a66f5..11bcfad 100644 --- a/ContaPessoas/SecondViewController.m +++ b/ContaPessoas/SecondViewController.m @@ -8,10 +8,9 @@ #import "SecondViewController.h" #import "Contador.h" +#import "FirstViewController.h" -@interface SecondViewController () { - Contador *contador; -} +@interface SecondViewController () @end @@ -19,11 +18,9 @@ @implementation SecondViewController - (void)viewDidLoad { [super viewDidLoad]; - contador = [[Contador alloc] init]; + contador = [Contador sharedCounter]; } - - - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. @@ -32,8 +29,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]]; } - @end From f8429770bf6f63f3cd482228f9aa12b47e5138f4 Mon Sep 17 00:00:00 2001 From: dwarque Date: Thu, 19 Feb 2015 12:19:32 -0200 Subject: [PATCH 5/7] Teste com singleton. --- ContaPessoas/FirstViewController.h | 2 +- ContaPessoas/FirstViewController.m | 1 - ContaPessoas/SecondViewController.h | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/ContaPessoas/FirstViewController.h b/ContaPessoas/FirstViewController.h index 0012962..530306e 100644 --- a/ContaPessoas/FirstViewController.h +++ b/ContaPessoas/FirstViewController.h @@ -7,7 +7,7 @@ // #import -@class Contador; +#import "Contador.h" @interface FirstViewController : UIViewController { Contador *contador; diff --git a/ContaPessoas/FirstViewController.m b/ContaPessoas/FirstViewController.m index e79045b..8c1b98d 100644 --- a/ContaPessoas/FirstViewController.m +++ b/ContaPessoas/FirstViewController.m @@ -19,7 +19,6 @@ @implementation FirstViewController - (void)viewDidLoad { [super viewDidLoad]; contador = [Contador sharedCounter]; - // Do any additional setup after loading the view, typically from a nib. } - (void)didReceiveMemoryWarning { diff --git a/ContaPessoas/SecondViewController.h b/ContaPessoas/SecondViewController.h index e442c4a..efc15d0 100644 --- a/ContaPessoas/SecondViewController.h +++ b/ContaPessoas/SecondViewController.h @@ -7,7 +7,7 @@ // #import -@class Contador; +#import "Contador.h" @interface SecondViewController : UIViewController { Contador *contador; From 992b8bb7ef413384ef1c0d8202f8a6a17360dad0 Mon Sep 17 00:00:00 2001 From: dwarque Date: Fri, 20 Feb 2015 11:08:52 -0200 Subject: [PATCH 6/7] Finito. --- ContaPessoas.xcodeproj/project.pbxproj | 2 ++ ContaPessoas/AppDelegate.h | 1 - ContaPessoas/Base.lproj/Main.storyboard | 40 ++++------------------ ContaPessoas/Contador.h | 16 ++++++--- ContaPessoas/Contador.m | 45 ++++++++++--------------- ContaPessoas/FirstViewController.h | 1 - ContaPessoas/FirstViewController.m | 7 ++-- ContaPessoas/SecondViewController.h | 4 +-- ContaPessoas/SecondViewController.m | 13 +++---- ContaPessoasTests/ContaPessoasTests.m | 12 +++---- 10 files changed, 55 insertions(+), 86 deletions(-) diff --git a/ContaPessoas.xcodeproj/project.pbxproj b/ContaPessoas.xcodeproj/project.pbxproj index 9ce30d1..ca06d09 100644 --- a/ContaPessoas.xcodeproj/project.pbxproj +++ b/ContaPessoas.xcodeproj/project.pbxproj @@ -438,6 +438,7 @@ 27A199C81A94B2A8008DC684 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; 27A199C91A94B2A8008DC684 /* Build configuration list for PBXNativeTarget "ContaPessoasTests" */ = { isa = XCConfigurationList; @@ -446,6 +447,7 @@ 27A199CB1A94B2A8008DC684 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; diff --git a/ContaPessoas/AppDelegate.h b/ContaPessoas/AppDelegate.h index a4e16ef..81895ab 100644 --- a/ContaPessoas/AppDelegate.h +++ b/ContaPessoas/AppDelegate.h @@ -14,4 +14,3 @@ @end - diff --git a/ContaPessoas/Base.lproj/Main.storyboard b/ContaPessoas/Base.lproj/Main.storyboard index 99fa0dc..421aa64 100644 --- a/ContaPessoas/Base.lproj/Main.storyboard +++ b/ContaPessoas/Base.lproj/Main.storyboard @@ -16,19 +16,15 @@ - - - - - - - - - - - - @@ -123,15 +104,6 @@ - diff --git a/ContaPessoas/Contador.h b/ContaPessoas/Contador.h index 179d1e0..3f57718 100644 --- a/ContaPessoas/Contador.h +++ b/ContaPessoas/Contador.h @@ -6,16 +6,22 @@ // Copyright (c) 2015 Vinicius Miana. All rights reserved. // +@protocol Mostrador + +@required +-(void)atualiza; + +@end + @interface Contador : NSObject -+(Contador *)sharedCounter; ++ (Contador *)getInstance; - (void)maisUmCueca; - (void)maisUmaGata; --(int)getBoys; --(int)getGirls; --(int)getTotal; +@property (nonatomic, weak) id mostrar; +@property int boy; +@property int girl; @end - diff --git a/ContaPessoas/Contador.m b/ContaPessoas/Contador.m index aa51634..ae39e41 100644 --- a/ContaPessoas/Contador.m +++ b/ContaPessoas/Contador.m @@ -9,45 +9,36 @@ #import #import "Contador.h" +@implementation Contador -@implementation Contador { - int boy; - int girl; -} +#pragma mark Singleton -+(Contador *)sharedCounter { - static Contador *contador = nil; - if (!contador) { - contador = [[Contador alloc] init]; - } - return contador; ++ (Contador *)getInstance { + static Contador *contadorCompartilhado = nil; + static dispatch_once_t token; + dispatch_once(&token, ^{ + contadorCompartilhado = [[self alloc] init]; + }); + return contadorCompartilhado; } --(id)init { +- (id)init { if ((self = [super init])) { - boy = 0; - girl = 0; + _boy = 0; + _girl = 0; } return self; } +#pragma mark Contador + - (void)maisUmCueca { - boy = boy + 1; + _boy = _boy + 1; + [_mostrar atualiza]; } - (void)maisUmaGata { - girl++; -} - --(int)getBoys { - return boy; -} - --(int)getGirls { - return girl; -} - --(int)getTotal { - return boy + girl; + _girl++; + [_mostrar atualiza]; } @end diff --git a/ContaPessoas/FirstViewController.h b/ContaPessoas/FirstViewController.h index 530306e..3895b33 100644 --- a/ContaPessoas/FirstViewController.h +++ b/ContaPessoas/FirstViewController.h @@ -17,4 +17,3 @@ - (IBAction)clickGirl:(id)sender; @end - diff --git a/ContaPessoas/FirstViewController.m b/ContaPessoas/FirstViewController.m index 8c1b98d..30a8db7 100644 --- a/ContaPessoas/FirstViewController.m +++ b/ContaPessoas/FirstViewController.m @@ -18,22 +18,21 @@ @implementation FirstViewController - (void)viewDidLoad { [super viewDidLoad]; - contador = [Contador sharedCounter]; + contador = [Contador getInstance]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; - // Dispose of any resources that can be recreated. } - (IBAction)clickBoy:(id)sender { [contador maisUmCueca]; - NSLog(@"Meninos - %i",[contador getBoys]); + NSLog(@"Meninos - %i", contador.boy); } - (IBAction)clickGirl:(id)sender { [contador maisUmaGata]; - NSLog(@"Meninas - %i",[contador getGirls]); + NSLog(@"Meninas - %i", contador.girl); } @end diff --git a/ContaPessoas/SecondViewController.h b/ContaPessoas/SecondViewController.h index efc15d0..6e632e9 100644 --- a/ContaPessoas/SecondViewController.h +++ b/ContaPessoas/SecondViewController.h @@ -16,7 +16,7 @@ @property (weak, nonatomic) IBOutlet UILabel *totalBoys; @property (weak, nonatomic) IBOutlet UILabel *totalGirls; @property (weak, nonatomic) IBOutlet UILabel *total; -- (IBAction)click:(id)sender; -@end +- (void)atualiza; +@end diff --git a/ContaPessoas/SecondViewController.m b/ContaPessoas/SecondViewController.m index 11bcfad..c8e556b 100644 --- a/ContaPessoas/SecondViewController.m +++ b/ContaPessoas/SecondViewController.m @@ -18,18 +18,19 @@ @implementation SecondViewController - (void)viewDidLoad { [super viewDidLoad]; - contador = [Contador sharedCounter]; + contador = [Contador getInstance]; + contador.mostrar = self; + [self atualiza]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; - // Dispose of any resources that can be recreated. } -- (IBAction)click:(id)sender { - _totalBoys.text = [NSString stringWithFormat: @"%d", [contador getBoys]]; - _totalGirls.text = [NSString stringWithFormat: @"%d", [contador getGirls]]; - _total.text = [NSString stringWithFormat:@"%d", [contador getTotal]]; +- (void)atualiza { + _totalBoys.text = [NSString stringWithFormat: @"%d", contador.boy]; + _totalGirls.text = [NSString stringWithFormat: @"%d", contador.girl]; + _total.text = [NSString stringWithFormat:@"%d", (contador.boy + contador.girl)]; } @end diff --git a/ContaPessoasTests/ContaPessoasTests.m b/ContaPessoasTests/ContaPessoasTests.m index 4e9662e..442e7f0 100644 --- a/ContaPessoasTests/ContaPessoasTests.m +++ b/ContaPessoasTests/ContaPessoasTests.m @@ -20,14 +20,14 @@ @implementation ContaPessoasTests - (void)testContaMeninos { Contador *c = [[Contador alloc] init]; [c maisUmCueca]; - XCTAssert(([c getBoys] == 1), @"Pass"); + XCTAssert((c.boy == 1), @"Pass"); } - (void)testContaMeninas { Contador *c = [[Contador alloc] init]; [c maisUmaGata]; - XCTAssert(([c getGirls] == 1), @"Pass"); - XCTAssert(([c getBoys] == 0), @"Pass"); + XCTAssert((c.girl == 1), @"Pass"); + XCTAssert((c.boy == 0), @"Pass"); } - (void)testContarTodos { @@ -35,9 +35,9 @@ - (void)testContarTodos { [c maisUmaGata]; [c maisUmaGata]; [c maisUmCueca]; - XCTAssert(([c getGirls] == 2), @"Pass"); - XCTAssert(([c getBoys] == 1), @"Pass"); - XCTAssert(([c getTotal] == 3), @"Pass"); + XCTAssert((c.girl == 2), @"Pass"); + XCTAssert((c.boy == 1), @"Pass"); + XCTAssert((c.girl + c.boy == 3), @"Pass"); } @end From b55cad2a2c4d79606361483622e4f11130a3089a Mon Sep 17 00:00:00 2001 From: dwarque Date: Fri, 20 Feb 2015 11:17:43 -0200 Subject: [PATCH 7/7] Conserta o storyboard --- ContaPessoas/Base.lproj/Main.storyboard | 343 +++++++++++++----------- 1 file changed, 181 insertions(+), 162 deletions(-) diff --git a/ContaPessoas/Base.lproj/Main.storyboard b/ContaPessoas/Base.lproj/Main.storyboard index 421aa64..56cc345 100644 --- a/ContaPessoas/Base.lproj/Main.storyboard +++ b/ContaPessoas/Base.lproj/Main.storyboard @@ -1,165 +1,184 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +