From 624111e07ad69b30b3e38b6a167aba5e29447298 Mon Sep 17 00:00:00 2001 From: camposmandy Date: Thu, 19 Feb 2015 14:27:10 -0200 Subject: [PATCH 1/5] commit --- ContaPessoas/Contador.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ContaPessoas/Contador.m b/ContaPessoas/Contador.m index fa64ad8..8ac9209 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" From 9d18d33baaa8f3df501c9e86a1c70d2d2a6f94f5 Mon Sep 17 00:00:00 2001 From: camposmandy Date: Thu, 19 Feb 2015 15:54:02 -0200 Subject: [PATCH 2/5] getTotal Singleton Teste --- ContaPessoas/Contador.h | 3 +++ ContaPessoas/Contador.m | 17 ++++++++++++++++- ContaPessoas/FirstViewController.m | 2 +- ContaPessoas/SecondViewController.m | 2 +- ContaPessoasTests/ContaPessoasTests.m | 6 ++++++ 5 files changed, 27 insertions(+), 3 deletions(-) diff --git a/ContaPessoas/Contador.h b/ContaPessoas/Contador.h index 18b7c16..3f93cc6 100644 --- a/ContaPessoas/Contador.h +++ b/ContaPessoas/Contador.h @@ -10,9 +10,12 @@ - (void)maisUmCueca; - (void)maisUmaGata; +- (void)totalCuecaEGata: (int) b : (int) g; -(int)getBoys; -(int)getGirls; +-(int)getTotal; ++(Contador *) instance; @end diff --git a/ContaPessoas/Contador.m b/ContaPessoas/Contador.m index 8ac9209..c8872e9 100644 --- a/ContaPessoas/Contador.m +++ b/ContaPessoas/Contador.m @@ -13,23 +13,36 @@ @implementation Contador { int boy; int girl; + int total; } +static Contador *_instance = nil; + -(id)init { self = [super init]; if (self) { boy = 0; girl = 0; + total = 0; } return self; } ++(Contador *)instance{ + + if(_instance == nil)_instance = [[Contador alloc] init]; + return _instance; +} + - (void)maisUmCueca { boy = boy + 1; } - (void)maisUmaGata { girl++; } +- (void) totalCuecaEGata: (int) b : (int) g { + total = boy + girl; +} -(int)getBoys { return boy; @@ -39,7 +52,9 @@ -(int)getGirls { return girl; } - +-(int)getTotal { + return total; +} @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/SecondViewController.m b/ContaPessoas/SecondViewController.m index a2a66f5..3e4f77e 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 instance]; } diff --git a/ContaPessoasTests/ContaPessoasTests.m b/ContaPessoasTests/ContaPessoasTests.m index 579bb3f..15ccf3c 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,10 @@ - (void)testContaMeninas { XCTAssert(([c getBoys] == 0), @"Pass"); } +- (void)testTotal { + Contador *c = [[Contador alloc] init]; + [c totalCuecaEGata:[c getBoys]:[c getGirls]]; + XCTAssert(([c getTotal] == 0), @"Pass"); +} @end From e0456ddd505aa4b36803e7481086c1d369df7bca Mon Sep 17 00:00:00 2001 From: camposmandy Date: Thu, 19 Feb 2015 17:04:55 -0200 Subject: [PATCH 3/5] getTotal simplificado --- ContaPessoas/Contador.h | 1 - ContaPessoas/Contador.m | 7 ++----- ContaPessoasTests/ContaPessoasTests.m | 3 +-- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/ContaPessoas/Contador.h b/ContaPessoas/Contador.h index 3f93cc6..7721a58 100644 --- a/ContaPessoas/Contador.h +++ b/ContaPessoas/Contador.h @@ -10,7 +10,6 @@ - (void)maisUmCueca; - (void)maisUmaGata; -- (void)totalCuecaEGata: (int) b : (int) g; -(int)getBoys; -(int)getGirls; diff --git a/ContaPessoas/Contador.m b/ContaPessoas/Contador.m index c8872e9..385f95a 100644 --- a/ContaPessoas/Contador.m +++ b/ContaPessoas/Contador.m @@ -23,7 +23,7 @@ -(id)init { if (self) { boy = 0; girl = 0; - total = 0; + } return self; } @@ -40,9 +40,6 @@ - (void)maisUmCueca { - (void)maisUmaGata { girl++; } -- (void) totalCuecaEGata: (int) b : (int) g { - total = boy + girl; -} -(int)getBoys { return boy; @@ -53,7 +50,7 @@ -(int)getGirls { } -(int)getTotal { - return total; + return girl + boy ; } @end diff --git a/ContaPessoasTests/ContaPessoasTests.m b/ContaPessoasTests/ContaPessoasTests.m index 15ccf3c..599be08 100644 --- a/ContaPessoasTests/ContaPessoasTests.m +++ b/ContaPessoasTests/ContaPessoasTests.m @@ -33,8 +33,7 @@ - (void)testContaMeninas { - (void)testTotal { Contador *c = [[Contador alloc] init]; - [c totalCuecaEGata:[c getBoys]:[c getGirls]]; XCTAssert(([c getTotal] == 0), @"Pass"); } -@end +@end From 39fbb25a94168d2666ebb905f860d1ea0b21dd4d Mon Sep 17 00:00:00 2001 From: camposmandy Date: Thu, 19 Feb 2015 17:23:37 -0200 Subject: [PATCH 4/5] getTotal simplificado --- ContaPessoas/Contador.h | 2 ++ ContaPessoas/Contador.m | 16 ++++++++++++++-- ContaPessoas/FirstViewController.m | 2 +- ContaPessoas/SecondViewController.m | 2 +- ContaPessoasTests/ContaPessoasTests.m | 7 ++++++- 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/ContaPessoas/Contador.h b/ContaPessoas/Contador.h index 18b7c16..7721a58 100644 --- a/ContaPessoas/Contador.h +++ b/ContaPessoas/Contador.h @@ -13,6 +13,8 @@ -(int)getBoys; -(int)getGirls; +-(int)getTotal; ++(Contador *) instance; @end diff --git a/ContaPessoas/Contador.m b/ContaPessoas/Contador.m index fa64ad8..385f95a 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,17 +13,27 @@ @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; +} + - (void)maisUmCueca { boy = boy + 1; } @@ -39,7 +49,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/SecondViewController.m b/ContaPessoas/SecondViewController.m index a2a66f5..3e4f77e 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 instance]; } 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 From 59a553771ad603c2f5e5ed790bf655d2d748a556 Mon Sep 17 00:00:00 2001 From: camposmandy Date: Fri, 20 Feb 2015 16:16:46 -0200 Subject: [PATCH 5/5] Delegate --- ContaPessoas.xcodeproj/project.pbxproj | 4 ++++ ContaPessoas/Contador.h | 6 +++++- ContaPessoas/Contador.m | 14 ++++++++++++++ ContaPessoas/Mostrador.h | 22 ++++++++++++++++++++++ ContaPessoas/SecondViewController.h | 5 ++++- ContaPessoas/SecondViewController.m | 15 ++++++++++++--- 6 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 ContaPessoas/Mostrador.h 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 7721a58..ebb35a7 100644 --- a/ContaPessoas/Contador.h +++ b/ContaPessoas/Contador.h @@ -6,8 +6,12 @@ // Copyright (c) 2015 Vinicius Miana. All rights reserved. // +#import "Mostrador.h" + @interface Contador : NSObject +@property (nonatomic, weak) id delegate; + - (void)maisUmCueca; - (void)maisUmaGata; @@ -15,6 +19,6 @@ -(int)getGirls; -(int)getTotal; -+(Contador *) instance; ++(Contador *) instance; @end diff --git a/ContaPessoas/Contador.m b/ContaPessoas/Contador.m index 385f95a..21842e9 100644 --- a/ContaPessoas/Contador.m +++ b/ContaPessoas/Contador.m @@ -34,11 +34,23 @@ +(Contador *)instance{ 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 { @@ -53,5 +65,7 @@ -(int)getTotal { return girl + boy ; } + + @end 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 3e4f77e..bae768b 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; @@ -20,9 +21,12 @@ @implementation SecondViewController - (void)viewDidLoad { [super viewDidLoad]; contador = [Contador instance]; + contador.delegate = self; } - +//-(void) viewDidAppear:(BOOL)animated{ +// +//} - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; @@ -34,6 +38,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