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
26 changes: 13 additions & 13 deletions ContaPessoas/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,30 @@
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" misplaced="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="hYm-mB-gId">
<rect key="frame" x="167" y="75" width="128" height="224"/>
<button opaque="NO" contentMode="scaleToFill" misplaced="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="jQx-1Z-n65">
<rect key="frame" x="325" y="81" width="111" height="211"/>
<constraints>
<constraint firstAttribute="height" constant="300" id="GJ8-PI-wpB"/>
<constraint firstAttribute="width" constant="150" id="wRK-D8-fAn"/>
<constraint firstAttribute="width" constant="300" id="D13-p5-bzh"/>
<constraint firstAttribute="height" constant="150" id="Q06-7B-no7"/>
</constraints>
<state key="normal" image="boy.png">
<state key="normal" title="Button" image="girl.png">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="clickBoy:" destination="9pv-A4-QxB" eventType="touchDown" id="QWF-hu-z2B"/>
<action selector="clickGirl:" destination="9pv-A4-QxB" eventType="touchDown" id="7bZ-J4-gek"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" misplaced="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="jQx-1Z-n65">
<rect key="frame" x="298" y="81" width="111" height="211"/>
<button opaque="NO" contentMode="scaleToFill" misplaced="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="hYm-mB-gId">
<rect key="frame" x="150" y="75" width="128" height="224"/>
<constraints>
<constraint firstAttribute="width" constant="300" id="D13-p5-bzh"/>
<constraint firstAttribute="height" constant="150" id="Q06-7B-no7"/>
<constraint firstAttribute="height" constant="300" id="GJ8-PI-wpB"/>
<constraint firstAttribute="width" constant="150" id="wRK-D8-fAn"/>
</constraints>
<state key="normal" title="Button" image="girl.png">
<state key="normal" image="boy.png">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="clickGirl:" destination="9pv-A4-QxB" eventType="touchDown" id="7bZ-J4-gek"/>
<action selector="clickBoy:" destination="9pv-A4-QxB" eventType="touchDown" id="QWF-hu-z2B"/>
</connections>
</button>
</subviews>
Expand All @@ -67,7 +67,7 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="W5J-7L-Pyd" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="750" y="-320"/>
<point key="canvasLocation" x="742" y="-376"/>
</scene>
<!--Second-->
<scene sceneID="wg7-f3-ORb">
Expand Down
10 changes: 9 additions & 1 deletion ContaPessoas/Contador.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,21 @@
// Copyright (c) 2015 Vinicius Miana. All rights reserved.
//

@protocol Mostrador <NSObject>
@required
-(void)atualiza;
@end

@interface Contador : NSObject

@property (nonatomic,weak)id mostrar;

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

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

-(int)getTotal;
+(id)getInstance;
@end

17 changes: 15 additions & 2 deletions ContaPessoas/Contador.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,29 @@


@implementation Contador {

int boy;
int girl;
}
static Contador *contador = nil;

-(id)init {
self = [super init];
if (self) {
if (self == nil) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Para que esta comparacao?

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 inverteu a logica. Isto esta errado!

boy = 0;
girl = 0;

}
return self;
}

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

-(int)getBoys {
Expand All @@ -38,7 +43,15 @@ -(int)getBoys {
-(int)getGirls {
return girl;
}

-(int)getTotal{
return boy + girl;
}
+(id)getInstance{
if (contador == nil) {
contador = [[Contador alloc]init];
}
return contador;
}


@end
Expand Down
3 changes: 2 additions & 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 getInstance];
// Do any additional setup after loading the view, typically from a nib.
}

Expand All @@ -39,3 +39,4 @@ - (IBAction)clickGirl:(id)sender {
}

@end
//rip in peace
3 changes: 2 additions & 1 deletion ContaPessoas/SecondViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
//

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

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

@property (weak, nonatomic) IBOutlet UILabel *totalBoys;
@property (weak, nonatomic) IBOutlet UILabel *totalGirls;
Expand Down
23 changes: 14 additions & 9 deletions ContaPessoas/SecondViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,35 @@
#import "Contador.h"

@interface SecondViewController () {
Contador *contador;
}

@end

@implementation SecondViewController
@implementation SecondViewController{
Contador* contador;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Porque mudou a declaração para cá?

}


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

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


@end
1 change: 1 addition & 0 deletions 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 getTotal] == 1), @"Pass");
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

E o teste do total nas meninas? E o caso que tenha um menino e uma menina?

}

- (void)testContaMeninas {
Expand Down