-
Notifications
You must be signed in to change notification settings - Fork 14
Fehler #2
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
base: master
Are you sure you want to change the base?
Fehler #2
Changes from 13 commits
c416396
7a68b41
9ec8690
a7d898b
2050977
8d49d39
1de14b2
3b0f943
acec4a9
f819fac
67b3c05
0a09f47
9f88b32
f10bd5a
0ee5227
fd515c4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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") | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| // | ||
| // 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>) | ||
|
|
||
|
Member
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. Du kannst hier auch eine |
||
| var baseURL: NSURL { return NSURL(string: "http://swapi.co/api")! } | ||
|
|
||
| var path: String { | ||
| switch self{ | ||
| case .planet(let namedResource): return "/planets/\(namedResource.name)" | ||
| } | ||
|
Member
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 { | ||
| case .planet(let namedResource): return "{\"planets\": \"\(namedResource.name)\",\"planets\":\"Tatooine\"}".dataUsingEncoding(NSUTF8StringEncoding)! | ||
| 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") | ||
| } | ||
| } | ||
| 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 | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.
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.
Dies sind Konflikt-Marker von Git nach einem Merge. Öffne das Storyboard in einem Texteditor und entferne die Marker und damit die Konflikte ;) https://githowto.com/resolving_conflicts