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
6 changes: 3 additions & 3 deletions ContaPessoas/AppDelegate.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//
// AppDelegate.h
// FirstViewController.m
// ContaPessoas
//
// Created by Vinicius Miana on 2/18/15.
// Copyright (c) 2015 Vinicius Miana. All rights reserved.
// Created by Hugo Luiz Chimello at 19/02/2015
// Copyright (c) 2015 Hugo Luiz Chimello. All rights reserved.
//

#import <UIKit/UIKit.h>
Expand Down
7 changes: 3 additions & 4 deletions ContaPessoas/AppDelegate.m
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
//
// AppDelegate.m
// FirstViewController.m
// ContaPessoas
//
// Created by Vinicius Miana on 2/18/15.
// Copyright (c) 2015 Vinicius Miana. All rights reserved.
// Created by Hugo Luiz Chimello at 19/02/2015
// Copyright (c) 2015 Hugo Luiz Chimello. All rights reserved.
//

#import "AppDelegate.h"

@interface AppDelegate ()
Expand Down
22 changes: 17 additions & 5 deletions ContaPessoas/Contador.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
//
// Contador.h
// FirstViewController.m
// ContaPessoas
//
// Created by Vinicius Miana on 2/18/15.
// Copyright (c) 2015 Vinicius Miana. All rights reserved.
// Created by Hugo Luiz Chimello at 19/02/2015
// Copyright (c) 2015 Hugo Luiz Chimello. All rights reserved.
//
@protocol HugoDelegate
@required
-(void)MostrarDados;

@interface Contador : NSObject
@end
@interface Contador : NSObject{

}
//tentativa de singleton
+(instancetype)Singleton;
//contador
- (void)maisUmCueca;
- (void)maisUmaGata;

//total de meninos/meninas
-(int)getBoys;
-(int)getGirls;
-(int)getTotal;


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

@end

30 changes: 26 additions & 4 deletions ContaPessoas/Contador.m
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//
// Contador.m
// FirstViewController.m
// ContaPessoas
//
// Created by Vinicius Miana on 2/18/15.
// Copyright (c) 2015 Vinicius Miana. All rights reserved.
// Created by Hugo Luiz Chimello at 19/02/2015
// Copyright (c) 2015 Hugo Luiz Chimello. All rights reserved.
//

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

}
@synthesize delegate;
//variavel global, fora das chaves
static Contador *singleInstance=nil;



//Com variavel total(memoria x processamento) soma
-(id)init {
self = [super init];
if (self) {
boy = 0;
girl = 0;

}
return self;
}
-(int)getTotal{
return girl+boy;
}
//colocar +(public) para as classes first and second, poderem ter acesso
+(instancetype)Singleton{

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

return singleInstance;
}

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

-(int)getBoys {
Expand Down
14 changes: 11 additions & 3 deletions ContaPessoas/FirstViewController.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
//
// FirstViewController.h
// FirstViewController.m
// ContaPessoas
//
// Created by Vinicius Miana on 2/18/15.
// Copyright (c) 2015 Vinicius Miana. All rights reserved.
// Created by Hugo Luiz Chimello at 19/02/2015
// Copyright (c) 2015 Hugo Luiz Chimello. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface FirstViewController : UIViewController




-(void) MeuDelegate:(FirstViewController *)firstViewController;

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



@end


17 changes: 13 additions & 4 deletions ContaPessoas/FirstViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// FirstViewController.m
// ContaPessoas
//
// Created by Vinicius Miana on 2/18/15.
// Copyright (c) 2015 Vinicius Miana. All rights reserved.
// Created by Hugo Luiz Chimello at 19/02/2015
// Copyright (c) 2015 Hugo Luiz Chimello. All rights reserved.
//

#import "FirstViewController.h"
Expand All @@ -19,9 +19,14 @@ @implementation FirstViewController {

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

contador=[Contador Singleton];

}





- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
Expand All @@ -31,11 +36,15 @@ - (void)didReceiveMemoryWarning {
- (IBAction)clickBoy:(id)sender {
[contador maisUmCueca];
NSLog(@"Meninos - %i",[contador getBoys]);
NSLog(@"total - %i", [contador getTotal]);
}

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




@end
11 changes: 5 additions & 6 deletions ContaPessoas/SecondViewController.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
//
// SecondViewController.h
// FirstViewController.m
// ContaPessoas
//
// Created by Vinicius Miana on 2/18/15.
// Copyright (c) 2015 Vinicius Miana. All rights reserved.
// Created by Hugo Luiz Chimello at 19/02/2015
// Copyright (c) 2015 Hugo Luiz Chimello. All rights reserved.
//

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

@interface SecondViewController : UIViewController

@interface SecondViewController : UIViewController <HugoDelegate>
@property (weak, nonatomic) IBOutlet UILabel *totalBoys;
@property (weak, nonatomic) IBOutlet UILabel *totalGirls;
@property (weak, nonatomic) IBOutlet UILabel *total;
Expand Down
22 changes: 16 additions & 6 deletions ContaPessoas/SecondViewController.m
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//
// SecondViewController.m
// FirstViewController.m
// ContaPessoas
//
// Created by Vinicius Miana on 2/18/15.
// Copyright (c) 2015 Vinicius Miana. All rights reserved.
// Created by Hugo Luiz Chimello at 19/02/2015
// Copyright (c) 2015 Hugo Luiz Chimello. All rights reserved.
//

#import "SecondViewController.h"
Expand All @@ -19,7 +19,17 @@ @implementation SecondViewController

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


}

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


Expand All @@ -28,11 +38,11 @@ - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

//criar classe getTotal(contador)
- (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
20 changes: 16 additions & 4 deletions ContaPessoasTests/ContaPessoasTests.m
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//
// ContaPessoasTests.m
// ContaPessoasTests
// FirstViewController.m
// ContaPessoas
//
// Created by Vinicius Miana on 2/18/15.
// Copyright (c) 2015 Vinicius Miana. All rights reserved.
// Created by Hugo Luiz Chimello at 19/02/2015
// Copyright (c) 2015 Hugo Luiz Chimello. All rights reserved.
//

#import <UIKit/UIKit.h>
Expand All @@ -21,13 +21,25 @@ - (void)testContaMeninos {
Contador *c = [[Contador alloc] init];
[c maisUmCueca];
XCTAssert(([c getBoys] == 1), @"Pass");
XCTAssert(([c getGirls] == 0), @"Pass");

}

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

}

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


Expand Down
6 changes: 3 additions & 3 deletions ContaPessoasTests/ContadorTests.m
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//
// ContadorTests.m
// FirstViewController.m
// ContaPessoas
//
// Created by Vinicius Miana on 2/18/15.
// Copyright (c) 2015 Vinicius Miana. All rights reserved.
// Created by Hugo Luiz Chimello at 19/02/2015
// Copyright (c) 2015 Hugo Luiz Chimello. All rights reserved.
//

#import <UIKit/UIKit.h>
Expand Down