Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fast_fertig: nur Problem bei PerformRequest #5

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
16 changes: 16 additions & 0 deletions APIClient.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,31 @@

/* Begin PBXBuildFile section */
872A275C1CF0D87100A988C4 /* APIResource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 872A275B1CF0D87100A988C4 /* APIResource.swift */; };
8744AA581CF2199F001B0470 /* SWViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8744AA571CF2199F001B0470 /* SWViewController.swift */; };
874D06591CEF295E009A494D /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 874D06581CEF295E009A494D /* AppDelegate.swift */; };
874D065E1CEF295E009A494D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 874D065C1CEF295E009A494D /* Main.storyboard */; };
874D06601CEF295E009A494D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 874D065F1CEF295E009A494D /* Assets.xcassets */; };
874D06631CEF295E009A494D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 874D06611CEF295E009A494D /* LaunchScreen.storyboard */; };
874D066B1CEF2BC0009A494D /* SWAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 874D066A1CEF2BC0009A494D /* SWAPI.swift */; };
A526FDEE5BF2D1BC3C97B9FA /* Pods_APIClient.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BD8A5B3E1266D5298CABE44A /* Pods_APIClient.framework */; };
DCE5C8C61CFB621C0025C611 /* StarWars.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCE5C8C51CFB621C0025C611 /* StarWars.swift */; };
DCE5C8C81CFB66320025C611 /* SWView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCE5C8C71CFB66320025C611 /* SWView.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
872A275B1CF0D87100A988C4 /* APIResource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = APIResource.swift; sourceTree = "<group>"; };
8744AA571CF2199F001B0470 /* SWViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SWViewController.swift; sourceTree = "<group>"; };
874D06551CEF295E009A494D /* APIClient.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = APIClient.app; sourceTree = BUILT_PRODUCTS_DIR; };
874D06581CEF295E009A494D /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
874D065D1CEF295E009A494D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
874D065F1CEF295E009A494D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
874D06621CEF295E009A494D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
874D06641CEF295E009A494D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
874D066A1CEF2BC0009A494D /* SWAPI.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SWAPI.swift; sourceTree = "<group>"; };
93EFAB13AE62F1B6FB2683B2 /* Pods-APIClient.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-APIClient.debug.xcconfig"; path = "Pods/Target Support Files/Pods-APIClient/Pods-APIClient.debug.xcconfig"; sourceTree = "<group>"; };
BD8A5B3E1266D5298CABE44A /* Pods_APIClient.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_APIClient.framework; sourceTree = BUILT_PRODUCTS_DIR; };
DCE5C8C51CFB621C0025C611 /* StarWars.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StarWars.swift; sourceTree = "<group>"; };
DCE5C8C71CFB66320025C611 /* SWView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SWView.swift; sourceTree = "<group>"; };
FFE13D543A95D28F27CFBDA4 /* Pods-APIClient.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-APIClient.release.xcconfig"; path = "Pods/Target Support Files/Pods-APIClient/Pods-APIClient.release.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand All @@ -43,20 +51,24 @@
872A27571CF0D4E200A988C4 /* View Controller */ = {
isa = PBXGroup;
children = (
8744AA571CF2199F001B0470 /* SWViewController.swift */,
);
name = "View Controller";
sourceTree = "<group>";
};
872A27581CF0D4EB00A988C4 /* View */ = {
isa = PBXGroup;
children = (
DCE5C8C71CFB66320025C611 /* SWView.swift */,
);
name = View;
sourceTree = "<group>";
};
872A27591CF0D64A00A988C4 /* Model */ = {
isa = PBXGroup;
children = (
874D066A1CEF2BC0009A494D /* SWAPI.swift */,
DCE5C8C51CFB621C0025C611 /* StarWars.swift */,
872A275B1CF0D87100A988C4 /* APIResource.swift */,
);
name = Model;
Expand Down Expand Up @@ -242,8 +254,12 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
874D066B1CEF2BC0009A494D /* SWAPI.swift in Sources */,
872A275C1CF0D87100A988C4 /* APIResource.swift in Sources */,
874D06591CEF295E009A494D /* AppDelegate.swift in Sources */,
8744AA581CF2199F001B0470 /* SWViewController.swift in Sources */,
DCE5C8C81CFB66320025C611 /* SWView.swift in Sources */,
DCE5C8C61CFB621C0025C611 /* StarWars.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
4 changes: 2 additions & 2 deletions APIClient/APIResource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import AwesomeCache
You are free to use this utility or implement your own way to keep track of loaded and not loaded resources.

- seealso: MoyaProvider.request<Resource: Freddy.JSONDecodable>(_:completion:)
*/
*/
enum APIResource<Target: Moya.TargetType, Resource: Freddy.JSONDecodable where Target: Cacheable> {

case notLoaded(Target)
Expand Down Expand Up @@ -91,4 +91,4 @@ protocol Cacheable {
/// A key used for identification in a cache
var cacheIdentifier: String { get }

}
}
14 changes: 13 additions & 1 deletion APIClient/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,26 @@
//

import UIKit
import Moya

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?


/// The SWAPI Provider representing the Server
let swAPI = MoyaProvider<SWAPI>()


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

if let starwarsViewController = (window?.rootViewController as? UINavigationController)?.topViewController as? SWViewController {

// Pass the SWAPI Provider on to the root view controller
starwarsViewController.swAPI = swAPI

}

return true
}

