diff --git a/ContaPessoas.xcodeproj/project.pbxproj b/ContaPessoas.xcodeproj/project.pbxproj index 9ce30d1..7ca84ed 100644 --- a/ContaPessoas.xcodeproj/project.pbxproj +++ b/ContaPessoas.xcodeproj/project.pbxproj @@ -32,6 +32,7 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 1057223C1A97945C00A01055 /* Mostrador.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Mostrador.h; sourceTree = ""; }; 27A199A01A94B2A8008DC684 /* ContaPessoas.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ContaPessoas.app; sourceTree = BUILT_PRODUCTS_DIR; }; 27A199A41A94B2A8008DC684 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 27A199A51A94B2A8008DC684 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; @@ -107,6 +108,7 @@ 27A199A31A94B2A8008DC684 /* Supporting Files */, 27A199D21A94D1FA008DC684 /* Contador.m */, 27A199D41A94D22B008DC684 /* Contador.h */, + 1057223C1A97945C00A01055 /* Mostrador.h */, ); path = ContaPessoas; sourceTree = ""; @@ -438,6 +440,7 @@ 27A199C81A94B2A8008DC684 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; 27A199C91A94B2A8008DC684 /* Build configuration list for PBXNativeTarget "ContaPessoasTests" */ = { isa = XCConfigurationList; @@ -446,6 +449,7 @@ 27A199CB1A94B2A8008DC684 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; diff --git a/ContaPessoas/Contador.h b/ContaPessoas/Contador.h index 18b7c16..ebb35a7 100644 --- a/ContaPessoas/Contador.h +++ b/ContaPessoas/Contador.h @@ -6,13 +6,19 @@ // Copyright (c) 2015 Vinicius Miana. All rights reserved. // +#import "Mostrador.h" + @interface Contador : NSObject +@property (nonatomic, weak) id delegate; + - (void)maisUmCueca; - (void)maisUmaGata; -(int)getBoys; -(int)getGirls; +-(int)getTotal; ++(Contador *) instance; @end diff --git a/ContaPessoas/Contador.m b/ContaPessoas/Contador.m index fa64ad8..d51d987 100644 --- a/ContaPessoas/Contador.m +++ b/ContaPessoas/Contador.m @@ -4,7 +4,7 @@ // // Created by Vinicius Miana on 2/18/15. // Copyright (c) 2015 Vinicius Miana. All rights reserved. -// +//amanda #import #import "Contador.h" @@ -13,22 +13,44 @@ @implementation Contador { int boy; int girl; + int total; } +static Contador *_instance = nil; + -(id)init { self = [super init]; if (self) { boy = 0; girl = 0; + } return self; } ++(Contador *)instance{ + + if(_instance == nil)_instance = [[Contador alloc] init]; + return _instance; +} + + //+(Contador *)instance{ +////static Contador *sharedContador = nil; +//static dispatch_once_t onceToken; +//dispatch_once(&onceToken, ˆ +// { +// sharedContador = [[self alloc] init]; +// }); return sharedContador;} + + - (void)maisUmCueca { boy = boy + 1; + [_delegate meninos: (boy) meninas: (girl) geral:[self getTotal]]; } + - (void)maisUmaGata { girl++; + [_delegate meninos: (boy) meninas: (girl) geral:[self getTotal]]; } -(int)getBoys { @@ -39,7 +61,9 @@ -(int)getGirls { return girl; } - +-(int)getTotal { + return girl + boy ; +} @end diff --git a/ContaPessoas/FirstViewController.m b/ContaPessoas/FirstViewController.m index fc70dd5..39fb11b 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 instance]; // Do any additional setup after loading the view, typically from a nib. } diff --git a/ContaPessoas/Mostrador.h b/ContaPessoas/Mostrador.h new file mode 100644 index 0000000..e28afda --- /dev/null +++ b/ContaPessoas/Mostrador.h @@ -0,0 +1,22 @@ +// +// Mostrador.h +// ContaPessoas +// +// Created by Amanda Guimaraes Campos on 20/02/15. +// Copyright (c) 2015 Vinicius Miana. All rights reserved. +// + +#import + +@protocol Mostrador + +//@required + + +- (void) meninos: (int)b meninas: (int)g geral:(int)t; + +//@optional +//-(void)optionalDelegateMethodOne; +//-(void)optionalDelegateMethodTwo:(NSString *)withArgument; + +@end \ No newline at end of file diff --git a/ContaPessoas/SecondViewController.h b/ContaPessoas/SecondViewController.h index f907831..da9f4f5 100644 --- a/ContaPessoas/SecondViewController.h +++ b/ContaPessoas/SecondViewController.h @@ -7,12 +7,15 @@ // #import +#import "Mostrador.h" -@interface SecondViewController : UIViewController +@interface SecondViewController : UIViewController @property (weak, nonatomic) IBOutlet UILabel *totalBoys; @property (weak, nonatomic) IBOutlet UILabel *totalGirls; @property (weak, nonatomic) IBOutlet UILabel *total; + + - (IBAction)click:(id)sender; @end diff --git a/ContaPessoas/SecondViewController.m b/ContaPessoas/SecondViewController.m index a2a66f5..065c0ac 100644 --- a/ContaPessoas/SecondViewController.m +++ b/ContaPessoas/SecondViewController.m @@ -8,6 +8,7 @@ #import "SecondViewController.h" #import "Contador.h" +#import "Mostrador.h" @interface SecondViewController () { Contador *contador; @@ -19,10 +20,14 @@ @implementation SecondViewController - (void)viewDidLoad { [super viewDidLoad]; - contador = [[Contador alloc] init]; + contador = [Contador instance]; + contador.delegate = self; + [self click:self]; } - +//-(void) viewDidAppear:(BOOL)animated{ +// +//} - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; @@ -34,6 +39,11 @@ - (IBAction)click:(id)sender { _totalGirls.text = [NSString stringWithFormat: @"%d", [contador getGirls]]; _total.text = [NSString stringWithFormat:@"%d", [contador getGirls] + [contador getBoys] ]; } - - +//delegate +-(void) meninos:(int)b meninas:(int)g geral:(int)t{ + NSLog(@"g:%d\ln b:%d\ln t:%d\ln",b,g,t); + _totalBoys.text = [NSString stringWithFormat: @"%d", b]; + _totalGirls.text = [NSString stringWithFormat: @"%d",g]; + _total.text = [NSString stringWithFormat:@"%d", t]; +} @end diff --git a/ContaPessoasTests/ContaPessoasTests.m b/ContaPessoasTests/ContaPessoasTests.m index 579bb3f..599be08 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,9 @@ - (void)testContaMeninas { XCTAssert(([c getBoys] == 0), @"Pass"); } +- (void)testTotal { + Contador *c = [[Contador alloc] init]; + XCTAssert(([c getTotal] == 0), @"Pass"); +} -@end +@end