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
13 changes: 12 additions & 1 deletion ContaPessoas/Contador.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,25 @@
// Created by Vinicius Miana on 2/18/15.
// Copyright (c) 2015 Vinicius Miana. All rights reserved.
//
#import <Foundation/Foundation.h>


@protocol Mostrador <NSObject>

-(void) atualiza;

@end

@interface Contador : NSObject

+ (Contador *) contador;
- (void)maisUmCueca;
- (void)maisUmaGata;

@property (nonatomic,weak) id <Mostrador> delegate;

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

-(int)getTotal;
@end

16 changes: 16 additions & 0 deletions ContaPessoas/Contador.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ -(id)init {

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

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

static Contador *contador = nil;

+ (Contador *) contador {

if (contador == nil) {
contador = [[Contador alloc]init];
}
return contador;
}

-(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 contador];
// Do any additional setup after loading the view, typically from a nib.
}

Expand Down
7 changes: 4 additions & 3 deletions ContaPessoas/SecondViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
// Created by Vinicius Miana on 2/18/15.
// Copyright (c) 2015 Vinicius Miana. All rights reserved.
//

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

@interface SecondViewController : UIViewController
@interface SecondViewController : UIViewController <Mostrador>

@property (weak, nonatomic) IBOutlet UILabel *totalBoys;
@property (weak, nonatomic) IBOutlet UILabel *totalGirls;
@property (weak, nonatomic) IBOutlet UILabel *total;
- (IBAction)click:(id)sender;
- (IBAction)click:(id)sender; // oi?
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

belo oi

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oi

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Olá

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

potq?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bacana

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oizinhoooo !!!

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oi, tudo bem?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oiee

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

//tchau

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tire o oi


Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comentario na linha do codigo...!


@end

15 changes: 13 additions & 2 deletions ContaPessoas/SecondViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,31 @@ @implementation SecondViewController

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

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


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

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

@end