Expand Down
85 changes: 59 additions & 26 deletions APIClient/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,44 +1,77 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<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="E10-YL-lxp">
<<<<<<< HEAD
<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="E10-YL-lxp">
Copy link
Member

@nilsvu nilsvu May 30, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bei dem Merge sind hier offenbar Konflikte aufgetreten, die musst du noch beheben. Einfach die .storyboard Datei in einem Texteditor öffnen und bei diesen Konflikt-Markierungen den oberen oder unteren Teil löschen, je nach dem was du behalten willst.
Einfacher wär's vielleicht sogar das Repository nochmal zu klonen und deine Dateien dort rein zu ziehen ;)

=======
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10116" systemVersion="15E65" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
>>>>>>> pokedex
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
</dependencies>
<scenes>
<!--Tabel View Controller-->
<scene sceneID="BhY-Tf-hbW">
<objects>
<tableViewController id="I2N-vN-JyT" customClass="SWTabelViewController" customModule="APIClient" customModuleProvider="target" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" id="afX-7l-FKq">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="Cell" textLabel="z52-Kc-dvv" detailTextLabel="MmQ-p9-Suq" style="IBUITableViewCellStyleValue1" id="hak-we-ati" customClass="SWPlanetsTableViewCell" customModule="APIClient" customModuleProvider="target">
<rect key="frame" x="0.0" y="92" width="600" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="hak-we-ati" id="a0A-OM-Lg3">
<rect key="frame" x="0.0" y="0.0" width="600" height="43"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="z52-Kc-dvv">
<rect key="frame" x="15" y="12" width="32" height="20"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Detail" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="MmQ-p9-Suq">
<rect key="frame" x="543" y="12" width="42" height="20"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<color key="textColor" red="0.55686274509803924" green="0.55686274509803924" blue="0.57647058823529407" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
<accessibility key="accessibilityConfiguration" identifier="Cell"/>
</tableViewCell>
</prototypes>
<connections>
<outlet property="dataSource" destination="I2N-vN-JyT" id="BPT-IH-Spw"/>
<outlet property="delegate" destination="I2N-vN-JyT" id="RY6-hL-i07"/>
</connections>
</tableView>
<navigationItem key="navigationItem" id="6RB-g8-Nrl"/>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="EPB-U2-OgQ" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="2575" y="388"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="Xrb-yS-kMZ">
<scene sceneID="1ak-lJ-4VT">
<objects>
<navigationController id="E10-YL-lxp" sceneMemberID="viewController">
<navigationBar key="navigationBar" contentMode="scaleToFill" id="amJ-5H-qs5">
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="q66-ie-KW5" sceneMemberID="viewController">
<toolbarItems/>
<navigationBar key="navigationBar" contentMode="scaleToFill" id="Rf9-m1-zrX">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<nil name="viewControllers"/>
<connections>
<segue destination="rPr-Fp-ALE" kind="relationship" relationship="rootViewController" id="g8j-CJ-uaE"/>
<segue destination="I2N-vN-JyT" kind="relationship" relationship="rootViewController" id="UMs-dC-BNe"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="hfS-9i-aMM" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-658" y="301"/>
</scene>
<!--View Controller-->
<scene sceneID="adh-8k-Iuh">
<objects>
<viewController id="rPr-Fp-ALE" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="pj8-zF-1z6"/>
<viewControllerLayoutGuide type="bottom" id="kt2-9S-3TK"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="rEB-Za-Zhx">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</view>
<navigationItem key="navigationItem" id="CZR-l9-xMg"/>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="OaC-W5-AeM" userLabel="First Responder" sceneMemberID="firstResponder"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="two-VQ-G1P" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="65" y="301"/>
<point key="canvasLocation" x="1763" y="388"/>
</scene>
</scenes>
</document>
11 changes: 11 additions & 0 deletions APIClient/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>pokeapi.co</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
</dict>
</dict>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
Expand Down
70 changes: 70 additions & 0 deletions APIClient/SWAPI.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//SWAPI
// APIClient

