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/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 18b7c16..8079c9e 100644 --- a/ContaPessoas/Contador.h +++ b/ContaPessoas/Contador.h @@ -6,13 +6,21 @@ // 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; -(int)getBoys; -(int)getGirls; - +-(int)getTotal; ++(id)getInstance; @end diff --git a/ContaPessoas/Contador.m b/ContaPessoas/Contador.m index fa64ad8..308a006 100644 --- a/ContaPessoas/Contador.m +++ b/ContaPessoas/Contador.m @@ -11,24 +11,29 @@ @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; } - (void)maisUmCueca { boy = boy + 1; + [_mostrar atualiza]; } - (void)maisUmaGata { girl++; + [_mostrar atualiza]; } -(int)getBoys { @@ -38,7 +43,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 fc70dd5..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. } @@ -39,3 +39,4 @@ - (IBAction)clickGirl:(id)sender { } @end +//rip in peace \ No newline at end of file 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 a2a66f5..988e40f 100644 --- a/ContaPessoas/SecondViewController.m +++ b/ContaPessoas/SecondViewController.m @@ -10,30 +10,35 @@ #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]; + [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 getGirls] + [contador getBoys] ]; + _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]]; } - - @end 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 {