Skip to content

Commit 308df73

Browse files
committed
import Moya, Freddy, ... klappt nicht
1 parent 970b416 commit 308df73

File tree

6 files changed

+121
-33
lines changed

6 files changed

+121
-33
lines changed

APIClient.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
/* Begin PBXBuildFile section */
1010
830DA5871CF437F100203B41 /* StarWarsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 830DA5861CF437F100203B41 /* StarWarsViewController.swift */; };
11+
830DA5891CF57DEE00203B41 /* SWAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 830DA5881CF57DEE00203B41 /* SWAPI.swift */; };
1112
872A275C1CF0D87100A988C4 /* APIResource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 872A275B1CF0D87100A988C4 /* APIResource.swift */; };
1213
874D06591CEF295E009A494D /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 874D06581CEF295E009A494D /* AppDelegate.swift */; };
1314
874D065E1CEF295E009A494D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 874D065C1CEF295E009A494D /* Main.storyboard */; };
@@ -18,6 +19,7 @@
1819

1920
/* Begin PBXFileReference section */
2021
830DA5861CF437F100203B41 /* StarWarsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StarWarsViewController.swift; sourceTree = "<group>"; };
22+
830DA5881CF57DEE00203B41 /* SWAPI.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SWAPI.swift; sourceTree = "<group>"; };
2123
872A275B1CF0D87100A988C4 /* APIResource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = APIResource.swift; sourceTree = "<group>"; };
2224
874D06551CEF295E009A494D /* APIClient.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = APIClient.app; sourceTree = BUILT_PRODUCTS_DIR; };
2325
874D06581CEF295E009A494D /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
@@ -61,6 +63,7 @@
6163
isa = PBXGroup;
6264
children = (
6365
872A275B1CF0D87100A988C4 /* APIResource.swift */,
66+
830DA5881CF57DEE00203B41 /* SWAPI.swift */,
6467
);
6568
name = Model;
6669
sourceTree = "<group>";
@@ -247,6 +250,7 @@
247250
files = (
248251
830DA5871CF437F100203B41 /* StarWarsViewController.swift in Sources */,
249252
872A275C1CF0D87100A988C4 /* APIResource.swift in Sources */,
253+
830DA5891CF57DEE00203B41 /* SWAPI.swift in Sources */,
250254
874D06591CEF295E009A494D /* AppDelegate.swift in Sources */,
251255
);
252256
runOnlyForDeploymentPostprocessing = 0;

APIClient/APIResource.swift

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -83,29 +83,6 @@ extension MoyaProvider where Target: Cacheable {
8383

8484
}
8585

86-
enum YourAPI: Moya.TargetType {
87-
case firstEndpoint (someParameter: String, anotherParameter: Int)
88-
var baseURL:NSURL {return NSURL(string: "http://swapi.co/api/")! }
89-
90-
var path : String {
91-
switch self {
92-
case .firstEndpoint(someParameter: let a, anotherParameter: _): return "/firstEndpoint/\(a)"
93-
}
94-
}
95-
96-
var method: Moya.Method {return .GET}
97-
98-
var parameters: [String : AnyObject]? {
99-
switch self {
100-
default: return nil
101-
}
102-
}
103-
104-
var sampleData: NSData {
105-
return "".dataUsingEncoding(NSUTF8StringEncoding)!
106-
}
107-
}
108-
10986
/// A persistent cache for resources
11087
private let resourceCache = try! Cache<NSData>(name: "APIResource")
11188

APIClient/AppDelegate.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//
88

99
import UIKit
10+
import Moya
1011

1112
@UIApplicationMain
1213
class AppDelegate: UIResponder, UIApplicationDelegate {
@@ -18,7 +19,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1819
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
1920

2021
if let starWarsViewController = (window?.rootViewController as? UINavigationController)?.topViewController as? StarWarsViewController {
21-
22+
// API to ViewController
23+
starWarsViewController.starWAPI = starWAPI
2224
}
2325

2426
return true

APIClient/Base.lproj/Main.storyboard

Lines changed: 65 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<dependencies>
44
<deployment identifier="iOS"/>
55
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
6+
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
67
</dependencies>
78
<scenes>
89
<!--Navigation Controller-->
@@ -21,24 +22,80 @@
2122
</objects>
2223
<point key="canvasLocation" x="-658" y="301"/>
2324
</scene>
24-
<!--View Controller-->
25+
<!--Star Wars View Controller-->
2526
<scene sceneID="adh-8k-Iuh">
2627
<objects>
27-
<viewController id="rPr-Fp-ALE" sceneMemberID="viewController">
28+
<viewController id="rPr-Fp-ALE" customClass="StarWarsViewController" customModule="APIClient" customModuleProvider="target" sceneMemberID="viewController">
2829
<layoutGuides>
29-
<viewControllerLayoutGuide type="top" id="pj8-zF-1z6"/>
30-
<viewControllerLayoutGuide type="bottom" id="kt2-9S-3TK"/>
30+
<viewControllerLayoutGuide type="top" id="chM-FO-a62"/>
31+
<viewControllerLayoutGuide type="bottom" id="7iq-nK-Ekc"/>
3132
</layoutGuides>
32-
<view key="view" contentMode="scaleToFill" id="rEB-Za-Zhx">
33+
<view key="view" contentMode="scaleToFill" id="bBw-Ym-2uK">
3334
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
34-
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
35+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
36+
<subviews>
37+
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" translatesAutoresizingMaskIntoConstraints="NO" id="PyA-76-HkM">
38+
<rect key="frame" x="20" y="64" width="560" height="200"/>
39+
<subviews>
40+
<stackView opaque="NO" contentMode="scaleToFill" misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Fed-da-Z7f">
41+
<rect key="frame" x="0.0" y="0.0" width="560" height="128"/>
42+
<subviews>
43+
<activityIndicatorView hidden="YES" opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" misplaced="YES" style="gray" translatesAutoresizingMaskIntoConstraints="NO" id="WIi-xB-SU0">
44+
<rect key="frame" x="0.0" y="0.0" width="20" height="128"/>
45+
</activityIndicatorView>
46+
<imageView hidden="YES" userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="DR2-O2-uIl">
47+
<rect key="frame" x="20" y="0.0" width="0.0" height="128"/>
48+
</imageView>
49+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" misplaced="YES" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="y6f-iU-cZH">
50+
<rect key="frame" x="20" y="0.0" width="540" height="128"/>
51+
<fontDescription key="fontDescription" type="system" pointSize="17"/>
52+
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
53+
<nil key="highlightedColor"/>
54+
</label>
55+
</subviews>
56+
</stackView>
57+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" ambiguous="YES" misplaced="YES" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="MNJ-HG-JlX">
58+
<rect key="frame" x="0.0" y="128" width="560" height="21"/>
59+
<fontDescription key="fontDescription" type="system" pointSize="17"/>
60+
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
61+
<nil key="highlightedColor"/>
62+
</label>
63+
<button opaque="NO" contentMode="scaleToFill" ambiguous="YES" misplaced="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="pdM-iY-5PV">
64+
<rect key="frame" x="0.0" y="149" width="560" height="52"/>
65+
<state key="normal" title="Button"/>
66+
</button>
67+
</subviews>
68+
</stackView>
69+
</subviews>
3570
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
71+
<constraints>
72+
<constraint firstItem="PyA-76-HkM" firstAttribute="top" secondItem="chM-FO-a62" secondAttribute="bottom" id="20W-JS-SCI"/>
73+
<constraint firstItem="7iq-nK-Ekc" firstAttribute="top" secondItem="PyA-76-HkM" secondAttribute="bottom" constant="336" id="kuu-ab-DLu"/>
74+
<constraint firstItem="PyA-76-HkM" firstAttribute="centerX" secondItem="bBw-Ym-2uK" secondAttribute="centerX" id="l1O-ME-tnZ"/>
75+
<constraint firstAttribute="trailingMargin" secondItem="PyA-76-HkM" secondAttribute="trailing" id="nFy-Gc-HDe"/>
76+
<constraint firstAttribute="leadingMargin" secondItem="PyA-76-HkM" secondAttribute="leading" id="sML-Po-ftm"/>
77+
</constraints>
3678
</view>
37-
<navigationItem key="navigationItem" id="CZR-l9-xMg"/>
79+
<navigationItem key="navigationItem" id="CZR-l9-xMg">
80+
<nil key="title"/>
81+
<textField key="titleView" opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" id="xUM-UT-swT">
82+
<rect key="frame" x="180" y="7" width="240" height="30"/>
83+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
84+
<fontDescription key="fontDescription" type="system" pointSize="14"/>
85+
<textInputTraits key="textInputTraits"/>
86+
</textField>
87+
</navigationItem>
88+
<connections>
89+
<outlet property="loadingIndicator" destination="WIi-xB-SU0" id="JLP-zs-ig3"/>
90+
<outlet property="planetLabel" destination="y6f-iU-cZH" id="Qi9-LI-6pw"/>
91+
<outlet property="searchTxtField" destination="xUM-UT-swT" id="Mje-gr-4AA"/>
92+
<outlet property="starShipImage" destination="DR2-O2-uIl" id="Vhn-p4-FZD"/>
93+
<outlet property="starShipLabel" destination="y6f-iU-cZH" id="OgI-WB-GUp"/>
94+
</connections>
3895
</viewController>
3996
<placeholder placeholderIdentifier="IBFirstResponder" id="OaC-W5-AeM" userLabel="First Responder" sceneMemberID="firstResponder"/>
4097
</objects>
41-
<point key="canvasLocation" x="65" y="301"/>
98+
<point key="canvasLocation" x="67" y="301"/>
4299
</scene>
43100
</scenes>
44101
</document>

APIClient/SWAPI.swift

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//
2+
// SWAPI.swift
3+
// APIClient
4+
//
5+
// Created by Christoph Blattgerste on 25.05.16.
6+
// Copyright © 2016 iOS Dev Kurs Universität Heidelberg. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import Moya
11+
import Freddy
12+
13+
14+
//adress of the used API: ("http://swapi.co/api/")
15+
16+
enum SWAPI: Moya.TargetType {
17+
18+
case starship (NamedResource<starship>)
19+
case planet (NamedResource<planets>)
20+
case species (NamedResource<species>)
21+
22+
var baseURL: NSURL {return NSURL(string: "http://swapi.co/api/")! }
23+
24+
var path : String {
25+
switch self {
26+
case .starship(let namedResource): return "/starships/\(namedResource.name)"
27+
case .planet(let namedResource): return "/planets/\(namedResource.name)"
28+
case .species(let namedResource): return "/species/\(namedResource.name)"
29+
}
30+
}
31+
32+
var method: Moya.Method {return .GET}
33+
34+
var parameters: [String : AnyObject]? {
35+
switch self {
36+
default: return nil
37+
}
38+
}
39+
40+
var sampleData: NSData {
41+
return "".dataUsingEncoding(NSUTF8StringEncoding)!
42+
}
43+
}

APIClient/StarWarsViewController.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
// Copyright © 2016 iOS Dev Kurs Universität Heidelberg. All rights reserved.
77
//
88

9-
import Foundation
109
import UIKit
1110
import Freddy
1211
import Moya
@@ -17,4 +16,10 @@ class StarWarsViewController: UIViewController {
1716
var starWAPI : MoyaProvider<SWAPI>!
1817

1918

19+
20+
21+
@IBOutlet weak var searchTxtField: UITextField!
22+
@IBOutlet weak var starShipLoading: UIActivityIndicatorView!
23+
@IBOutlet weak var starShipLabel: UILabel!
24+
@IBOutlet weak var starShipImage: UIImageView!
2025
}

0 commit comments

Comments
 (0)