Skip to content

Instantly share code, notes, and snippets.

class FeedViewController: BaseViewController {
//...
override func viewDidLoad() {
super.viewDidLoad()
setupViews()
setupBindings()
sessionDidUpdate(appCoordinator.session)
}
import Foundation
protocol Reversible {
var isOn: Bool { get set }
mutating func reverse()
func reversed() -> Self
}
extension Reversible {
/// Represents a user action which reacts to something
struct Reaction {
let type: ReactionType
let target: ReactionTarget
var isOn: Bool
}
enum ReactionType: String, Decodable {
case heart
case unsupported
import Foundation
class Cache<T> {
private var dict: [String: T] = [:]
var didSetHandler: ((_ key: String, _ value: T) -> Void)?
func clear() {
dict.removeAll()
}
func perform(followAction: FollowAction,
cache: Cache<FanClub>,
updateHandler: @escaping (_ isRevertOnFailure: Bool) -> Void) {
// update cache optimistically
let originalFanClub = cache.value(for: followAction.fanClubId)
if let updatedFanClub = originalFanClub?.updated(with: followAction) {
cache.set(updatedFanClub, for: followAction.fanClubId)
}
updateHandler(false)
lastFollowActionUpdatedAt = Date()
import UIKit
import Lottie
protocol LikeSwitchDelegate: class {
func likeSwitch(_ likeSwitch: LikeSwitch, didToggle isSelected: Bool)
}
class LikeSwitch: UIView {
weak var delegate: LikeSwitchDelegate?
getPokemonList(
success: { data in
self.update(data: data)
return KotlinUnit()
}, failure: {
self.handleError($0?.message)
return KotlinUnit()
})
getPokemonList(
success: { data in
self.update(data: data)
return KotlinUnit()
}, failure: {
self.handleError($0?.message)
return KotlinUnit()
})
class PokeApi {
fun getPokemonList(success: (List<PokemonEntry>) -> Unit, failure: (Throwable?) -> Unit) {
...
}
}