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
64 changes: 30 additions & 34 deletions ContaPessoas/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6254" systemVersion="14C109" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="49e-Tb-3d3">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6247"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
</dependencies>
<scenes>
<!--First-->
Expand All @@ -13,21 +14,14 @@
<viewControllerLayoutGuide type="bottom" id="4ug-Mw-9AY"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="tsR-hK-woN">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleToFill" misplaced="YES" text="Contador" textAlignment="center" lineBreakMode="tailTruncation" minimumFontSize="10" translatesAutoresizingMaskIntoConstraints="NO" id="KQZ-1w-vlD">
<rect key="frame" x="222" y="25" width="157.5" height="41.5"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<fontDescription key="fontDescription" name="Helvetica" family="Helvetica" pointSize="36"/>
<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" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="hYm-mB-gId">
<rect key="frame" x="26" y="172" width="128" height="224"/>
<constraints>
<constraint firstAttribute="height" constant="300" id="GJ8-PI-wpB"/>
<constraint firstAttribute="width" constant="150" id="wRK-D8-fAn"/>
<constraint firstAttribute="height" constant="224" id="kS8-KS-qN5"/>
<constraint firstAttribute="width" constant="128" id="xJ6-jt-nBQ"/>
</constraints>
<state key="normal" image="boy.png">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
Expand All @@ -36,11 +30,11 @@
<action selector="clickBoy:" destination="9pv-A4-QxB" eventType="touchDown" id="QWF-hu-z2B"/>
</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" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="jQx-1Z-n65">
<rect key="frame" x="183" y="179" width="111" height="211"/>
<constraints>
<constraint firstAttribute="width" constant="300" id="D13-p5-bzh"/>
<constraint firstAttribute="height" constant="150" id="Q06-7B-no7"/>
<constraint firstAttribute="width" constant="111" id="YfB-5T-3fJ"/>
<constraint firstAttribute="height" constant="211" id="dWA-cZ-B8e"/>
</constraints>
<state key="normal" title="Button" image="girl.png">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
Expand All @@ -49,21 +43,32 @@
<action selector="clickGirl:" destination="9pv-A4-QxB" eventType="touchDown" id="7bZ-J4-gek"/>
</connections>
</button>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleToFill" text="Contador" textAlignment="center" lineBreakMode="tailTruncation" minimumFontSize="10" translatesAutoresizingMaskIntoConstraints="NO" id="KQZ-1w-vlD">
<rect key="frame" x="81" y="48" width="157.5" height="41.5"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="height" constant="41.5" id="PAg-Rd-LKD"/>
<constraint firstAttribute="width" constant="157.5" id="uwe-Mk-vaL"/>
</constraints>
<fontDescription key="fontDescription" name="Helvetica" family="Helvetica" pointSize="36"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="centerY" secondItem="hYm-mB-gId" secondAttribute="centerY" constant="113" id="25f-oe-XWF"/>
<constraint firstAttribute="centerX" secondItem="KQZ-1w-vlD" secondAttribute="centerX" id="6BV-lF-sBN"/>
<constraint firstAttribute="centerY" secondItem="KQZ-1w-vlD" secondAttribute="centerY" constant="254.25" id="7NO-DY-fvY"/>
<constraint firstAttribute="centerX" secondItem="hYm-mB-gId" secondAttribute="centerX" constant="105" id="BIr-Ng-iZd"/>
<constraint firstAttribute="centerX" secondItem="jQx-1Z-n65" secondAttribute="centerX" constant="-53.5" id="HvV-q8-w7n"/>
<constraint firstItem="jQx-1Z-n65" firstAttribute="width" secondItem="hYm-mB-gId" secondAttribute="width" id="QXq-FV-L3B"/>
<constraint firstItem="jQx-1Z-n65" firstAttribute="top" secondItem="hYm-mB-gId" secondAttribute="top" constant="31" id="Sxc-Z0-BuJ"/>
<constraint firstItem="jQx-1Z-n65" firstAttribute="height" secondItem="hYm-mB-gId" secondAttribute="height" id="eqk-7z-cvb"/>
<constraint firstAttribute="top" secondItem="KQZ-1w-vlD" secondAttribute="top" id="exm-UA-ej4"/>
<constraint firstItem="hYm-mB-gId" firstAttribute="leading" secondItem="tsR-hK-woN" secondAttribute="leadingMargin" constant="10" id="2hJ-ZM-bN0"/>
<constraint firstItem="hYm-mB-gId" firstAttribute="leading" secondItem="tsR-hK-woN" secondAttribute="leadingMargin" constant="10" id="3O9-Ix-2is"/>
<constraint firstAttribute="trailingMargin" secondItem="jQx-1Z-n65" secondAttribute="trailing" constant="10" id="9xL-C4-bzE"/>
<constraint firstAttribute="centerY" secondItem="jQx-1Z-n65" secondAttribute="centerY" id="Kfv-wa-9Gr"/>
<constraint firstAttribute="centerX" secondItem="KQZ-1w-vlD" secondAttribute="centerX" id="bEg-IP-0hx"/>
<constraint firstAttribute="trailingMargin" secondItem="jQx-1Z-n65" secondAttribute="trailing" constant="10" id="cU6-VX-gUl"/>
<constraint firstAttribute="centerY" secondItem="hYm-mB-gId" secondAttribute="centerY" id="eBm-DH-umT"/>
<constraint firstItem="KQZ-1w-vlD" firstAttribute="top" secondItem="Ia1-K6-d13" secondAttribute="bottom" constant="28" id="pHD-md-piT"/>
</constraints>
</view>
<tabBarItem key="tabBarItem" title="First" image="first" id="acW-dT-cKf"/>
<simulatedScreenMetrics key="simulatedDestinationMetrics" type="retina4"/>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="W5J-7L-Pyd" sceneMemberID="firstResponder"/>
</objects>
Expand Down Expand Up @@ -123,15 +128,6 @@
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Wdw-cL-Bgf">
<rect key="frame" x="299" y="406" width="54" height="30"/>
<state key="normal" title="Atualiza">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="click:" destination="8rJ-Kc-sve" eventType="touchUpInside" id="Wmf-Ss-Ora"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<constraints>
Expand Down
6 changes: 6 additions & 0 deletions ContaPessoas/Contador.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@