import Foundation
import Moya
import Freddy



/// The abstraction of the [SWAPI](http://swapi.co) REST API.
enum SWAPI: Moya.TargetType {


/// MARK: Endpoints

case planets (NamedResource<SWPlanet>)
case planets_id (NamedResource<SWPlanet>)
case planets_schema (NamedResource<SWPlanet>)


// MARK: Network Abstraction

var baseURL: NSURL { return NSURL(string: "http://swapi.co/api")! }

var path: String {
switch self {
case .planets(let namedResource): return "/planets/\(namedResource.name)"
case .planets_id(let namedResource): return "/planets_id/\(namedResource)"
case .planets_schema(let namedResource): return "/planets_schema/\(namedResource)"
}
}

var method: Moya.Method { return .GET }

var parameters: [String : AnyObject]? {
switch self {
default: return nil
}
}

// TODO: Provide sample data for testing
var sampleData: NSData {
switch self {
default: return "".dataUsingEncoding(NSUTF8StringEncoding)!
}
}
}

struct NamedResource<Resource: Freddy.JSONDecodable>: Freddy.JSONDecodable {

let name: String

init(name: String) {
self.name = name
}

init(json: JSON) throws {
self.name = try json.string("name")
}

}









16 changes: 16 additions & 0 deletions APIClient/SWView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// SWView.swift
// APIClient
//
// Created by Felix Meissner on 5/29/16.
// Copyright © 2016 iOS Dev Kurs Universität Heidelberg. All rights reserved.
//

import Foundation
import UIKit

class SWPlanetsTableViewCell: UITableViewCell {



}
68 changes: 68 additions & 0 deletions APIClient/SWViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@

// Created by Nils Fischer on 22.05.16.
// Copyright © 2016 iOS Dev Kurs Universität Heidelberg. All rights reserved.
//

import UIKit
import Moya



class SWViewController: UITableViewController, UITextFieldDelegate {

/// The SWAPI provider that handles requests for server resources
var swAPI: MoyaProvider<SWAPI>!


@IBOutlet var Laden: UIButton!
@IBOutlet var Textfeld: UITextField!


override func viewDidLoad() {
super.viewDidLoad()

// Handle the text field’s user input through delegate callbacks.
Textfeld.delegate = self
}


// MARK: Actions

@IBAction func PerformRequest(sender: UIButton) {
swAPI.request(swAPI) {result in
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Die request Methode nimmt ein Case des SWAPI Enums an, also z.B.:

swAPI.request(.planets(NamedResource(name: "1"))) {result in // ...

switch result {
case .Success(let response):
do {
try response.filterSuccessfulStatusCodes()
print(response)
let json = try JSON (data: reponse.data)
} catch {
print(error)
}
case .Failure(let error):
print(error)
}
}




}
}

extension SWViewController {
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 0
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath)
return cell
}

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

}
}


Loading