Skip to content

Instantly share code, notes, and snippets.

@jsoneaday
Created February 19, 2020 04:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsoneaday/a9aaea124b30959035643a61a032a1e6 to your computer and use it in GitHub Desktop.
Save jsoneaday/a9aaea124b30959035643a61a032a1e6 to your computer and use it in GitHub Desktop.
//
// 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