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
1 change: 0 additions & 1 deletion ContaPessoas/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@


@end

371 changes: 181 additions & 190 deletions ContaPessoas/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

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

@protocol Mostrador <NSObject>

@required
-(void)atualiza;

@end

@interface Contador : NSObject

+ (Contador *)getInstance;

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

-(int)getBoys;
-(int)getGirls;
@property (nonatomic, weak) id mostrar;
@property int boy;
@property int girl;

@end

41 changes: 20 additions & 21 deletions ContaPessoas/Contador.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,36 @@
#import <Foundation/Foundation.h>
#import "Contador.h"

@implementation Contador

@implementation Contador {
int boy;
int girl;
#pragma mark Singleton

+ (Contador *)getInstance {
static Contador *contadorCompartilhado = nil;
static dispatch_once_t token;
dispatch_once(&token, ^{
contadorCompartilhado = [[self alloc] init];
});
return contadorCompartilhado;
}

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

#pragma mark Contador

- (void)maisUmCueca {
boy = boy + 1;
_boy = _boy + 1;
[_mostrar atualiza];
}
- (void)maisUmaGata {
girl++;
_girl++;
[_mostrar atualiza];
}

-(int)getBoys {
return boy;
}

-(int)getGirls {
return girl;
}



@end

6 changes: 4 additions & 2 deletions ContaPessoas/FirstViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
//

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

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

- (IBAction)clickBoy:(id)sender;
- (IBAction)clickGirl:(id)sender;

@end

15 changes: 6 additions & 9 deletions ContaPessoas/FirstViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,37 @@
// FirstViewController.m
// ContaPessoas
//
// Created by Vinicius Miana on 2/18/15.
// Created by Eduardo Quadros on 2/18/15.
// Copyright (c) 2015 Vinicius Miana. All rights reserved.
//

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

@interface FirstViewController ()

@end

@implementation FirstViewController {
Contador *contador;
}
@implementation FirstViewController

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

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

- (IBAction)clickBoy:(id)sender {
[contador maisUmCueca];
NSLog(@"Meninos - %i",[contador getBoys]);
NSLog(@"Meninos - %i", contador.boy);
}

- (IBAction)clickGirl:(id)sender {
[contador maisUmaGata];
NSLog(@"Meninas - %i",[contador getGirls]);
NSLog(@"Meninas - %i", contador.girl);
}

@end
9 changes: 6 additions & 3 deletions ContaPessoas/SecondViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
//

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

@interface SecondViewController : UIViewController
@interface SecondViewController : UIViewController {
Contador *contador;
}

@property (weak, nonatomic) IBOutlet UILabel *totalBoys;
@property (weak, nonatomic) IBOutlet UILabel *totalGirls;
@property (weak, nonatomic) IBOutlet UILabel *total;
- (IBAction)click:(id)sender;

@end
- (void)atualiza;

@end
21 changes: 9 additions & 12 deletions ContaPessoas/SecondViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,29 @@

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

@interface SecondViewController () {
Contador *contador;
}
@interface SecondViewController ()

@end

@implementation SecondViewController

- (void)viewDidLoad {
[super viewDidLoad];
contador = [[Contador alloc] init];
contador = [Contador getInstance];
contador.mostrar = self;
[self atualiza];
}



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

- (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] ];
- (void)atualiza {
_totalBoys.text = [NSString stringWithFormat: @"%d", contador.boy];
_totalGirls.text = [NSString stringWithFormat: @"%d", contador.girl];
_total.text = [NSString stringWithFormat:@"%d", (contador.boy + contador.girl)];
}


@end
15 changes: 12 additions & 3 deletions ContaPessoasTests/ContaPessoasTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,24 @@ @implementation ContaPessoasTests
- (void)testContaMeninos {
Contador *c = [[Contador alloc] init];
[c maisUmCueca];
XCTAssert(([c getBoys] == 1), @"Pass");
XCTAssert((c.boy == 1), @"Pass");
}

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

- (void)testContarTodos {
Contador *c = [[Contador alloc] init];
[c maisUmaGata];
[c maisUmaGata];
[c maisUmCueca];
XCTAssert((c.girl == 2), @"Pass");
XCTAssert((c.boy == 1), @"Pass");
XCTAssert((c.girl + c.boy == 3), @"Pass");
}

@end