Created
February 26, 2019 01:49
-
-
Save beachead/44817f915db218d38e36da4a75d62c7c to your computer and use it in GitHub Desktop.
Ios / AppSync
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
// | |
// ViewController.swift | |
// GraphQL | |
// | |
// Created by Geoff on 2/25/19. | |
// Copyright © 2019 Beachead Technologies Inc. All rights reserved. | |
// | |
import UIKit | |
import AWSAppSync | |
class BaseTableViewController<T: UITableViewCell>: UITableViewController { | |
let cellId = "cellId" | |
var items = [Any]() | |
var appSyncClient: AWSAppSyncClient? | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
print("got here.1") | |
// Reference AppSync client for App Delegate | |
let appDelegate = UIApplication.shared.delegate as! AppDelegate | |
appSyncClient = appDelegate.appSyncClient | |
print("got here!2") | |
print("fetching data...3") | |
appSyncClient?.fetch (query: ListInstructorsQuery(), cachePolicy: .returnCacheDataAndFetch) { (result, error) in | |
if error != nil { | |
print(error?.localizedDescription ?? "error") | |
return | |
} | |
print("hi") | |
// Line 41 is where I'm having issues... | |
result?.data?.listInstructors?.items!.forEach { print(($0?.file)! + " " + ($0?.id)!) } | |
} | |
tableView.register(T.self, forCellReuseIdentifier: cellId) | |
} | |
override func tableView(_ tableView: UITableView, | |
numberOfRowsInSection section: Int) -> Int { | |
return items.count | |
} | |
override func tableView(_ tableView: UITableView, cellForRowAt IndexPath: IndexPath) -> UITableViewCell { | |
let cell = tableView.dequeueReusableCell(withIdentifier: cellId, for: IndexPath) as! BaseCell | |
cell.item = self.items[IndexPath.row] | |
return cell | |
} | |
} | |
class BaseCell: UITableViewCell { | |
var item: Any! { | |
didSet { | |
textLabel?.text = item as? String | |
} | |
} | |
} | |
class SomeListController: BaseTableViewController<BaseCell> { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
items = ["hello", "world", "awesome"] | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment