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

input error #7

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

/* Begin PBXBuildFile section */
078B558C6C77F3C6DCDC4678 /* Pods_APIClientUITests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 82531BA6D6228998A00AB5B6 /* Pods_APIClientUITests.framework */; };
1652B9AB1D05E48F00443CF1 /* SearchViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1652B9AA1D05E48F00443CF1 /* SearchViewController.swift */; };
1652B9AD1D05E67F00443CF1 /* InformationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1652B9AC1D05E67F00443CF1 /* InformationViewController.swift */; };
1652B9AF1D05E81F00443CF1 /* SWAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1652B9AE1D05E81F00443CF1 /* SWAPI.swift */; };
1652B9B11D05EBDF00443CF1 /* Peoples.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1652B9B01D05EBDF00443CF1 /* Peoples.swift */; };
872A275C1CF0D87100A988C4 /* APIResource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 872A275B1CF0D87100A988C4 /* APIResource.swift */; };
874D06591CEF295E009A494D /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 874D06581CEF295E009A494D /* AppDelegate.swift */; };
874D065E1CEF295E009A494D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 874D065C1CEF295E009A494D /* Main.storyboard */; };
Expand Down Expand Up @@ -35,6 +39,10 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
1652B9AA1D05E48F00443CF1 /* SearchViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SearchViewController.swift; sourceTree = "<group>"; };
1652B9AC1D05E67F00443CF1 /* InformationViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InformationViewController.swift; sourceTree = "<group>"; };
1652B9AE1D05E81F00443CF1 /* SWAPI.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SWAPI.swift; sourceTree = "<group>"; };
1652B9B01D05EBDF00443CF1 /* Peoples.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Peoples.swift; sourceTree = "<group>"; };
198B23CD94C6D84016A5208A /* Pods-APIClientUITests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-APIClientUITests.release.xcconfig"; path = "Pods/Target Support Files/Pods-APIClientUITests/Pods-APIClientUITests.release.xcconfig"; sourceTree = "<group>"; };
4FFA0A7AA37697BD5CBC3211 /* Pods_APIClientTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_APIClientTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
65C820A0F52E3181871F5ECA /* Pods-APIClientTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-APIClientTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-APIClientTests/Pods-APIClientTests.release.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -88,6 +96,8 @@
872A27571CF0D4E200A988C4 /* View Controller */ = {
isa = PBXGroup;
children = (
1652B9AA1D05E48F00443CF1 /* SearchViewController.swift */,
1652B9AC1D05E67F00443CF1 /* InformationViewController.swift */,
);
name = "View Controller";
sourceTree = "<group>";
Expand All @@ -103,6 +113,8 @@
isa = PBXGroup;
children = (
872A275B1CF0D87100A988C4 /* APIResource.swift */,
1652B9B01D05EBDF00443CF1 /* Peoples.swift */,
1652B9AE1D05E81F00443CF1 /* SWAPI.swift */,
);
name = Model;
sourceTree = "<group>";
Expand Down Expand Up @@ -468,8 +480,12 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
1652B9AB1D05E48F00443CF1 /* SearchViewController.swift in Sources */,
872A275C1CF0D87100A988C4 /* APIResource.swift in Sources */,
874D06591CEF295E009A494D /* AppDelegate.swift in Sources */,
1652B9AF1D05E81F00443CF1 /* SWAPI.swift in Sources */,
1652B9B11D05EBDF00443CF1 /* Peoples.swift in Sources */,
1652B9AD1D05E67F00443CF1 /* InformationViewController.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
14 changes: 0 additions & 14 deletions APIClient/APIResource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,6 @@ import Freddy
import AwesomeCache



/**
Representation for a resource that may or may not be loaded yet.

It is based on two generic types:

- The `Target` is a `Moya.TargetType` that abstracts the API. It must also be `Cacheable` so that responses can be cached.
- The `Resource` is a `Freddy.JSONDecodable` type so that responses from the API can be directly parsed to JSON and decoded to the expected type.

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 All @@ -34,7 +21,6 @@ enum APIResource<Target: Moya.TargetType, Resource: Freddy.JSONDecodable where T

}


// MARK: - Requesting Resources

extension MoyaProvider where Target: Cacheable {
Expand Down
11 changes: 11 additions & 0 deletions APIClient/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,27 @@
//

import UIKit
import Moya

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

let swAPI = MoyaProvider<SWAPI>()


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

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

SearchViewController.starWarsAPI = swAPI

}

return true
}


}

102 changes: 99 additions & 3 deletions APIClient/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,120 @@
</objects>
<point key="canvasLocation" x="-658" y="301"/>
</scene>
<!--View Controller-->
<!--Search View Controller-->
<scene sceneID="adh-8k-Iuh">
<objects>
<viewController id="rPr-Fp-ALE" sceneMemberID="viewController">
<viewController id="rPr-Fp-ALE" customClass="SearchViewController" customModule="APIClient" customModuleProvider="target" 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"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" ambiguous="YES" misplaced="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="H5e-9H-f5E">
<rect key="frame" x="285" y="360" width="30" height="30"/>
<state key="normal" title="Go!"/>
<connections>
<action selector="buttonLoad:" destination="rPr-Fp-ALE" eventType="touchUpInside" id="bZ7-Mp-YNV"/>
</connections>
</button>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" ambiguous="YES" misplaced="YES" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="Insert number" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="HlY-os-WRA">
<rect key="frame" x="213" y="310" width="175" height="30"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
</textField>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" ambiguous="YES" misplaced="YES" text="Search figure: " textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Zd2-af-zuT">
<rect key="frame" x="244" y="270" width="112" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="H5e-9H-f5E" firstAttribute="centerX" secondItem="rEB-Za-Zhx" secondAttribute="centerX" id="505-p9-PEk"/>
<constraint firstItem="H5e-9H-f5E" firstAttribute="top" secondItem="HlY-os-WRA" secondAttribute="bottom" constant="20" id="DBB-1o-Z3f"/>
<constraint firstItem="HlY-os-WRA" firstAttribute="centerX" secondItem="rEB-Za-Zhx" secondAttribute="centerX" id="sNM-Ql-U1b"/>
<constraint firstItem="HlY-os-WRA" firstAttribute="top" secondItem="Zd2-af-zuT" secondAttribute="bottom" constant="20" id="sej-7h-Vkx"/>
<constraint firstItem="Zd2-af-zuT" firstAttribute="centerX" secondItem="rEB-Za-Zhx" secondAttribute="centerX" id="su2-iS-b8o"/>
</constraints>
</view>
<navigationItem key="navigationItem" id="CZR-l9-xMg"/>
<connections>
<outlet property="searchTextfield" destination="HlY-os-WRA" id="6zD-aD-aZt"/>
<segue destination="SkG-HW-Kyf" kind="show" identifier="showInformation" id="wZl-5V-tI7"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="OaC-W5-AeM" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="65" y="301"/>
<point key="canvasLocation" x="63" y="309"/>
</scene>
<!--Information-->
<scene sceneID="g9j-q7-1Lp">
<objects>
<viewController id="SkG-HW-Kyf" customClass="InformationViewController" customModule="APIClient" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="HCN-TO-2hY"/>
<viewControllerLayoutGuide type="bottom" id="77T-GC-sEA"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="Ayt-9A-wyw">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<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="agG-SY-bO5">
<rect key="frame" x="279" y="338" width="42" height="21"/>
<constraints>
<constraint firstAttribute="height" constant="21" id="KJG-2i-bsP"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<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="uLe-Nd-Hwz">
<rect key="frame" x="279" y="389" width="42" height="22"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<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="sTS-QZ-gco">
<rect key="frame" x="279" y="441" width="42" height="21"/>
<constraints>
<constraint firstAttribute="height" constant="21" id="zqI-3S-OTE"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<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="f9S-EJ-Ui6">
<rect key="frame" x="279" y="289" width="42" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="agG-SY-bO5" firstAttribute="centerX" secondItem="Ayt-9A-wyw" secondAttribute="centerX" id="Gau-JU-8XY"/>
<constraint firstItem="sTS-QZ-gco" firstAttribute="centerX" secondItem="Ayt-9A-wyw" secondAttribute="centerX" id="Qzl-aC-ZND"/>
<constraint firstItem="f9S-EJ-Ui6" firstAttribute="centerX" secondItem="Ayt-9A-wyw" secondAttribute="centerX" id="coU-Be-yUu"/>
<constraint firstItem="uLe-Nd-Hwz" firstAttribute="centerX" secondItem="Ayt-9A-wyw" secondAttribute="centerX" id="rJc-IG-RTo"/>
</constraints>
</view>
<navigationItem key="navigationItem" title="Information" id="X9Z-Wr-UBC">
<barButtonItem key="backBarButtonItem" title="Search" id="zWv-Wr-alx"/>
</navigationItem>
<connections>
<outlet property="gender" destination="agG-SY-bO5" id="oi7-Fd-YDI"/>
<outlet property="height" destination="uLe-Nd-Hwz" id="XYz-al-jbs"/>
<outlet property="mass" destination="sTS-QZ-gco" id="3aI-us-Mnh"/>
<outlet property="name" destination="f9S-EJ-Ui6" id="Uk3-lK-OU2"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="oFh-Wr-2KY" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="752" y="309"/>
</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>swapi.co</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
</dict>
</dict>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
Expand Down
41 changes: 41 additions & 0 deletions APIClient/InformationViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// InformationViewController.swift
// APIClient
//
// Created by logosal mac on 06.06.16.
// Copyright © 2016 iOS Dev Kurs Universität Heidelberg. All rights reserved.
//


import Foundation
import UIKit
import Freddy
import Moya
import AlamofireImage


class InformationViewController: UIViewController {

var peoples : SWPeoples?

@IBOutlet weak var name: UILabel!

@IBOutlet weak var gender: UILabel!

@IBOutlet weak var height: UILabel!

@IBOutlet weak var mass: UILabel!

override func viewDidLoad() {
super.viewDidLoad()
name.text = peoples?.name
gender.text = peoples?.gender
height.text = peoples?.height
mass.text = peoples?.mass

}


}


33 changes: 33 additions & 0 deletions APIClient/Peoples.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// Peoples.swift
// APIClient
//
// Created by logosal mac on 06.06.16.
// Copyright © 2016 iOS Dev Kurs Universität Heidelberg. All rights reserved.
//

import Foundation
import Freddy
import UIKit

// Informationen über Figur

struct SWPeoples: JSONDecodable {

let name: String
let gender: String
let height: String
let mass: String


// Durchsucht Datei von API nach Schlagwörtern

init(json: JSON) throws {
self.name = try json.string("name")
self.gender = try json.string("gender")
self.height = try json.string("height")
self.mass = try json.string("mass")

}

}
61 changes: 61 additions & 0 deletions APIClient/SWAPI.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//
// SWAPI.swift
// APIClient
//
// Created by logosal mac on 06.06.16.
// Copyright © 2016 iOS Dev Kurs Universität Heidelberg. All rights reserved.
//

import Foundation
import Moya
import Freddy


enum SWAPI: Moya.TargetType, Cacheable {

case people(id: Int)

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

var path: String {
switch self {
case .people(let id): return "/people/\(id)/"
}
}

var method: Moya.Method { return .GET }

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

var sampleData: NSData {
switch self {
default: return "".dataUsingEncoding(NSUTF8StringEncoding)!
}
}

var cacheIdentifier: String {
return self.path
}


}

// Represents a resource provided by the SWAPI by its name

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")
}

}
Loading