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
16 changes: 14 additions & 2 deletions ContaPessoas/Contador.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,25 @@
// Copyright (c) 2015 Vinicius Miana. All rights reserved.
//

@interface Contador : NSObject
@protocol ContadorDelegate <NSObject>

@required
-(void)atualizaDados;

@end

@interface Contador : NSObject {
id <ContadorDelegate> delegate;
}

@property(nonatomic, retain) id <ContadorDelegate> delegate;

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

+(Contador *) instancia;
-(int)getBoys;
-(int)getGirls;

-(int)getTotal;
@end

19 changes: 18 additions & 1 deletion ContaPessoas/Contador.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,26 @@
#import <Foundation/Foundation.h>
#import "Contador.h"


@implementation Contador {
int boy;
int girl;
}

@synthesize delegate;

static Contador *_contador = nil;

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

-(id)init {
self = [super init];
if (self) {
delegate = nil;
boy = 0;
girl = 0;
}
Expand All @@ -26,9 +37,11 @@ -(id)init {

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

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

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



@end
Expand Down
4 changes: 2 additions & 2 deletions ContaPessoas/FirstViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// FirstViewController.h
// ContaPessoas
//
// Created by Vinicius Miana on 2/18/15.
// Copyright (c) 2015 Vinicius Miana. All rights reserved.
// Created by Lucas Lea Mendonça on 2/18/15.
// Copyright (c) 2015 Lucas Leal Mendonça. All rights reserved.
//

#import <UIKit/UIKit.h>
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
4 changes: 3 additions & 1 deletion ContaPessoas/SecondViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
//

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

@interface SecondViewController : UIViewController
@interface SecondViewController : UIViewController <ContadorDelegate>

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

@end

34 changes: 31 additions & 3 deletions ContaPessoas/SecondViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
// Copyright (c) 2015 Vinicius Miana. All rights reserved.
//

/*Fazer:

-> Singleton
-> getTotal
-> teste
-> delegate C (observer)
*/

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

Expand All @@ -17,22 +25,42 @@ @interface SecondViewController () {

@implementation SecondViewController

//-(id)init {
// self = [super init];
// if (self) {
// contador = [Contador instancia];
// contador.delegate = self;
// }
// return self;
//}

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


//- (void)viewDidAppear:(BOOL)animated{
// [self click:self];//Gambiarra. Please Understand
//}

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

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

- (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
16 changes: 16 additions & 0 deletions ContaPessoasTests/ContaPessoasTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,29 @@ - (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 maisUmCueca];
XCTAssert(([c getGirls] == 1), @"Pass");
XCTAssert(([c getBoys] == 2), @"Pass");
XCTAssert(([c getTotal] == 3), @"Pass");

}


Expand Down