Skip to content

Commit 7ef2f9d

Browse files
author
cramsden@thoughtworks.com
committed
[Carson | Shea] initial structure for workshop example
1 parent 66b280a commit 7ef2f9d

21 files changed

+549
-268
lines changed

RestExample/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# OSX Temporary Files
2-
.DS_Store
2+
*.DS_Store
33
.Trashes
44
*.swp
55
profile

RestExample/HelloRest/HelloRest.xcodeproj/project.pbxproj

Lines changed: 188 additions & 16 deletions
Large diffs are not rendered by default.

RestExample/HelloRest/HelloRest/Base.lproj/LaunchScreen.storyboard

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="8150" systemVersion="15A204g" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" initialViewController="01J-lp-oVM">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10116" systemVersion="15E65" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" initialViewController="01J-lp-oVM">
33
<dependencies>
4-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8122"/>
4+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
55
</dependencies>
66
<scenes>
77
<!--View Controller-->
@@ -15,7 +15,6 @@
1515
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
1616
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
1717
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
18-
<animations/>
1918
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
2019
</view>
2120
</viewController>
Lines changed: 12 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,9 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="JMR-3a-qCz">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10116" systemVersion="15E65" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="JMR-3a-qCz">
33
<dependencies>
4-
<deployment identifier="iOS"/>
54
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
6-
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
75
</dependencies>
86
<scenes>
9-
<!--View Controller-->
10-
<scene sceneID="tne-QT-ifu">
11-
<objects>
12-
<viewController storyboardIdentifier="ViewController" id="BYZ-38-t0r" customClass="ViewController" customModule="HelloRest" customModuleProvider="target" sceneMemberID="viewController">
13-
<layoutGuides>
14-
<viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/>
15-
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
16-
</layoutGuides>
17-
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
18-
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
19-
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
20-
<subviews>
21-
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="yMQ-rS-8Ze">
22-
<rect key="frame" x="30" y="0.0" width="540" height="600"/>
23-
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
24-
</tableView>
25-
</subviews>
26-
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
27-
<constraints>
28-
<constraint firstItem="yMQ-rS-8Ze" firstAttribute="top" secondItem="8bC-Xf-vdC" secondAttribute="topMargin" id="79v-4f-Jeh"/>
29-
<constraint firstItem="yMQ-rS-8Ze" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leadingMargin" constant="10" id="Cvy-mk-jJ5"/>
30-
<constraint firstAttribute="trailingMargin" secondItem="yMQ-rS-8Ze" secondAttribute="trailing" constant="10" id="D3O-3F-lGd"/>
31-
<constraint firstItem="wfy-db-euE" firstAttribute="top" secondItem="yMQ-rS-8Ze" secondAttribute="bottom" id="lOV-5D-G8u"/>
32-
</constraints>
33-
</view>
34-
<navigationItem key="navigationItem" id="bhD-w0-KCM"/>
35-
<connections>
36-
<outlet property="tableView" destination="yMQ-rS-8Ze" id="Xha-8v-nek"/>
37-
</connections>
38-
</viewController>
39-
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
40-
</objects>
41-
<point key="canvasLocation" x="1588" y="522"/>
42-
</scene>
437
<!--Navigation Controller-->
448
<scene sceneID="d5F-4k-jHV">
459
<objects>
@@ -51,12 +15,22 @@
5115
</navigationBar>
5216
<nil name="viewControllers"/>
5317
<connections>
54-
<segue destination="BYZ-38-t0r" kind="relationship" relationship="rootViewController" id="Cf6-4G-KwB"/>
18+
<segue destination="Wwe-gb-5sZ" kind="relationship" relationship="rootViewController" id="KsA-f5-MVF"/>
5519
</connections>
5620
</navigationController>
5721
<placeholder placeholderIdentifier="IBFirstResponder" id="GUe-6J-KJY" userLabel="First Responder" sceneMemberID="firstResponder"/>
5822
</objects>
5923
<point key="canvasLocation" x="859" y="515"/>
6024
</scene>
25+
<!--PeopleListView-->
26+
<scene sceneID="doG-Tt-A9C">
27+
<objects>
28+
<viewControllerPlaceholder storyboardName="PeopleListView" id="Wwe-gb-5sZ" sceneMemberID="viewController">
29+
<navigationItem key="navigationItem" id="UpC-Ob-2r8"/>
30+
</viewControllerPlaceholder>
31+
<placeholder placeholderIdentifier="IBFirstResponder" id="bx1-Bt-iOa" userLabel="First Responder" sceneMemberID="firstResponder"/>
32+
</objects>
33+
<point key="canvasLocation" x="1437.5" y="515"/>
34+
</scene>
6135
</scenes>
6236
</document>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import Foundation
2+
3+
struct Person {
4+
let id: Int
5+
let name: String
6+
let age: Int?
7+
let phone: String?
8+
9+
init(id:Int, name: String, age: Int? = nil, phone: String? = nil){
10+
self.id = id
11+
self.name = name
12+
self.age = age
13+
self.phone = phone
14+
}
15+
}
16+
17+
extension Person : Equatable {}
18+
19+
func ==(lhs: Person, rhs: Person) -> Bool {
20+
return lhs.id == rhs.id &&
21+
lhs.name == rhs.name &&
22+
lhs.age == rhs.age &&
23+
lhs.phone == rhs.phone
24+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10116" systemVersion="15E65" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="5r4-VJ-Jr0">
3+
<dependencies>
4+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
5+
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
6+
</dependencies>
7+
<scenes>
8+
<!--People List View Controller-->
9+
<scene sceneID="1iN-Sv-HEK">
10+
<objects>
11+
<viewController storyboardIdentifier="PeopleListViewController" id="5r4-VJ-Jr0" customClass="PeopleListViewController" customModule="HelloRest" customModuleProvider="target" sceneMemberID="viewController">
12+
<layoutGuides>
13+
<viewControllerLayoutGuide type="top" id="giA-Bl-vuK"/>
14+
<viewControllerLayoutGuide type="bottom" id="T6N-vs-9kN"/>
15+
</layoutGuides>
16+
<view key="view" contentMode="scaleToFill" id="0dJ-9y-TGd">
17+
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
18+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
19+
<subviews>
20+
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="Ssc-Qf-lCZ">
21+
<rect key="frame" x="30" y="0.0" width="540" height="600"/>
22+
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
23+
<connections>
24+
<outlet property="dataSource" destination="5r4-VJ-Jr0" id="CFT-ZO-ilL"/>
25+
<outlet property="delegate" destination="5r4-VJ-Jr0" id="SO6-7v-vXc"/>
26+
</connections>
27+
</tableView>
28+
</subviews>
29+
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
30+
<constraints>
31+
<constraint firstAttribute="trailingMargin" secondItem="Ssc-Qf-lCZ" secondAttribute="trailing" constant="10" id="WiV-i3-yAL"/>
32+
<constraint firstItem="Ssc-Qf-lCZ" firstAttribute="leading" secondItem="0dJ-9y-TGd" secondAttribute="leadingMargin" constant="10" id="pcE-AA-Yhd"/>
33+
<constraint firstItem="T6N-vs-9kN" firstAttribute="top" secondItem="Ssc-Qf-lCZ" secondAttribute="bottom" id="pkT-IM-RPb"/>
34+
<constraint firstItem="Ssc-Qf-lCZ" firstAttribute="top" secondItem="0dJ-9y-TGd" secondAttribute="topMargin" id="tGR-xD-E28"/>
35+
</constraints>
36+
</view>
37+
<connections>
38+
<outlet property="tableView" destination="Ssc-Qf-lCZ" id="gSE-us-pEQ"/>
39+
</connections>
40+
</viewController>
41+
<placeholder placeholderIdentifier="IBFirstResponder" id="X1p-FH-Aj0" userLabel="First Responder" sceneMemberID="firstResponder"/>
42+
</objects>
43+
<point key="canvasLocation" x="486" y="458"/>
44+
</scene>
45+
</scenes>
46+
</document>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import UIKit
2+
import Alamofire
3+
import SwiftyJSON
4+
import ReactiveCocoa
5+
6+
class PeopleListViewController: UIViewController{
7+
let peopleSignal = MutableProperty<[Person]>([])
8+
9+
@IBOutlet weak var tableView: UITableView!
10+
11+
var viewModel: PeopleListViewModel!
12+
13+
let peopleService = PeopleService()
14+
15+
override func viewDidLoad() {
16+
super.viewDidLoad()
17+
self.title = "Contacts"
18+
19+
viewModel = PeopleListViewModel(peopleService: peopleService)
20+
peopleSignal <~ viewModel!.people.producer
21+
22+
peopleSignal.producer.startWithNext { people in
23+
self.tableView.reloadData()
24+
}
25+
}
26+
}
27+
28+
extension PeopleListViewController : UITableViewDataSource {
29+
30+
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
31+
return viewModel.numberOfPeople
32+
}
33+
34+
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
35+
let personForIndex = viewModel.getPersonAtIndex(indexPath.row)
36+
let cellIdentifier = "\(personForIndex.id)"
37+
let cell: UITableViewCell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier) ?? UITableViewCell(style: .Default, reuseIdentifier: cellIdentifier)
38+
39+
cell.textLabel?.text = personForIndex.name
40+
return cell
41+
}
42+
43+
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
44+
return 1
45+
}
46+
}
47+
48+
49+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import UIKit
2+
import SwiftyJSON
3+
import ReactiveCocoa
4+
5+
struct PeopleListViewModel {
6+
let people = MutableProperty<[Person]>([])
7+
let peopleService: PeopleServiceType
8+
9+
init(peopleService: PeopleServiceType) {
10+
self.peopleService = peopleService
11+
peopleService.getAllPeopleJSON() { people in
12+
self.people.value = people
13+
}
14+
}
15+
16+
var numberOfPeople: Int {
17+
return people.value.count
18+
}
19+
20+
func getPersonAtIndex(index: Int) -> Person {
21+
return people.value[index]
22+
}
23+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import Foundation
2+
import Alamofire
3+
import SwiftyJSON
4+
5+
protocol PeopleServiceType {
6+
func getAllPeopleJSON(onCompletion: ([Person]) -> Void)
7+
}
8+
9+
class PeopleService : PeopleServiceType {
10+
11+
func getAllPeopleJSON(onCompletion: ([Person]) -> Void) {
12+
Alamofire
13+
.request(.GET, "http://localhost:8000/list")
14+
.validate(statusCode: 200..<400)
15+
.responseJSON { response in
16+
if let value = response.result.value {
17+
let json = JSON(value)
18+
let people = PeopleTransformer.transformListOfPeopleWithoutDetail(json)
19+
onCompletion(people)
20+
}
21+
}
22+
23+
}
24+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import Foundation
2+
import SwiftyJSON
3+
4+
struct PeopleTransformer {
5+
static func transformListOfPeopleWithoutDetail(response: JSON) -> [Person] {
6+
let jsonArray = response.arrayValue
7+
return jsonArray.map { json in
8+
Person(id: json["id"].intValue, name: json["name"].stringValue)
9+
}
10+
}
11+
}

0 commit comments

Comments
 (0)