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
4 changes: 3 additions & 1 deletion ContaPessoas.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@
27A199B31A94B2A8008DC684 /* Images.xcassets */,
27A199B51A94B2A8008DC684 /* LaunchScreen.xib */,
27A199A31A94B2A8008DC684 /* Supporting Files */,
27A199D21A94D1FA008DC684 /* Contador.m */,
27A199D41A94D22B008DC684 /* Contador.h */,
27A199D21A94D1FA008DC684 /* Contador.m */,
);
path = ContaPessoas;
sourceTree = "<group>";
Expand Down 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
102 changes: 44 additions & 58 deletions ContaPessoas/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

16 changes: 15 additions & 1 deletion ContaPessoas/Contador.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,27 @@
// Copyright (c) 2015 Vinicius Miana. All rights reserved.
//

@interface Contador : NSObject
#import <UIKit/UIKit.h>

@protocol AtualizarValores <NSObject>

@required
-(void)AtualizarValores;

@end

@interface Contador : NSObject

@property(nonatomic,assign) id mostrarValores;

+(Contador *)globalContador;

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

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

@end

17 changes: 15 additions & 2 deletions ContaPessoas/Contador.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,21 @@
#import <Foundation/Foundation.h>
#import "Contador.h"


@implementation Contador {
int boy;
int girl;
}

static Contador *globalContador = nil;

+(Contador *)globalContador;
{
if (!globalContador) {
globalContador = [[Contador alloc]init];
}
return globalContador;
}

-(id)init {
self = [super init];
if (self) {
Expand All @@ -26,9 +35,11 @@ -(id)init {

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

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


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

@end

5 changes: 4 additions & 1 deletion ContaPessoas/FirstViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
//

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

@interface FirstViewController : UIViewController
@interface FirstViewController : UIViewController{
Contador *globalContador;
}

- (IBAction)clickBoy:(id)sender;
- (IBAction)clickGirl:(id)sender;
Expand Down
4 changes: 2 additions & 2 deletions ContaPessoas/FirstViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

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

@interface FirstViewController ()

Expand All @@ -19,7 +19,7 @@ @implementation FirstViewController {

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

Expand Down
7 changes: 6 additions & 1 deletion ContaPessoas/SecondViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@
//

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

@interface SecondViewController : UIViewController
@interface SecondViewController : UIViewController<AtualizarValores>
{
Contador *globalContador;
}

@property (weak, nonatomic) IBOutlet UILabel *totalBoys;
@property (weak, nonatomic) IBOutlet UILabel *totalGirls;
@property (weak, nonatomic) IBOutlet UILabel *total;

- (IBAction)click:(id)sender;

@end
Expand Down
23 changes: 13 additions & 10 deletions ContaPessoas/SecondViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,36 @@
//

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

@interface SecondViewController () {
Contador *contador;
}

@end

@implementation SecondViewController

- (void)viewDidLoad {
[super viewDidLoad];
contador = [[Contador alloc] init];
// self.mostrarValores;
[self AtualizarValores];
}



- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

- (IBAction)click:(id)sender {
Contador *contador = [Contador globalContador];

_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]];
}

- (void)AtualizarValores{
Contador *contador = [Contador globalContador];

_totalBoys.text = [NSString stringWithFormat: @"%d", [contador getBoys]];
_totalGirls.text = [NSString stringWithFormat: @"%d", [contador getGirls]];
_total.text = [NSString stringWithFormat:@"%d", [contador getTotal]];
}

@end
15 changes: 11 additions & 4 deletions ContaPessoasTests/ContaPessoasTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ @interface ContaPessoasTests : XCTestCase

@implementation ContaPessoasTests


- (void)testContaMeninos {
Contador *c = [[Contador alloc] init];
[c maisUmCueca];
XCTAssert(([c getBoys] == 1), @"Pass");
Contador *c = [[Contador alloc] init]; // Cria um contatdor e aloca na memória
[c maisUmCueca]; // Cria um método
XCTAssert(([c getBoys] == 1), @"Pass"); //
XCTAssert(([c getGirls] == 0), @"Pass"); //
}

- (void)testContaMeninas {
Expand All @@ -30,5 +30,12 @@ - (void)testContaMeninas {
XCTAssert(([c getBoys] == 0), @"Pass");
}

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

@end