Skip to content
This repository was archived by the owner on Aug 21, 2021. It is now read-only.

Commit 57b5b68

Browse files
committed
Merge branch 'add-ui'
2 parents 6851935 + 5fd728e commit 57b5b68

File tree

8 files changed

+193
-58
lines changed

8 files changed

+193
-58
lines changed

SwinjectSimpleExample.xcodeproj/project.pbxproj

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
9878A1ED1B7876A70005ACD9 /* OpenWeatherMap.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9878A1EC1B7876A70005ACD9 /* OpenWeatherMap.swift */; };
1515
9878A1EF1B78930E0005ACD9 /* Networking.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9878A1EE1B78930E0005ACD9 /* Networking.swift */; };
1616
9878A1F11B7893210005ACD9 /* Network.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9878A1F01B7893210005ACD9 /* Network.swift */; };
17+
9878A1F31B78B9610005ACD9 /* WeatherTablerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9878A1F21B78B9610005ACD9 /* WeatherTablerViewController.swift */; };
18+
9878A1F51B78C8340005ACD9 /* WeatherTablerViewControllerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9878A1F41B78C8340005ACD9 /* WeatherTablerViewControllerSpec.swift */; };
1719
98BA27341B785EB00047549E /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98BA27331B785EB00047549E /* AppDelegate.swift */; };
18-
98BA27361B785EB00047549E /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98BA27351B785EB00047549E /* ViewController.swift */; };
1920
98BA27391B785EB00047549E /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 98BA27371B785EB00047549E /* Main.storyboard */; };
2021
98BA273B1B785EB00047549E /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 98BA273A1B785EB00047549E /* Assets.xcassets */; };
2122
98BA273E1B785EB00047549E /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 98BA273C1B785EB00047549E /* LaunchScreen.storyboard */; };
@@ -40,9 +41,10 @@
4041
9878A1EC1B7876A70005ACD9 /* OpenWeatherMap.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OpenWeatherMap.swift; sourceTree = "<group>"; };
4142
9878A1EE1B78930E0005ACD9 /* Networking.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Networking.swift; sourceTree = "<group>"; };
4243
9878A1F01B7893210005ACD9 /* Network.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Network.swift; sourceTree = "<group>"; };
44+
9878A1F21B78B9610005ACD9 /* WeatherTablerViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WeatherTablerViewController.swift; sourceTree = "<group>"; };
45+
9878A1F41B78C8340005ACD9 /* WeatherTablerViewControllerSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WeatherTablerViewControllerSpec.swift; sourceTree = "<group>"; };
4346
98BA27301B785EB00047549E /* SwinjectSimpleExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SwinjectSimpleExample.app; sourceTree = BUILT_PRODUCTS_DIR; };
4447
98BA27331B785EB00047549E /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
45-
98BA27351B785EB00047549E /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
4648
98BA27381B785EB00047549E /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
4749
98BA273A1B785EB00047549E /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
4850
98BA273D1B785EB00047549E /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
@@ -132,7 +134,7 @@
132134
children = (
133135
9878A1E41B7874420005ACD9 /* Model */,
134136
98BA27331B785EB00047549E /* AppDelegate.swift */,
135-
98BA27351B785EB00047549E /* ViewController.swift */,
137+
9878A1F21B78B9610005ACD9 /* WeatherTablerViewController.swift */,
136138
98BA27371B785EB00047549E /* Main.storyboard */,
137139
98BA273A1B785EB00047549E /* Assets.xcassets */,
138140
98BA273C1B785EB00047549E /* LaunchScreen.storyboard */,
@@ -146,6 +148,7 @@
146148
children = (
147149
9878A1E91B7874610005ACD9 /* Model */,
148150
98BA274A1B785EB00047549E /* Info.plist */,
151+
9878A1F41B78C8340005ACD9 /* WeatherTablerViewControllerSpec.swift */,
149152
);
150153
path = SwinjectSimpleExampleTests;
151154
sourceTree = "<group>";
@@ -359,9 +362,9 @@
359362
buildActionMask = 2147483647;
360363
files = (
361364
9878A1ED1B7876A70005ACD9 /* OpenWeatherMap.swift in Sources */,
362-
98BA27361B785EB00047549E /* ViewController.swift in Sources */,
363365
9878A1E81B78745C0005ACD9 /* WeatherFetcher.swift in Sources */,
364366
9878A1EF1B78930E0005ACD9 /* Networking.swift in Sources */,
367+
9878A1F31B78B9610005ACD9 /* WeatherTablerViewController.swift in Sources */,
365368
9878A1E71B78745C0005ACD9 /* City.swift in Sources */,
366369
9878A1F11B7893210005ACD9 /* Network.swift in Sources */,
367370
98BA27341B785EB00047549E /* AppDelegate.swift in Sources */,
@@ -372,6 +375,7 @@
372375
isa = PBXSourcesBuildPhase;
373376
buildActionMask = 2147483647;
374377
files = (
378+
9878A1F51B78C8340005ACD9 /* WeatherTablerViewControllerSpec.swift in Sources */,
375379
9878A1EB1B78746C0005ACD9 /* WeatherFetcherSpec.swift in Sources */,
376380
);
377381
runOnlyForDeploymentPostprocessing = 0;

SwinjectSimpleExample/AppDelegate.swift

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,22 @@
77
//
88

99
import UIKit
10+
import Swinject
1011

1112
@UIApplicationMain
1213
class AppDelegate: UIResponder, UIApplicationDelegate {
13-
1414
var window: UIWindow?
1515

16-
1716
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
18-
// Override point for customization after application launch.
17+
let window = UIWindow(frame: UIScreen.mainScreen().bounds)
18+
window.backgroundColor = UIColor.whiteColor()
19+
window.makeKeyAndVisible()
20+
self.window = window
21+
22+
let container = createContainer()
23+
let storyboard = SwinjectStoryboard.create(name: "Main", bundle: nil, container: container)
24+
window.rootViewController = storyboard.instantiateInitialViewController()!
25+
1926
return true
2027
}
2128

@@ -41,6 +48,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
4148
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
4249
}
4350

44-
51+
private func createContainer() -> Container {
52+
let container = Container()
53+
container.registerForStoryboard(WeatherTablerViewController.self) { r, c in
54+
c.weatherFetcher = r.resolve(WeatherFetcher.self)
55+
}
56+
container.register(Networking.self) { _ in Network() }
57+
container.register(WeatherFetcher.self) { r in WeatherFetcher(networking: r.resolve(Networking.self)!) }
58+
return container
59+
}
4560
}
46-
Lines changed: 58 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,69 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6211" systemVersion="14A298i" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="8173.3" systemVersion="14E46" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="6eh-ad-Rg8">
33
<dependencies>
4-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6204"/>
4+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8142"/>
55
</dependencies>
66
<scenes>
7-
<!--View Controller-->
8-
<scene sceneID="tne-QT-ifu">
7+
<!--Weather Now-->
8+
<scene sceneID="2D7-jx-u5T">
99
<objects>
10-
<viewController id="BYZ-38-t0r" customClass="ViewController" customModuleProvider="target" sceneMemberID="viewController">
11-
<layoutGuides>
12-
<viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/>
13-
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
14-
</layoutGuides>
15-
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
10+
<tableViewController id="ykF-tn-1bK" customClass="WeatherTablerViewController" customModule="SwinjectSimpleExample" customModuleProvider="target" sceneMemberID="viewController">
11+
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" id="45C-dC-7GN">
1612
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
1713
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
18-
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
19-
</view>
20-
</viewController>
21-
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
14+
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
15+
<prototypes>
16+
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="Cell" textLabel="O4B-QC-lsS" detailTextLabel="3Fw-6V-S1v" style="IBUITableViewCellStyleValue1" id="eSk-Tb-JRP">
17+
<rect key="frame" x="0.0" y="92" width="600" height="44"/>
18+
<autoresizingMask key="autoresizingMask"/>
19+
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="eSk-Tb-JRP" id="2ng-UJ-XOP">
20+
<rect key="frame" x="0.0" y="0.0" width="600" height="43"/>
21+
<autoresizingMask key="autoresizingMask"/>
22+
<subviews>
23+
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="O4B-QC-lsS">
24+
<rect key="frame" x="15" y="12" width="32" height="20"/>
25+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
26+
<fontDescription key="fontDescription" type="system" pointSize="16"/>
27+
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
28+
<nil key="highlightedColor"/>
29+
</label>
30+
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Detail" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="3Fw-6V-S1v">
31+
<rect key="frame" x="543" y="12" width="42" height="20"/>
32+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
33+
<fontDescription key="fontDescription" type="system" pointSize="16"/>
34+
<color key="textColor" red="0.55686274509803924" green="0.55686274509803924" blue="0.57647058823529407" alpha="1" colorSpace="calibratedRGB"/>
35+
<nil key="highlightedColor"/>
36+
</label>
37+
</subviews>
38+
</tableViewCellContentView>
39+
</tableViewCell>
40+
</prototypes>
41+
<connections>
42+
<outlet property="dataSource" destination="ykF-tn-1bK" id="Loc-bT-F8q"/>
43+
<outlet property="delegate" destination="ykF-tn-1bK" id="A91-tc-RNK"/>
44+
</connections>
45+
</tableView>
46+
<navigationItem key="navigationItem" title="Weather Now" id="h32-Mz-ff1"/>
47+
</tableViewController>
48+
<placeholder placeholderIdentifier="IBFirstResponder" id="M1f-qV-6GX" userLabel="First Responder" sceneMemberID="firstResponder"/>
2249
</objects>
50+
<point key="canvasLocation" x="754" y="425"/>
51+
</scene>
52+
<!--Navigation Controller-->
53+
<scene sceneID="fMw-mp-r2U">
54+
<objects>
55+
<navigationController id="6eh-ad-Rg8" sceneMemberID="viewController">
56+
<navigationBar key="navigationBar" contentMode="scaleToFill" id="rqO-9g-00j">
57+
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
58+
<autoresizingMask key="autoresizingMask"/>
59+
</navigationBar>
60+
<connections>
61+
<segue destination="ykF-tn-1bK" kind="relationship" relationship="rootViewController" id="tes-ei-5vC"/>
62+
</connections>
63+
</navigationController>
64+
<placeholder placeholderIdentifier="IBFirstResponder" id="cRc-NZ-vhP" userLabel="First Responder" sceneMemberID="firstResponder"/>
65+
</objects>
66+
<point key="canvasLocation" x="-66" y="425"/>
2367
</scene>
2468
</scenes>
2569
</document>

SwinjectSimpleExample/Info.plist

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
<true/>
2525
<key>UILaunchStoryboardName</key>
2626
<string>LaunchScreen</string>
27-
<key>UIMainStoryboardFile</key>
28-
<string>Main</string>
2927
<key>UIRequiredDeviceCapabilities</key>
3028
<array>
3129
<string>armv7</string>

SwinjectSimpleExample/ViewController.swift

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//
2+
// WeatherTablerViewController.swift
3+
// SwinjectSimpleExample
4+
//
5+
// Created by Yoichi Tagaya on 8/10/15.
6+
// Copyright © 2015 Swinject Contributors. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
class WeatherTablerViewController: UITableViewController {
12+
var weatherFetcher: WeatherFetcher?
13+
private var cities = [City]() {
14+
didSet {
15+
tableView.reloadData()
16+
}
17+
}
18+
19+
override func viewWillAppear(animated: Bool) {
20+
weatherFetcher?.fetch {
21+
if let cities = $0 {
22+
self.cities = cities
23+
}
24+
else {
25+
let title = "Error"
26+
let message = "Cannot communicate with the weather server. Check wi-fi or cellular network settings."
27+
let dismiss = "Dismiss"
28+
let alert = UIAlertController(title: title, message: message, preferredStyle: .Alert)
29+
alert.addAction(UIAlertAction(title: dismiss, style: .Default) { _ in
30+
alert.dismissViewControllerAnimated(true, completion: nil)
31+
})
32+
self.presentViewController(alert, animated: true, completion: nil)
33+
}
34+
}
35+
}
36+
37+
// MARK: UITableViewDataSource
38+
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
39+
return cities.count
40+
}
41+
42+
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
43+
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath)
44+
let city = cities[indexPath.row]
45+
cell.textLabel?.text = city.name
46+
cell.detailTextLabel?.text = city.weather
47+
return cell
48+
}
49+
}

SwinjectSimpleExampleTests/WeatherFetcherSpec.swift

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,17 @@ class WeatherFetcherSpec: QuickSpec {
4545
}
4646

4747
override func spec() {
48-
let container = Container()
49-
container.register(Networking.self) { _ in Network() }
50-
container.register(WeatherFetcher.self) { r in
51-
WeatherFetcher(networking: r.resolve(Networking.self)!)
52-
}
53-
container.register(Networking.self, name: "stub") { _ in StubNetwork() }
54-
container.register(WeatherFetcher.self, name: "stub") { r in
55-
WeatherFetcher(networking: r.resolve(Networking.self, name: "stub")!)
48+
var container: Container!
49+
beforeEach {
50+
container = Container()
51+
container.register(Networking.self) { _ in Network() }
52+
container.register(WeatherFetcher.self) { r in
53+
WeatherFetcher(networking: r.resolve(Networking.self)!)
54+
}
55+
container.register(Networking.self, name: "stub") { _ in StubNetwork() }
56+
container.register(WeatherFetcher.self, name: "stub") { r in
57+
WeatherFetcher(networking: r.resolve(Networking.self, name: "stub")!)
58+
}
5659
}
5760

5861
it("returns cities.") {
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//
2+
// WeatherTablerViewControllerSpec.swift
3+
// SwinjectSimpleExample
4+
//
5+
// Created by Yoichi Tagaya on 8/10/15.
6+
// Copyright © 2015 Swinject Contributors. All rights reserved.
7+
//
8+
9+
import Quick
10+
import Nimble
11+
import Swinject
12+
@testable import SwinjectSimpleExample
13+
14+
class WeatherTablerViewControllerSpec: QuickSpec {
15+
class MockNetwork: Networking {
16+
var requestCount = 0
17+
18+
func request(response: NSData? -> ()) {
19+
requestCount++
20+
}
21+
}
22+
23+
override func spec() {
24+
var container: Container!
25+
beforeEach {
26+
container = Container()
27+
container.register(Networking.self) { _ in MockNetwork() }
28+
.inObjectScope(.Container)
29+
container.register(WeatherFetcher.self) { r in
30+
WeatherFetcher(networking: r.resolve(Networking.self)!)
31+
}
32+
container.register(WeatherTablerViewController.self) { r in
33+
let controller = WeatherTablerViewController()
34+
controller.weatherFetcher = r.resolve(WeatherFetcher.self)
35+
return controller
36+
}
37+
}
38+
39+
it("starts fetching weather information when the view is about appearing.") {
40+
let network = container.resolve(Networking.self) as! MockNetwork
41+
let controller = container.resolve(WeatherTablerViewController.self)!
42+
43+
expect(network.requestCount) == 0
44+
controller.viewWillAppear(true)
45+
expect(network.requestCount).toEventually(equal(1))
46+
}
47+
}
48+
}

0 commit comments

Comments
 (0)