Created
February 19, 2020 04:04
-
-
Save jsoneaday/a9aaea124b30959035643a61a032a1e6 to your computer and use it in GitHub Desktop.
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
// | |
// ContentView.swift | |
// dzhaven-client-swift | |
// | |
// Created by David Choi on 2/16/20. | |
// Copyright © 2020 David Choi. All rights reserved. | |
// | |
import SwiftUI | |
extension String: Identifiable { | |
public var id: String { self } | |
} | |
struct ContentView: View { | |
@ObservedObject private var launchData: LaunchListData = LaunchListData() | |
var body: some View { | |
return List(launchData.sites) { site in | |
Text(site) | |
} | |
} | |
} | |
struct ContentView_Previews: PreviewProvider { | |
static var previews: some View { | |
ContentView() | |
} | |
} | |
class LaunchListData: ObservableObject { | |
@Published var sites: [String] | |
init() { | |
print("running loadData") | |
self.sites = [String]() | |
loadData() | |
} | |
func loadData() { | |
Network.shared.apollo.fetch(query: LaunchListQuery()) { result in | |
switch result { | |
case .success(let graphQLResult): | |
for launch in graphQLResult.data!.launches.launches { | |
if launch != nil { | |
if launch!.site != nil { | |
self.sites.append(launch!.site!) | |
} | |
} | |
} | |
print("Success! Result: \(String(describing: self.sites))") | |
case .failure(let error): | |
print("Failure! Error: \(error)") | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment