Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion ContaPessoas/Contador.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
// Copyright (c) 2015 Vinicius Miana. All rights reserved.
//

@interface Contador : NSObject
@interface Contador : NSObject

- (void)maisUmCueca;
- (void)maisUmaGata;

-(int)getBoys;
-(int)getGirls;
-(int)getTotal;
-(id)init;
+(Contador *) instancia;

@end

19 changes: 15 additions & 4 deletions ContaPessoas/Contador.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// Contador.m
// ContaPessoas
//
// Sem comentários
// Created by Vinicius Miana on 2/18/15.
// Copyright (c) 2015 Vinicius Miana. All rights reserved.
//
Expand All @@ -11,12 +11,19 @@


@implementation Contador {
int boy;
int girl;
int boy;
int girl;
}
static Contador *_instancia;

+(Contador *) instancia{
if(_instancia == nil){
_instancia = [[Contador alloc] init];
}
return _instancia;
}

-(id)init {
self = [super init];
if (self) {
boy = 0;
girl = 0;
Expand All @@ -39,6 +46,10 @@ -(int)getGirls {
return girl;
}

-(int)getTotal{
return girl + boy;
}



@end
Expand Down
2 changes: 1 addition & 1 deletion ContaPessoas/FirstViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ @implementation FirstViewController {

- (void)viewDidLoad {
[super viewDidLoad];
contador = [[Contador alloc] init];
contador = [Contador instancia];
// Do any additional setup after loading the view, typically from a nib.
}

Expand Down
7 changes: 5 additions & 2 deletions ContaPessoas/SecondViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ @implementation SecondViewController

- (void)viewDidLoad {
[super viewDidLoad];
contador = [[Contador alloc] init];
contador = [Contador instancia];
}

- (void)viewDidAppear:(BOOL)animated{
[self click:self];
}


- (void)didReceiveMemoryWarning {
Expand All @@ -32,7 +35,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]];
}


Expand Down
8 changes: 8 additions & 0 deletions ContaPessoasTests/ContaPessoasTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -30,5 +31,12 @@ - (void)testContaMeninas {
XCTAssert(([c getBoys] == 0), @"Pass");
}

- (void)testContaTotal{
Contador *c = [[Contador alloc] init];
[c maisUmaGata];
[c maisUmCueca];

XCTAssert(([c getTotal] == 2), @"Pass");
}

@end
1 change: 1 addition & 0 deletions ContaPessoasTests/ContadorTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ - (void)testPerformanceExample {
}];
}


@end