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
8 changes: 8 additions & 0 deletions ContaPessoas.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
27A199D11A94B501008DC684 /* boy.png in Resources */ = {isa = PBXBuildFile; fileRef = 27A199D01A94B501008DC684 /* boy.png */; };
27A199D31A94D1FA008DC684 /* Contador.m in Sources */ = {isa = PBXBuildFile; fileRef = 27A199D21A94D1FA008DC684 /* Contador.m */; };
27A199D61A94D821008DC684 /* ContadorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 27A199D51A94D821008DC684 /* ContadorTests.m */; };
E37FFAB51A9658C60061174F /* Singleton.m in Sources */ = {isa = PBXBuildFile; fileRef = E37FFAB41A9658C60061174F /* Singleton.m */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -52,6 +53,8 @@
27A199D21A94D1FA008DC684 /* Contador.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Contador.m; sourceTree = "<group>"; };
27A199D41A94D22B008DC684 /* Contador.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Contador.h; sourceTree = "<group>"; };
27A199D51A94D821008DC684 /* ContadorTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ContadorTests.m; sourceTree = "<group>"; };
E37FFAB31A9658C60061174F /* Singleton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Singleton.h; sourceTree = "<group>"; };
E37FFAB41A9658C60061174F /* Singleton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Singleton.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -116,6 +119,8 @@
children = (
27A199A41A94B2A8008DC684 /* Info.plist */,
27A199A51A94B2A8008DC684 /* main.m */,
E37FFAB31A9658C60061174F /* Singleton.h */,
E37FFAB41A9658C60061174F /* Singleton.m */,
);
name = "Supporting Files";
sourceTree = "<group>";
Expand Down Expand Up @@ -243,6 +248,7 @@
27A199AF1A94B2A8008DC684 /* SecondViewController.m in Sources */,
27A199A91A94B2A8008DC684 /* AppDelegate.m in Sources */,
27A199AC1A94B2A8008DC684 /* FirstViewController.m in Sources */,
E37FFAB51A9658C60061174F /* Singleton.m in Sources */,
27A199D31A94D1FA008DC684 /* Contador.m in Sources */,
27A199A61A94B2A8008DC684 /* main.m in Sources */,
);
Expand Down Expand Up @@ -438,6 +444,7 @@
27A199C81A94B2A8008DC684 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
27A199C91A94B2A8008DC684 /* Build configuration list for PBXNativeTarget "ContaPessoasTests" */ = {
isa = XCConfigurationList;
Expand All @@ -446,6 +453,7 @@
27A199CB1A94B2A8008DC684 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
Expand Down
3 changes: 3 additions & 0 deletions ContaPessoas/Contador.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@

@interface Contador : NSObject


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

-(int)getBoys;
-(int)getGirls;
-(int)getTotal;
+ (Contador *) instancia;

@end

17 changes: 16 additions & 1 deletion ContaPessoas/Contador.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@
@implementation Contador {
int boy;
int girl;
int total;

}

static Contador *_instancia;
-(id)init {
self = [super init];
if (self) {
boy = 0;
girl = 0;
_instancia = nil;
}
return self;
}
Expand All @@ -39,6 +42,18 @@ -(int)getGirls {
return girl;
}

-(int)getTotal
{
return total = [self getBoys] + [self getGirls];
}

+ (Contador *) instancia {

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


@end
Expand Down
2 changes: 1 addition & 1 deletion ContaPessoas/FirstViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@

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

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

Expand Down
7 changes: 3 additions & 4 deletions ContaPessoas/SecondViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ @implementation SecondViewController

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



- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
Expand All @@ -32,7 +31,7 @@ - (void)didReceiveMemoryWarning {
- (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
14 changes: 14 additions & 0 deletions ContaPessoas/Singleton.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// Singleton.h
// ContaPessoas
//
// Created by Rafael Hieda on 19/02/15.
// Copyright (c) 2015 Vinicius Miana. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface Singleton : NSObject
{}
+ (Singleton *) instancia;
@end
21 changes: 21 additions & 0 deletions ContaPessoas/Singleton.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// Singleton.m
// ContaPessoas
//
// Created by Rafael Hieda on 19/02/15.
// Copyright (c) 2015 Vinicius Miana. All rights reserved.
//

#import "Singleton.h"

@implementation Singleton
static Singleton *_instancia = nil;

+ (Singleton *) instancia {

if (_instancia == nil) {
_instancia = [[Singleton alloc] init];
}
return _instancia;
}
@end
17 changes: 17 additions & 0 deletions ContaPessoas/Singleton/Singleton/main.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// main.m
// Singleton
//
// Created by Rafael Hieda on 19/02/15.
// Copyright (c) 2015 Rafael Hieda. All rights reserved.
//

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
@autoreleasepool {
// insert code here...
NSLog(@"Hello, World!");
}
return 0;
}
9 changes: 9 additions & 0 deletions ContaPessoasTests/ContaPessoasTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,27 @@
#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>
#import "Contador.h"
#import "Singleton.h"

@interface ContaPessoasTests : XCTestCase

@end

@implementation ContaPessoasTests

-(void)CriaSingleton
{
Singleton *novoSingleton = [[Singleton alloc]init];
Contador *aux = [[Contador alloc]init];
aux = (Contador *) novoSingleton;

}

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

- (void)testContaMeninas {
Expand Down