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: 4 additions & 0 deletions ContaPessoas.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
1057223C1A97945C00A01055 /* Mostrador.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Mostrador.h; sourceTree = "<group>"; };
27A199A01A94B2A8008DC684 /* ContaPessoas.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ContaPessoas.app; sourceTree = BUILT_PRODUCTS_DIR; };
27A199A41A94B2A8008DC684 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
27A199A51A94B2A8008DC684 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -107,6 +108,7 @@
27A199A31A94B2A8008DC684 /* Supporting Files */,
27A199D21A94D1FA008DC684 /* Contador.m */,
27A199D41A94D22B008DC684 /* Contador.h */,
1057223C1A97945C00A01055 /* Mostrador.h */,
);
path = ContaPessoas;
sourceTree = "<group>";
Expand Down Expand Up @@ -438,6 +440,7 @@
27A199C81A94B2A8008DC684 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
27A199C91A94B2A8008DC684 /* Build configuration list for PBXNativeTarget "ContaPessoasTests" */ = {
isa = XCConfigurationList;
Expand All @@ -446,6 +449,7 @@
27A199CB1A94B2A8008DC684 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
Expand Down
6 changes: 6 additions & 0 deletions ContaPessoas/Contador.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@
// Copyright (c) 2015 Vinicius Miana. All rights reserved.
//

#import "Mostrador.h"

@interface Contador : NSObject

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

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

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

+(Contador *) instance;
@end

28 changes: 26 additions & 2 deletions ContaPessoas/Contador.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//
// Created by Vinicius Miana on 2/18/15.
// Copyright (c) 2015 Vinicius Miana. All rights reserved.
//
//amanda

#import <Foundation/Foundation.h>
#import "Contador.h"
Expand All @@ -13,22 +13,44 @@
@implementation Contador {
int boy;
int girl;
int total;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Voce nao esta usando o total para nada. Apague ou use...

}

static Contador *_instance = nil;

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

}
return self;
}

+(Contador *)instance{

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

//+(Contador *)instance{
////static Contador *sharedContador = nil;
//static dispatch_once_t onceToken;
//dispatch_once(&onceToken, ˆ
// {
// sharedContador = [[self alloc] init];
// }); return sharedContador;}


- (void)maisUmCueca {
boy = boy + 1;
[_delegate meninos: (boy) meninas: (girl) geral:[self getTotal]];
}

- (void)maisUmaGata {
girl++;
[_delegate meninos: (boy) meninas: (girl) geral:[self getTotal]];
}

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


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

@end

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

Expand Down
22 changes: 22 additions & 0 deletions ContaPessoas/Mostrador.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// Mostrador.h
// ContaPessoas
//
// Created by Amanda Guimaraes Campos on 20/02/15.
// Copyright (c) 2015 Vinicius Miana. All rights reserved.
//

#import <Foundation/Foundation.h>

@protocol Mostrador <NSObject>

//@required


- (void) meninos: (int)b meninas: (int)g geral:(int)t;

//@optional
//-(void)optionalDelegateMethodOne;
//-(void)optionalDelegateMethodTwo:(NSString *)withArgument;

@end
5 changes: 4 additions & 1 deletion ContaPessoas/SecondViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
//

#import <UIKit/UIKit.h>
#import "Mostrador.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;

@end
Expand Down
18 changes: 14 additions & 4 deletions ContaPessoas/SecondViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

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

@interface SecondViewController () {
Contador *contador;
Expand All @@ -19,10 +20,14 @@ @implementation SecondViewController

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


//-(void) viewDidAppear:(BOOL)animated{
//
//}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
Expand All @@ -34,6 +39,11 @@ - (IBAction)click:(id)sender {
_totalGirls.text = [NSString stringWithFormat: @"%d", [contador getGirls]];
_total.text = [NSString stringWithFormat:@"%d", [contador getGirls] + [contador getBoys] ];
}


//delegate
-(void) meninos:(int)b meninas:(int)g geral:(int)t{
NSLog(@"g:%d\ln b:%d\ln t:%d\ln",b,g,t);
_totalBoys.text = [NSString stringWithFormat: @"%d", b];
_totalGirls.text = [NSString stringWithFormat: @"%d",g];
_total.text = [NSString stringWithFormat:@"%d", t];
}
@end
7 changes: 6 additions & 1 deletion ContaPessoasTests/ContaPessoasTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ - (void)testContaMeninos {
Contador *c = [[Contador alloc] init];
[c maisUmCueca];
XCTAssert(([c getBoys] == 1), @"Pass");
XCTAssert(([c getGirls] == 0) , @"Pass");
}

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

- (void)testTotal {
Contador *c = [[Contador alloc] init];
XCTAssert(([c getTotal] == 0), @"Pass");
}

@end
@end