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 a4e16ef..4b65c2d 100644 --- a/ContaPessoas/AppDelegate.h +++ b/ContaPessoas/AppDelegate.h @@ -1,9 +1,9 @@ // -// AppDelegate.h +// FirstViewController.m // ContaPessoas // -// Created by Vinicius Miana on 2/18/15. -// Copyright (c) 2015 Vinicius Miana. All rights reserved. +// 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 2f0670a..3911fa1 100644 --- a/ContaPessoas/AppDelegate.m +++ b/ContaPessoas/AppDelegate.m @@ -1,11 +1,10 @@ // -// AppDelegate.m +// FirstViewController.m // ContaPessoas // -// Created by Vinicius Miana on 2/18/15. -// Copyright (c) 2015 Vinicius Miana. All rights reserved. +// 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 18b7c16..625eb88 100644 --- a/ContaPessoas/Contador.h +++ b/ContaPessoas/Contador.h @@ -1,18 +1,30 @@ // -// Contador.h +// FirstViewController.m // ContaPessoas // -// Created by Vinicius Miana on 2/18/15. -// Copyright (c) 2015 Vinicius Miana. All rights reserved. +// 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 - (void)maisUmCueca; - (void)maisUmaGata; - +//total de meninos/meninas -(int)getBoys; -(int)getGirls; +-(int)getTotal; + + +@property (nonatomic,weak) id delegate; @end diff --git a/ContaPessoas/Contador.m b/ContaPessoas/Contador.m index fa64ad8..39070da 100644 --- a/ContaPessoas/Contador.m +++ b/ContaPessoas/Contador.m @@ -1,9 +1,9 @@ // -// Contador.m +// FirstViewController.m // ContaPessoas // -// Created by Vinicius Miana on 2/18/15. -// Copyright (c) 2015 Vinicius Miana. All rights reserved. +// Created by Hugo Luiz Chimello at 19/02/2015 +// Copyright (c) 2015 Hugo Luiz Chimello. All rights reserved. // #import @@ -13,22 +13,44 @@ @implementation Contador { int boy; 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]; 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++; + [delegate MostrarDados]; } - (void)maisUmaGata { girl++; + [delegate MostrarDados]; } -(int)getBoys { diff --git a/ContaPessoas/FirstViewController.h b/ContaPessoas/FirstViewController.h index 59c8301..76033ee 100644 --- a/ContaPessoas/FirstViewController.h +++ b/ContaPessoas/FirstViewController.h @@ -1,17 +1,25 @@ // -// FirstViewController.h +// FirstViewController.m // ContaPessoas // -// Created by Vinicius Miana on 2/18/15. -// Copyright (c) 2015 Vinicius Miana. All rights reserved. +// Created by Hugo Luiz Chimello at 19/02/2015 +// Copyright (c) 2015 Hugo Luiz Chimello. All rights reserved. // #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 fc70dd5..af6a0d6 100644 --- a/ContaPessoas/FirstViewController.m +++ b/ContaPessoas/FirstViewController.m @@ -2,8 +2,8 @@ // FirstViewController.m // ContaPessoas // -// Created by Vinicius Miana on 2/18/15. -// Copyright (c) 2015 Vinicius Miana. All rights reserved. +// Created by Hugo Luiz Chimello at 19/02/2015 +// Copyright (c) 2015 Hugo Luiz Chimello. All rights reserved. // #import "FirstViewController.h" @@ -19,9 +19,14 @@ @implementation FirstViewController { - (void)viewDidLoad { [super viewDidLoad]; - contador = [[Contador alloc] init]; - // Do any additional setup after loading the view, typically from a nib. + + contador=[Contador Singleton]; + } + + + + - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; @@ -31,6 +36,7 @@ - (void)didReceiveMemoryWarning { - (IBAction)clickBoy:(id)sender { [contador maisUmCueca]; NSLog(@"Meninos - %i",[contador getBoys]); + NSLog(@"total - %i", [contador getTotal]); } - (IBAction)clickGirl:(id)sender { @@ -38,4 +44,7 @@ - (IBAction)clickGirl:(id)sender { NSLog(@"Meninas - %i",[contador getGirls]); } + + + @end diff --git a/ContaPessoas/SecondViewController.h b/ContaPessoas/SecondViewController.h index f907831..e52bc9d 100644 --- a/ContaPessoas/SecondViewController.h +++ b/ContaPessoas/SecondViewController.h @@ -1,15 +1,14 @@ // -// SecondViewController.h +// FirstViewController.m // ContaPessoas // -// Created by Vinicius Miana on 2/18/15. -// Copyright (c) 2015 Vinicius Miana. All rights reserved. +// Created by Hugo Luiz Chimello at 19/02/2015 +// 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 a2a66f5..864d462 100644 --- a/ContaPessoas/SecondViewController.m +++ b/ContaPessoas/SecondViewController.m @@ -1,9 +1,9 @@ // -// SecondViewController.m +// FirstViewController.m // ContaPessoas // -// Created by Vinicius Miana on 2/18/15. -// Copyright (c) 2015 Vinicius Miana. All rights reserved. +// Created by Hugo Luiz Chimello at 19/02/2015 +// Copyright (c) 2015 Hugo Luiz Chimello. All rights reserved. // #import "SecondViewController.h" @@ -19,7 +19,17 @@ @implementation SecondViewController - (void)viewDidLoad { [super viewDidLoad]; - contador = [[Contador alloc] init]; + 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] ]; } @@ -28,11 +38,11 @@ - (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]]; - _total.text = [NSString stringWithFormat:@"%d", [contador getGirls] + [contador getBoys] ]; + _total.text = [NSString stringWithFormat:@"%d", [contador getTotal] ]; } diff --git a/ContaPessoasTests/ContaPessoasTests.m b/ContaPessoasTests/ContaPessoasTests.m index 579bb3f..67ae74c 100644 --- a/ContaPessoasTests/ContaPessoasTests.m +++ b/ContaPessoasTests/ContaPessoasTests.m @@ -1,9 +1,9 @@ // -// ContaPessoasTests.m -// ContaPessoasTests +// FirstViewController.m +// ContaPessoas // -// Created by Vinicius Miana on 2/18/15. -// Copyright (c) 2015 Vinicius Miana. All rights reserved. +// Created by Hugo Luiz Chimello at 19/02/2015 +// Copyright (c) 2015 Hugo Luiz Chimello. All rights reserved. // #import @@ -21,6 +21,8 @@ - (void)testContaMeninos { Contador *c = [[Contador alloc] init]; [c maisUmCueca]; XCTAssert(([c getBoys] == 1), @"Pass"); + XCTAssert(([c getGirls] == 0), @"Pass"); + } - (void)testContaMeninas { @@ -28,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 67c06ac..3e18545 100644 --- a/ContaPessoasTests/ContadorTests.m +++ b/ContaPessoasTests/ContadorTests.m @@ -1,9 +1,9 @@ // -// ContadorTests.m +// FirstViewController.m // ContaPessoas // -// Created by Vinicius Miana on 2/18/15. -// Copyright (c) 2015 Vinicius Miana. All rights reserved. +// Created by Hugo Luiz Chimello at 19/02/2015 +// Copyright (c) 2015 Hugo Luiz Chimello. All rights reserved. // #import