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: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# iOS Workshop Part II (Starting Point)
# iOS Workshop Part II (Step 2 Complete)
## Prerequisites
* A basic understanding of Swift
* Ability to create a basic, single-view app
Expand Down Expand Up @@ -48,6 +48,6 @@
### Reactive Cocoa
* http://ifnotapps.com/2013/07/25/reactivecocoa-from-the-ground-floor-part1/

# Next Branch: `listWithDetails`
# Next Branch: `transition_to_new_view`


32 changes: 32 additions & 0 deletions RestExample/HelloRest/HelloRest.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@
isa = PBXNativeTarget;
buildConfigurationList = AD72BAE81D1CA73B00C230B9 /* Build configuration list for PBXNativeTarget "HelloRestSpecs" */;
buildPhases = (
99F73E9884FFFC5AB76BBC29 /* [CP] Check Pods Manifest.lock */,
EAE3D014E57140C65E5C3643 /* [CP] Check Pods Manifest.lock */,
AAF4A4CFC64D12F3060EC27D /* [CP] Check Pods Manifest.lock */,
AD72BADB1D1CA73B00C230B9 /* Sources */,
Expand All @@ -237,6 +238,7 @@
isa = PBXNativeTarget;
buildConfigurationList = AD86367B1D1CA38000792EDC /* Build configuration list for PBXNativeTarget "HelloRest" */;
buildPhases = (
C58B037D40F413D99A37FDBB /* [CP] Check Pods Manifest.lock */,
68E8A2EC53524B779E21F046 /* [CP] Check Pods Manifest.lock */,
054A7AC6CC5D8E9D0785E5C3 /* [CP] Check Pods Manifest.lock */,
AD8636651D1CA38000792EDC /* Sources */,
Expand Down Expand Up @@ -376,6 +378,21 @@
shellScript = "\"${SRCROOT}/../Pods/Target Support Files/Pods-HelloRestSpecs/Pods-HelloRestSpecs-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
99F73E9884FFFC5AB76BBC29 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "[CP] Check Pods Manifest.lock";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n";
showEnvVarsInLog = 0;
};
9B5FEDA850D40C4E8FB38ABE /* 📦 Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -436,6 +453,21 @@
shellScript = "\"${SRCROOT}/../Pods/Target Support Files/Pods-HelloRest/Pods-HelloRest-resources.sh\"\n";
showEnvVarsInLog = 0;
};
C58B037D40F413D99A37FDBB /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "[CP] Check Pods Manifest.lock";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n";
showEnvVarsInLog = 0;
};
E2FC52759A204C528D5D5B90 /* 📦 Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ extension PeopleListViewController : UITableViewDataSource {

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let personForIndex = viewModel.getPersonAtIndex(indexPath.row)
let cellIdentifier = "\(personForIndex.id)"
let cell: UITableViewCell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier) ?? UITableViewCell(style: .Default, reuseIdentifier: cellIdentifier)
let cellIdentifier = "cell"
let cell: UITableViewCell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier) ?? UITableViewCell(style: .Subtitle, reuseIdentifier: cellIdentifier)

cell.textLabel?.text = personForIndex.name
cell.detailTextLabel?.text = personForIndex.phone ?? ""
return cell
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ struct PeopleListViewModel {

init(peopleService: PeopleServiceType) {
self.peopleService = peopleService
peopleService.getAllPeople() { people in
peopleService.getAllPeopleWithDetails { people in
self.people.value = people
}
}
Expand Down
13 changes: 13 additions & 0 deletions RestExample/HelloRest/HelloRest/Services/PeopleService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import SwiftyJSON

protocol PeopleServiceType {
func getAllPeople(onCompletion: ([Person]) -> Void)
func getAllPeopleWithDetails(onCompletion:([Person])-> Void)
}

class PeopleService : PeopleServiceType {
Expand All @@ -21,4 +22,16 @@ class PeopleService : PeopleServiceType {
}

}
func getAllPeopleWithDetails(onCompletion:([Person])-> Void) {
Alamofire
.request(.GET, "http://localhost:8000/listAll")
.validate(statusCode: 200..<400)
.responseJSON { response in
if let value = response.result.value {
let json = JSON(value)
let people = PeopleTransformer.transformListOfPeople(json)
onCompletion(people)
}
}
}
}
6 changes: 6 additions & 0 deletions RestExample/HelloRest/HelloRestSpecs/PeopleServiceMock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ import Foundation

class PeopleServiceMock: PeopleServiceType {
var getAllPeopleCalled = false
var getAllPeopleWithDetailsCalled = false
var stubbedPeopleWithoutDetail = [Person(id: 1, name: "someName")]

func getAllPeople(onCompletion: ([Person]) -> Void){
getAllPeopleCalled = true
onCompletion(stubbedPeopleWithoutDetail)
}

func getAllPeopleWithDetails(onCompletion:([Person])-> Void) {
getAllPeopleWithDetailsCalled = true
onCompletion(stubbedPeopleWithoutDetail)
}
}
38 changes: 38 additions & 0 deletions RestExample/HelloRest/HelloRestSpecs/PeopleServiceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,25 @@ class PeopleServiceTests: QuickSpec {
return OHHTTPStubsResponse(JSONObject: obj, statusCode: 200, headers: nil).responseTime(OHHTTPStubsDownloadSpeed3G)

}

stub(isHost("localhost") && isPath("/listAll") && isMethodGET()) { request in

let obj = [[
"id": 7,
"name": "Ballard Craig",
"age": 19,
"phone": "somePhone"
],
[
"id": 8,
"name": "Brown Holt",
"age": 10,
"phone" : "somePhone"
]]

return OHHTTPStubsResponse(JSONObject: obj, statusCode: 200, headers: nil).responseTime(OHHTTPStubsDownloadSpeed3G)

}
}

afterEach {
Expand Down Expand Up @@ -51,6 +70,25 @@ class PeopleServiceTests: QuickSpec {
}

}
describe(".getAllPeopleWithDetails"){
it("should get people with details from listAll endpoint") {
let peopleService = PeopleService()
var completionCalled = false
var actualPeople:[Person] = []

peopleService.getAllPeopleWithDetails { people in
completionCalled = true
actualPeople = people
}

expect(completionCalled).toEventually(beTrue())
expect(actualPeople).toEventually(haveCount(2))

let firstPerson = actualPeople.first
expect(firstPerson?.phone).toNot(beNil())

}
}

}
}