-
Notifications
You must be signed in to change notification settings - Fork 14
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
Fehler #2
Open
DenKlei
wants to merge
16
commits into
iOS-Dev-Kurs:master
Choose a base branch
from
DenKlei:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+323
−8
Open
Fehler #2
Changes from 4 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
c416396
init fehlt
7a68b41
Fehler2
9ec8690
funktioniert
a7d898b
constraints
2050977
Funktioniert
8d49d39
init fehlt
1de14b2
Fehler2
3b0f943
funktioniert
acec4a9
constraints
f819fac
Funktioniert
67b3c05
Erste Tests
0a09f47
Test
9f88b32
StartTag
f10bd5a
Behoben
0ee5227
Erste Tests
fd515c4
Mehr
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// Planet.swift | ||
// APIClient | ||
// | ||
// Created by Kleimaier, Dennis on 23.05.16. | ||
// Copyright © 2016 iOS Dev Kurs Universität Heidelberg. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import Freddy | ||
|
||
struct Planet: JSONDecodable { | ||
|
||
let name: String | ||
|
||
init(json: JSON) throws { | ||
self.name = try json.string("name") | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// | ||
// PlanetAPI.swift | ||
// APIClient | ||
// | ||
// Created by Kleimaier, Dennis on 23.05.16. | ||
// Copyright © 2016 iOS Dev Kurs Universität Heidelberg. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import Moya | ||
import Freddy | ||
|
||
enum PlanetAPI: Moya.TargetType{ | ||
case planet(NamedResource<Planet>) | ||
|
||
var baseURL: NSURL { return NSURL(string: "http://swapi.co/api")! } | ||
|
||
var path: String { | ||
switch self{ | ||
case .planet(let namedResource): return "/planets/(namedResource)" | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hier fehlt ein case .planet(let namedResource): return "/planets/\(namedResource.name)" |
||
} | ||
|
||
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") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// | ||
// PlanetViewController.swift | ||
// APIClient | ||
// | ||
// Created by Kleimaier, Dennis on 23.05.16. | ||
// Copyright © 2016 iOS Dev Kurs Universität Heidelberg. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import Moya | ||
import Freddy | ||
|
||
class PlanetViewController: UIViewController { | ||
|
||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
} | ||
|
||
var planetAPI: MoyaProvider<PlanetAPI>! | ||
var planet: Planet? { | ||
didSet { | ||
self.planetLab.text = planet?.name | ||
} | ||
} | ||
|
||
|
||
@IBOutlet weak var searchField: UITextField! | ||
@IBOutlet weak var planetLab: UILabel! | ||
|
||
|
||
func loadPlanet(planet: NamedResource<Planet>){ | ||
planetAPI.request(.planet(planet)){ result in | ||
switch result { | ||
case .Success(let response): | ||
do { | ||
try response.filterSuccessfulStatusCodes() | ||
// Try to parse the response to JSON | ||
let json = try JSON(data: response.data) | ||
// Try to decode the JSON to the required type | ||
let pokemonSpecies = try Planet(json: json) | ||
// Configure view according to model | ||
self.planet = pokemonSpecies | ||
print(pokemonSpecies) | ||
} catch { | ||
print(error) | ||
} | ||
case .Failure(let error): | ||
print(error) | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
func textFieldShouldReturn(textField: UITextField) -> Bool { | ||
guard let name = textField.text else { | ||
return true | ||
} | ||
self.loadPlanet(NamedResource(name: name)) | ||
return true | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Du kannst hier auch eine
NamedResource<Planet>
statt einesname: String
als Associated Value verwenden, damit wird die API noch besser modelliert ;)