Skip to content

Instantly share code, notes, and snippets.

View koromiko's full-sized avatar

Shih Ting Huang (Neo) koromiko

View GitHub Profile
enum RequestError: Error {
case apiError(reason: String)
}
class AsyncJokeGenerator: AsyncSequence {
__consuming func makeAsyncIterator() -> AsyncIterator {
return AsyncIterator(numberOfJokes: numberOfJokes)
}
typealias Element = String
import SwiftUI
import UIKit
import Foundation
import Combine
enum RequestError: Error {
case apiError(reason: String)
}
class ResultController: ObservableObject {
typealias JSON = [String: Any]
/// Helper for getting value from nested json dictionary
extension JSON {
/// Get the value of the given keypath.
/// - Parameter Path: The keypath separated by "."
/// - Returns: The value of the specified keypath. Return `nil` if the value is not found.
public subscript<T>(path path: String) -> T? {
get {
var dic: JSON? = self
let keyPaths = path.split(separator: ".").map { String($0) }
func package(config: Configuration) {
}
private var cellViewModels: [PhotoListCellViewModel] = [PhotoListCellViewModel]() {
didSet {
self.reloadTableViewClosure?()
}
}
var numberOfCells: Int {
return cellViewModels.count
}
func getCellViewModel( at indexPath: IndexPath ) -> PhotoListCellViewModel
class PhotoListViewModel {
let apiService: APIServiceProtocol
init( apiService: APIServiceProtocol = APIService()) {
self.apiService = apiService
}
func initFetch() {
self.isLoading = true
apiService.fetchPopularPhoto { [weak self] (success, photos, error) in
import PlaygroundSupport
import SwiftUI
enum MoveAction: String {
case left
case right
case up
case down
var systemImageName: String {
return "arrow.\(self.rawValue)"
func initStubs() {
func insertTodoItem( name: String, finished: Bool ) -> ToDoItem? {
let obj = NSEntityDescription.insertNewObject(forEntityName: "ToDoItem", into: mockPersistantContainer.viewContext)
obj.setValue(name, forKey: "name")
obj.setValue(finished, forKey: "finished")
return obj as? ToDoItem
}
#if PROD
print(“We brew beer in the Production”)
#elseif STG
print(“We brew beer in the Staging”)
#endif
exportOptions: [
"signingStyle": "manual",
"provisioningProfiles": [config.appIdentifier: config.provisioningProfile] ]