From bf5c6a6797de583da8c1b2414acc89ee7ef7f168 Mon Sep 17 00:00:00 2001 From: Chimello44 Date: Thu, 19 Feb 2015 14:19:29 -0200 Subject: [PATCH 1/4] name changed --- ContaPessoas/AppDelegate.h | 8 +------- ContaPessoas/AppDelegate.m | 8 +------- ContaPessoas/Contador.h | 8 +------- ContaPessoas/Contador.m | 8 +------- ContaPessoas/FirstViewController.h | 8 +------- ContaPessoas/FirstViewController.m | 7 ------- ContaPessoas/SecondViewController.h | 7 ------- ContaPessoas/SecondViewController.m | 7 ------- ContaPessoasTests/ContaPessoasTests.m | 7 ------- ContaPessoasTests/ContadorTests.m | 8 +------- 10 files changed, 6 insertions(+), 70 deletions(-) diff --git a/ContaPessoas/AppDelegate.h b/ContaPessoas/AppDelegate.h index a4e16ef..f376b4c 100644 --- a/ContaPessoas/AppDelegate.h +++ b/ContaPessoas/AppDelegate.h @@ -1,10 +1,4 @@ -// -// AppDelegate.h -// ContaPessoas -// -// Created by Vinicius Miana on 2/18/15. -// Copyright (c) 2015 Vinicius Miana. All rights reserved. -// + #import diff --git a/ContaPessoas/AppDelegate.m b/ContaPessoas/AppDelegate.m index 2f0670a..a84a13e 100644 --- a/ContaPessoas/AppDelegate.m +++ b/ContaPessoas/AppDelegate.m @@ -1,10 +1,4 @@ -// -// AppDelegate.m -// ContaPessoas -// -// Created by Vinicius Miana on 2/18/15. -// Copyright (c) 2015 Vinicius Miana. All rights reserved. -// + #import "AppDelegate.h" diff --git a/ContaPessoas/Contador.h b/ContaPessoas/Contador.h index 18b7c16..8b41ea1 100644 --- a/ContaPessoas/Contador.h +++ b/ContaPessoas/Contador.h @@ -1,10 +1,4 @@ -// -// Contador.h -// ContaPessoas -// -// Created by Vinicius Miana on 2/18/15. -// Copyright (c) 2015 Vinicius Miana. All rights reserved. -// + @interface Contador : NSObject diff --git a/ContaPessoas/Contador.m b/ContaPessoas/Contador.m index fa64ad8..33c8289 100644 --- a/ContaPessoas/Contador.m +++ b/ContaPessoas/Contador.m @@ -1,10 +1,4 @@ -// -// Contador.m -// ContaPessoas -// -// Created by Vinicius Miana on 2/18/15. -// Copyright (c) 2015 Vinicius Miana. All rights reserved. -// + #import #import "Contador.h" diff --git a/ContaPessoas/FirstViewController.h b/ContaPessoas/FirstViewController.h index 59c8301..fde4884 100644 --- a/ContaPessoas/FirstViewController.h +++ b/ContaPessoas/FirstViewController.h @@ -1,10 +1,4 @@ -// -// FirstViewController.h -// ContaPessoas -// -// Created by Vinicius Miana on 2/18/15. -// Copyright (c) 2015 Vinicius Miana. All rights reserved. -// + #import diff --git a/ContaPessoas/FirstViewController.m b/ContaPessoas/FirstViewController.m index fc70dd5..243fb74 100644 --- a/ContaPessoas/FirstViewController.m +++ b/ContaPessoas/FirstViewController.m @@ -1,10 +1,3 @@ -// -// FirstViewController.m -// ContaPessoas -// -// Created by Vinicius Miana on 2/18/15. -// Copyright (c) 2015 Vinicius Miana. All rights reserved. -// #import "FirstViewController.h" #import "Contador.h" diff --git a/ContaPessoas/SecondViewController.h b/ContaPessoas/SecondViewController.h index f907831..7002dc9 100644 --- a/ContaPessoas/SecondViewController.h +++ b/ContaPessoas/SecondViewController.h @@ -1,10 +1,3 @@ -// -// SecondViewController.h -// ContaPessoas -// -// Created by Vinicius Miana on 2/18/15. -// Copyright (c) 2015 Vinicius Miana. All rights reserved. -// #import diff --git a/ContaPessoas/SecondViewController.m b/ContaPessoas/SecondViewController.m index a2a66f5..2337e0b 100644 --- a/ContaPessoas/SecondViewController.m +++ b/ContaPessoas/SecondViewController.m @@ -1,10 +1,3 @@ -// -// SecondViewController.m -// ContaPessoas -// -// Created by Vinicius Miana on 2/18/15. -// Copyright (c) 2015 Vinicius Miana. All rights reserved. -// #import "SecondViewController.h" #import "Contador.h" diff --git a/ContaPessoasTests/ContaPessoasTests.m b/ContaPessoasTests/ContaPessoasTests.m index 579bb3f..195edb3 100644 --- a/ContaPessoasTests/ContaPessoasTests.m +++ b/ContaPessoasTests/ContaPessoasTests.m @@ -1,10 +1,3 @@ -// -// ContaPessoasTests.m -// ContaPessoasTests -// -// Created by Vinicius Miana on 2/18/15. -// Copyright (c) 2015 Vinicius Miana. All rights reserved. -// #import #import diff --git a/ContaPessoasTests/ContadorTests.m b/ContaPessoasTests/ContadorTests.m index 67c06ac..94d91bf 100644 --- a/ContaPessoasTests/ContadorTests.m +++ b/ContaPessoasTests/ContadorTests.m @@ -1,10 +1,4 @@ -// -// ContadorTests.m -// ContaPessoas -// -// Created by Vinicius Miana on 2/18/15. -// Copyright (c) 2015 Vinicius Miana. All rights reserved. -// + #import #import From ef288ca06546d05d942fb897ee1810ac031a38d8 Mon Sep 17 00:00:00 2001 From: Chimello44 Date: Thu, 19 Feb 2015 16:05:33 -0200 Subject: [PATCH 2/4] SINGLETON + TESTE + GETTOTAL = OK --- ContaPessoas.xcodeproj/project.pbxproj | 2 ++ ContaPessoas/AppDelegate.h | 8 ++++++- ContaPessoas/AppDelegate.m | 9 ++++++-- ContaPessoas/Contador.h | 17 ++++++++++---- ContaPessoas/Contador.m | 31 ++++++++++++++++++++++++-- ContaPessoas/FirstViewController.h | 8 ++++++- ContaPessoas/FirstViewController.m | 13 ++++++++++- ContaPessoas/SecondViewController.h | 8 ++++++- ContaPessoas/SecondViewController.m | 11 +++++++-- ContaPessoasTests/ContaPessoasTests.m | 19 ++++++++++++++++ ContaPessoasTests/ContadorTests.m | 8 ++++++- 11 files changed, 119 insertions(+), 15 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 f376b4c..4b65c2d 100644 --- a/ContaPessoas/AppDelegate.h +++ b/ContaPessoas/AppDelegate.h @@ -1,4 +1,10 @@ - +// +// FirstViewController.m +// ContaPessoas +// +// Created by Hugo Luiz Chimello at 19/02/2015 +// Copyright (c) 2015 Hugo Luiz Chimello. All rights reserved. +// #import diff --git a/ContaPessoas/AppDelegate.m b/ContaPessoas/AppDelegate.m index a84a13e..3911fa1 100644 --- a/ContaPessoas/AppDelegate.m +++ b/ContaPessoas/AppDelegate.m @@ -1,5 +1,10 @@ - - +// +// FirstViewController.m +// ContaPessoas +// +// Created by Hugo Luiz Chimello at 19/02/2015 +// Copyright (c) 2015 Hugo Luiz Chimello. All rights reserved. +// #import "AppDelegate.h" @interface AppDelegate () diff --git a/ContaPessoas/Contador.h b/ContaPessoas/Contador.h index 8b41ea1..07df1cd 100644 --- a/ContaPessoas/Contador.h +++ b/ContaPessoas/Contador.h @@ -1,12 +1,21 @@ +// +// FirstViewController.m +// ContaPessoas +// +// Created by Hugo Luiz Chimello at 19/02/2015 +// Copyright (c) 2015 Hugo Luiz Chimello. All rights reserved. +// - -@interface Contador : NSObject - +@interface Contador : NSObject +//tentativa de singleton ++(instancetype)Singleton; +//contador - (void)maisUmCueca; - (void)maisUmaGata; - +//total de meninos/meninas -(int)getBoys; -(int)getGirls; +-(int)getTotal; @end diff --git a/ContaPessoas/Contador.m b/ContaPessoas/Contador.m index 33c8289..06ea9b3 100644 --- a/ContaPessoas/Contador.m +++ b/ContaPessoas/Contador.m @@ -1,4 +1,10 @@ - +// +// FirstViewController.m +// ContaPessoas +// +// Created by Hugo Luiz Chimello at 19/02/2015 +// Copyright (c) 2015 Hugo Luiz Chimello. All rights reserved. +// #import #import "Contador.h" @@ -7,22 +13,43 @@ @implementation Contador { int boy; int girl; + } +//variavel global, fora das chaves +static Contador *singleInstance=nil; + + +//Com variavel total(memoria x processamento) soma -(id)init { self = [super init]; if (self) { boy = 0; girl = 0; + } return self; } +-(int)getTotal{ + return girl+boy; +} +//colocar +(public) para as classes first and second, poderem ter acesso ++(instancetype)Singleton{ + + if (singleInstance==nil) { + singleInstance = [[Contador alloc] init]; +} + + return singleInstance; +} - (void)maisUmCueca { - boy = boy + 1; + boy++; + } - (void)maisUmaGata { girl++; + } -(int)getBoys { diff --git a/ContaPessoas/FirstViewController.h b/ContaPessoas/FirstViewController.h index fde4884..abbc105 100644 --- a/ContaPessoas/FirstViewController.h +++ b/ContaPessoas/FirstViewController.h @@ -1,4 +1,10 @@ - +// +// FirstViewController.m +// ContaPessoas +// +// Created by Hugo Luiz Chimello at 19/02/2015 +// Copyright (c) 2015 Hugo Luiz Chimello. All rights reserved. +// #import diff --git a/ContaPessoas/FirstViewController.m b/ContaPessoas/FirstViewController.m index 243fb74..db06d19 100644 --- a/ContaPessoas/FirstViewController.m +++ b/ContaPessoas/FirstViewController.m @@ -1,3 +1,10 @@ +// +// FirstViewController.m +// ContaPessoas +// +// Created by Hugo Luiz Chimello at 19/02/2015 +// Copyright (c) 2015 Hugo Luiz Chimello. All rights reserved. +// #import "FirstViewController.h" #import "Contador.h" @@ -12,7 +19,10 @@ @implementation FirstViewController { - (void)viewDidLoad { [super viewDidLoad]; - contador = [[Contador alloc] init]; + + contador=[Contador Singleton]; + + // Do any additional setup after loading the view, typically from a nib. } @@ -24,6 +34,7 @@ - (void)didReceiveMemoryWarning { - (IBAction)clickBoy:(id)sender { [contador maisUmCueca]; NSLog(@"Meninos - %i",[contador getBoys]); + NSLog(@"total - %i", [contador getBoys] + [ contador getGirls]); } - (IBAction)clickGirl:(id)sender { diff --git a/ContaPessoas/SecondViewController.h b/ContaPessoas/SecondViewController.h index 7002dc9..3715345 100644 --- a/ContaPessoas/SecondViewController.h +++ b/ContaPessoas/SecondViewController.h @@ -1,4 +1,10 @@ - +// +// FirstViewController.m +// ContaPessoas +// +// Created by Hugo Luiz Chimello at 19/02/2015 +// Copyright (c) 2015 Hugo Luiz Chimello. All rights reserved. +// #import @interface SecondViewController : UIViewController diff --git a/ContaPessoas/SecondViewController.m b/ContaPessoas/SecondViewController.m index 2337e0b..24e17ec 100644 --- a/ContaPessoas/SecondViewController.m +++ b/ContaPessoas/SecondViewController.m @@ -1,3 +1,10 @@ +// +// FirstViewController.m +// ContaPessoas +// +// Created by Hugo Luiz Chimello at 19/02/2015 +// Copyright (c) 2015 Hugo Luiz Chimello. All rights reserved. +// #import "SecondViewController.h" #import "Contador.h" @@ -12,7 +19,7 @@ @implementation SecondViewController - (void)viewDidLoad { [super viewDidLoad]; - contador = [[Contador alloc] init]; + contador= [Contador Singleton]; } @@ -21,7 +28,7 @@ - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - +//criar classe getTotal(contador) - (IBAction)click:(id)sender { _totalBoys.text = [NSString stringWithFormat: @"%d", [contador getBoys]]; _totalGirls.text = [NSString stringWithFormat: @"%d", [contador getGirls]]; diff --git a/ContaPessoasTests/ContaPessoasTests.m b/ContaPessoasTests/ContaPessoasTests.m index 195edb3..67ae74c 100644 --- a/ContaPessoasTests/ContaPessoasTests.m +++ b/ContaPessoasTests/ContaPessoasTests.m @@ -1,3 +1,10 @@ +// +// FirstViewController.m +// ContaPessoas +// +// Created by Hugo Luiz Chimello at 19/02/2015 +// Copyright (c) 2015 Hugo Luiz Chimello. All rights reserved. +// #import #import @@ -14,6 +21,8 @@ - (void)testContaMeninos { Contador *c = [[Contador alloc] init]; [c maisUmCueca]; XCTAssert(([c getBoys] == 1), @"Pass"); + XCTAssert(([c getGirls] == 0), @"Pass"); + } - (void)testContaMeninas { @@ -21,6 +30,16 @@ - (void)testContaMeninas { [c maisUmaGata]; XCTAssert(([c getGirls] == 1), @"Pass"); XCTAssert(([c getBoys] == 0), @"Pass"); + +} + +-(void)testTotal{ + Contador *c=[[Contador alloc] init]; + [c maisUmaGata]; + [c maisUmCueca]; + XCTAssert(([c getGirls] == 1), @"Pass"); + XCTAssert(([c getBoys] == 1), @"Pass"); + XCTAssert(([c getTotal] == 2), @"Pass"); } diff --git a/ContaPessoasTests/ContadorTests.m b/ContaPessoasTests/ContadorTests.m index 94d91bf..3e18545 100644 --- a/ContaPessoasTests/ContadorTests.m +++ b/ContaPessoasTests/ContadorTests.m @@ -1,4 +1,10 @@ - +// +// FirstViewController.m +// ContaPessoas +// +// Created by Hugo Luiz Chimello at 19/02/2015 +// Copyright (c) 2015 Hugo Luiz Chimello. All rights reserved. +// #import #import From 7da2517db3ab546ae7963bbc2d65e9a3eda9ff9b Mon Sep 17 00:00:00 2001 From: Chimello44 Date: Thu, 19 Feb 2015 17:04:11 -0200 Subject: [PATCH 3/4] no message --- ContaPessoas/FirstViewController.m | 2 +- ContaPessoas/SecondViewController.m | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ContaPessoas/FirstViewController.m b/ContaPessoas/FirstViewController.m index db06d19..3342c34 100644 --- a/ContaPessoas/FirstViewController.m +++ b/ContaPessoas/FirstViewController.m @@ -34,7 +34,7 @@ - (void)didReceiveMemoryWarning { - (IBAction)clickBoy:(id)sender { [contador maisUmCueca]; NSLog(@"Meninos - %i",[contador getBoys]); - NSLog(@"total - %i", [contador getBoys] + [ contador getGirls]); + NSLog(@"total - %i", [contador getTotal]); } - (IBAction)clickGirl:(id)sender { diff --git a/ContaPessoas/SecondViewController.m b/ContaPessoas/SecondViewController.m index 24e17ec..1493213 100644 --- a/ContaPessoas/SecondViewController.m +++ b/ContaPessoas/SecondViewController.m @@ -32,7 +32,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] ]; } From b56c0a8d24670689848d0033741286fb25aaf8ea Mon Sep 17 00:00:00 2001 From: Chimello44 Date: Fri, 20 Feb 2015 15:29:28 -0200 Subject: [PATCH 4/4] Degelate+Singleton+test+getTotal= funcionando --- ContaPessoas/Contador.h | 11 ++++++++++- ContaPessoas/Contador.m | 7 ++++--- ContaPessoas/FirstViewController.h | 8 ++++++++ ContaPessoas/FirstViewController.m | 9 +++++++-- ContaPessoas/SecondViewController.h | 4 ++-- ContaPessoas/SecondViewController.m | 10 ++++++++++ 6 files changed, 41 insertions(+), 8 deletions(-) diff --git a/ContaPessoas/Contador.h b/ContaPessoas/Contador.h index 07df1cd..625eb88 100644 --- a/ContaPessoas/Contador.h +++ b/ContaPessoas/Contador.h @@ -5,8 +5,14 @@ // Created by Hugo Luiz Chimello at 19/02/2015 // Copyright (c) 2015 Hugo Luiz Chimello. All rights reserved. // +@protocol HugoDelegate +@required +-(void)MostrarDados; -@interface Contador : NSObject +@end +@interface Contador : NSObject{ + +} //tentativa de singleton +(instancetype)Singleton; //contador @@ -17,5 +23,8 @@ -(int)getGirls; -(int)getTotal; + +@property (nonatomic,weak) id delegate; + @end diff --git a/ContaPessoas/Contador.m b/ContaPessoas/Contador.m index 06ea9b3..39070da 100644 --- a/ContaPessoas/Contador.m +++ b/ContaPessoas/Contador.m @@ -15,11 +15,12 @@ @implementation Contador { int girl; } - +@synthesize delegate; //variavel global, fora das chaves static Contador *singleInstance=nil; + //Com variavel total(memoria x processamento) soma -(id)init { self = [super init]; @@ -45,11 +46,11 @@ +(instancetype)Singleton{ - (void)maisUmCueca { boy++; - + [delegate MostrarDados]; } - (void)maisUmaGata { girl++; - + [delegate MostrarDados]; } -(int)getBoys { diff --git a/ContaPessoas/FirstViewController.h b/ContaPessoas/FirstViewController.h index abbc105..76033ee 100644 --- a/ContaPessoas/FirstViewController.h +++ b/ContaPessoas/FirstViewController.h @@ -9,9 +9,17 @@ #import @interface FirstViewController : UIViewController + + + + +-(void) MeuDelegate:(FirstViewController *)firstViewController; - (IBAction)clickBoy:(id)sender; - (IBAction)clickGirl:(id)sender; + + @end + diff --git a/ContaPessoas/FirstViewController.m b/ContaPessoas/FirstViewController.m index 3342c34..af6a0d6 100644 --- a/ContaPessoas/FirstViewController.m +++ b/ContaPessoas/FirstViewController.m @@ -22,9 +22,11 @@ - (void)viewDidLoad { contador=[Contador Singleton]; - - // Do any additional setup after loading the view, typically from a nib. } + + + + - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; @@ -42,4 +44,7 @@ - (IBAction)clickGirl:(id)sender { NSLog(@"Meninas - %i",[contador getGirls]); } + + + @end diff --git a/ContaPessoas/SecondViewController.h b/ContaPessoas/SecondViewController.h index 3715345..e52bc9d 100644 --- a/ContaPessoas/SecondViewController.h +++ b/ContaPessoas/SecondViewController.h @@ -6,9 +6,9 @@ // Copyright (c) 2015 Hugo Luiz Chimello. All rights reserved. // #import +#import "Contador.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; diff --git a/ContaPessoas/SecondViewController.m b/ContaPessoas/SecondViewController.m index 1493213..864d462 100644 --- a/ContaPessoas/SecondViewController.m +++ b/ContaPessoas/SecondViewController.m @@ -20,6 +20,16 @@ @implementation SecondViewController - (void)viewDidLoad { [super viewDidLoad]; contador= [Contador Singleton]; + [self click:self]; + contador.delegate = self; + + +} + +-(void)MostrarDados{ + _totalBoys.text = [NSString stringWithFormat: @"%d", [contador getBoys]]; + _totalGirls.text = [NSString stringWithFormat: @"%d", [contador getGirls]]; + _total.text = [NSString stringWithFormat:@"%d", [contador getTotal] ]; }