From c6021d65cd40656645d66fdddb2da3808c12fd3c Mon Sep 17 00:00:00 2001 From: Rafael Cavalcante Ferreira Santos Matos Date: Thu, 19 Feb 2015 08:53:06 -0200 Subject: [PATCH 1/4] test --- ContaPessoas/SecondViewController.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ContaPessoas/SecondViewController.m b/ContaPessoas/SecondViewController.m index a2a66f5..a9af1bf 100644 --- a/ContaPessoas/SecondViewController.m +++ b/ContaPessoas/SecondViewController.m @@ -34,6 +34,6 @@ - (IBAction)click:(id)sender { _totalGirls.text = [NSString stringWithFormat: @"%d", [contador getGirls]]; _total.text = [NSString stringWithFormat:@"%d", [contador getGirls] + [contador getBoys] ]; } - +//testerino @end From 732275e6f93181ac006083279739f96ad515e8e5 Mon Sep 17 00:00:00 2001 From: Rafael Cavalcante Ferreira Santos Matos Date: Thu, 19 Feb 2015 09:07:07 -0200 Subject: [PATCH 2/4] testerino testerino --- ContaPessoas/FirstViewController.m | 1 + 1 file changed, 1 insertion(+) diff --git a/ContaPessoas/FirstViewController.m b/ContaPessoas/FirstViewController.m index fc70dd5..26b4396 100644 --- a/ContaPessoas/FirstViewController.m +++ b/ContaPessoas/FirstViewController.m @@ -39,3 +39,4 @@ - (IBAction)clickGirl:(id)sender { } @end +//rip in peace \ No newline at end of file From 57d27af6b98cb340f666d4803f144e904938ed1e Mon Sep 17 00:00:00 2001 From: Rafael Cavalcante Ferreira Santos Matos Date: Thu, 19 Feb 2015 11:28:26 -0200 Subject: [PATCH 3/4] test Arrumei tudo --- ContaPessoas.xcodeproj/project.pbxproj | 2 ++ ContaPessoas/Contador.h | 3 ++- ContaPessoas/Contador.m | 15 +++++++++++++-- ContaPessoas/FirstViewController.m | 2 +- ContaPessoas/SecondViewController.m | 13 +++++++------ ContaPessoasTests/ContaPessoasTests.m | 1 + 6 files changed, 26 insertions(+), 10 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/Contador.h b/ContaPessoas/Contador.h index 18b7c16..4dd0833 100644 --- a/ContaPessoas/Contador.h +++ b/ContaPessoas/Contador.h @@ -13,6 +13,7 @@ -(int)getBoys; -(int)getGirls; - +-(int)getTotal; ++(id)getInstance; @end diff --git a/ContaPessoas/Contador.m b/ContaPessoas/Contador.m index fa64ad8..27be058 100644 --- a/ContaPessoas/Contador.m +++ b/ContaPessoas/Contador.m @@ -11,15 +11,18 @@ @implementation Contador { + int boy; int girl; } +static Contador *contador = nil; -(id)init { self = [super init]; - if (self) { + if (self == nil) { boy = 0; girl = 0; + } return self; } @@ -38,7 +41,15 @@ -(int)getBoys { -(int)getGirls { return girl; } - +-(int)getTotal{ + return boy + girl; +} ++(id)getInstance{ + if (contador == nil) { + contador = [[Contador alloc]init]; + } + return contador; +} @end diff --git a/ContaPessoas/FirstViewController.m b/ContaPessoas/FirstViewController.m index 26b4396..99bda30 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 getInstance]; // Do any additional setup after loading the view, typically from a nib. } diff --git a/ContaPessoas/SecondViewController.m b/ContaPessoas/SecondViewController.m index a9af1bf..78b4e08 100644 --- a/ContaPessoas/SecondViewController.m +++ b/ContaPessoas/SecondViewController.m @@ -10,20 +10,21 @@ #import "Contador.h" @interface SecondViewController () { - Contador *contador; } @end -@implementation SecondViewController +@implementation SecondViewController{ + Contador* contador; +} + - (void)viewDidLoad { [super viewDidLoad]; - contador = [[Contador alloc] init]; -} - + contador = [Contador getInstance]; +} - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. @@ -32,7 +33,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] ]; } //testerino diff --git a/ContaPessoasTests/ContaPessoasTests.m b/ContaPessoasTests/ContaPessoasTests.m index 579bb3f..99d5b99 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 getTotal] == 1), @"Pass"); } - (void)testContaMeninas { From fcc5c50e19d7ef5e3cbe4b8cfc428d490188fbcd Mon Sep 17 00:00:00 2001 From: Rafael Cavalcante Ferreira Santos Matos Date: Fri, 20 Feb 2015 10:56:49 -0200 Subject: [PATCH 4/4] implementando Delegate --- ContaPessoas/Base.lproj/Main.storyboard | 26 ++++++++++++------------- ContaPessoas/Contador.h | 7 +++++++ ContaPessoas/Contador.m | 2 ++ ContaPessoas/SecondViewController.h | 3 ++- ContaPessoas/SecondViewController.m | 12 ++++++++---- 5 files changed, 32 insertions(+), 18 deletions(-) diff --git a/ContaPessoas/Base.lproj/Main.storyboard b/ContaPessoas/Base.lproj/Main.storyboard index 99fa0dc..1c62221 100644 --- a/ContaPessoas/Base.lproj/Main.storyboard +++ b/ContaPessoas/Base.lproj/Main.storyboard @@ -23,30 +23,30 @@ - - @@ -67,7 +67,7 @@ - + diff --git a/ContaPessoas/Contador.h b/ContaPessoas/Contador.h index 4dd0833..8079c9e 100644 --- a/ContaPessoas/Contador.h +++ b/ContaPessoas/Contador.h @@ -6,8 +6,15 @@ // Copyright (c) 2015 Vinicius Miana. All rights reserved. // +@protocol Mostrador +@required +-(void)atualiza; +@end + @interface Contador : NSObject +@property (nonatomic,weak)id mostrar; + - (void)maisUmCueca; - (void)maisUmaGata; diff --git a/ContaPessoas/Contador.m b/ContaPessoas/Contador.m index 27be058..308a006 100644 --- a/ContaPessoas/Contador.m +++ b/ContaPessoas/Contador.m @@ -29,9 +29,11 @@ -(id)init { - (void)maisUmCueca { boy = boy + 1; + [_mostrar atualiza]; } - (void)maisUmaGata { girl++; + [_mostrar atualiza]; } -(int)getBoys { diff --git a/ContaPessoas/SecondViewController.h b/ContaPessoas/SecondViewController.h index f907831..cbeddfc 100644 --- a/ContaPessoas/SecondViewController.h +++ b/ContaPessoas/SecondViewController.h @@ -7,8 +7,9 @@ // #import +#import "Contador.h" -@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 78b4e08..988e40f 100644 --- a/ContaPessoas/SecondViewController.m +++ b/ContaPessoas/SecondViewController.m @@ -22,19 +22,23 @@ @implementation SecondViewController{ - (void)viewDidLoad { [super viewDidLoad]; contador = [Contador getInstance]; + [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] ]; + _total.text = [NSString stringWithFormat:@"%d", [contador getTotal]]; +} +-(void)atualiza{ +_totalBoys.text = [NSString stringWithFormat: @"%d", [contador getBoys]]; +_totalGirls.text = [NSString stringWithFormat: @"%d", [contador getGirls]]; +_total.text = [NSString stringWithFormat:@"%d", [contador getTotal]]; } -//testerino - @end