@interface Contador : NSObject

+ (Contador *) contGlobal;

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

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

-(int)getTotal;

@property (nonatomic, weak) id mostrar;

@end

16 changes: 16 additions & 0 deletions ContaPessoas/Contador.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,23 @@

#import <Foundation/Foundation.h>
#import "Contador.h"
#import "SecondViewController.h"


@implementation Contador {
int boy;
int girl;
}

+ (Contador *)contGlobal{
static Contador *contGlobal = nil;

if (!contGlobal){
contGlobal = [[Contador alloc] init];
}
return contGlobal;
}

-(id)init {
self = [super init];
if (self) {
Expand All @@ -26,9 +36,11 @@ -(id)init {

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

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

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



@end
Expand Down
5 changes: 4 additions & 1 deletion ContaPessoas/FirstViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
//

#import <UIKit/UIKit.h>
@class Contador;

@interface FirstViewController : UIViewController
@interface FirstViewController : UIViewController{
Contador *contador;
}

- (IBAction)clickBoy:(id)sender;
- (IBAction)clickGirl:(id)sender;
Expand Down
14 changes: 8 additions & 6 deletions ContaPessoas/FirstViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,26 @@
// FirstViewController.m
// ContaPessoas
//
// Created by Vinicius Miana on 2/18/15.
// Copyright (c) 2015 Vinicius Miana. All rights reserved.
// Created by Lidia Chou on 2/18/15.
// Copyright (c) 2015 Lidia Chou. All rights reserved.
//
//
//

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

@interface FirstViewController ()

@end

@implementation FirstViewController {
Contador *contador;
}
@implementation FirstViewController


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

Expand Down
8 changes: 6 additions & 2 deletions ContaPessoas/SecondViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@
//

#import <UIKit/UIKit.h>
@class Contador;

@interface SecondViewController : UIViewController
@interface SecondViewController : UIViewController{
Contador *contador;
}

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

-(void)atualiza;

@end

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

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

@interface SecondViewController ()

@interface SecondViewController () {
Contador *contador;
}

@end

@implementation SecondViewController

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


Expand All @@ -29,10 +31,10 @@ - (void)didReceiveMemoryWarning {
// Dispose of any resources that can be recreated.
}

- (IBAction)click:(id)sender {
- (void)atualiza {
_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
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 getGirls] == 0), @"Pass");
}

- (void)testContaMeninas {
Expand Down