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
2 changes: 2 additions & 0 deletions ContaPessoas.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@
27A199C81A94B2A8008DC684 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
27A199C91A94B2A8008DC684 /* Build configuration list for PBXNativeTarget "ContaPessoasTests" */ = {
isa = XCConfigurationList;
Expand All @@ -446,6 +447,7 @@
27A199CB1A94B2A8008DC684 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
Expand Down
17 changes: 16 additions & 1 deletion ContaPessoas/Contador.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,28 @@
// Copyright (c) 2015 Vinicius Miana. All rights reserved.
//

@interface Contador : NSObject
@protocol MostradorDelegate
@required
-(void)mostraDados;

@end

@interface Contador : NSObject
{
}

@property (retain) id<MostradorDelegate> delegate;

- (void) setDelegate:(id)newDelegate;

+(Contador *)instancia;

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

-(int)getBoys;
-(int)getGirls;
-(int)getTotal;

@end

20 changes: 20 additions & 0 deletions ContaPessoas/Contador.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,37 @@ @implementation Contador {
int girl;
}

@synthesize delegate;

- (void) setDelegate:(id)newDelegate{
delegate = newDelegate;
}

static Contador *_instancia;

-(id)init {
self = [super init];
if (self) {
boy = 0;
girl = 0;

}
return self;
}

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

- (void)maisUmCueca {
boy = boy + 1;
[delegate mostraDados];
}
- (void)maisUmaGata {
girl++;
[delegate mostraDados];
}

-(int)getBoys {
Expand All @@ -39,6 +56,9 @@ -(int)getGirls {
return girl;
}

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


@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
3 changes: 2 additions & 1 deletion ContaPessoas/SecondViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
//

#import <UIKit/UIKit.h>
#include "Contador.h"

@interface SecondViewController : UIViewController
@interface SecondViewController : UIViewController <MostradorDelegate>

@property (weak, nonatomic) IBOutlet UILabel *totalBoys;
@property (weak, nonatomic) IBOutlet UILabel *totalGirls;
Expand Down
13 changes: 10 additions & 3 deletions ContaPessoas/SecondViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//

#import "SecondViewController.h"
#import "Contador.h"

@interface SecondViewController () {
Contador *contador;
Expand All @@ -17,13 +16,21 @@ @interface SecondViewController () {

@implementation SecondViewController

-(void)mostraDados{
_totalBoys.text = [NSString stringWithFormat: @"%d", [contador getBoys]];
_totalGirls.text = [NSString stringWithFormat: @"%d", [contador getGirls]];
_total.text = [NSString stringWithFormat: @"%d", [contador getTotal]];
}

- (void)viewDidLoad {
[super viewDidLoad];
contador = [[Contador alloc] init];
contador = [Contador instancia];
[self click:self];
[contador setDelegate:self];

}



- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
Expand Down
14 changes: 14 additions & 0 deletions ContaPessoasTests/ContaPessoasTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,27 @@ - (void)testContaMeninos {
Contador *c = [[Contador alloc] init];
[c maisUmCueca];
XCTAssert(([c getBoys] == 1), @"Pass");
XCTAssert(([c getGirls] == 0), @"Pass");
XCTAssert(([c getTotal] == 1), @"Pass");
}

- (void)testContaMeninas {
Contador *c = [[Contador alloc] init];
[c maisUmaGata];
XCTAssert(([c getGirls] == 1), @"Pass");
XCTAssert(([c getBoys] == 0), @"Pass");
XCTAssert(([c getTotal] == 1), @"Pass");
}

- (void)testContaTotal {
Contador *c = [[Contador alloc] init];
[c maisUmaGata];
[c maisUmCueca];
[c maisUmaGata];
[c maisUmCueca];
XCTAssert(([c getGirls] == 2), @"Pass");
XCTAssert(([c getBoys] == 2), @"Pass");
XCTAssert(([c getTotal] == 4), @"Pass");
}


Expand Down