Skip to content

Instantly share code, notes, and snippets.

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()
})
import UIKit
import Lottie
protocol LikeSwitchDelegate: class {
func likeSwitch(_ likeSwitch: LikeSwitch, didToggle isSelected: Bool)
}
class LikeSwitch: UIView {
weak var delegate: LikeSwitchDelegate?
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 Foundation
class Cache<T> {
private var dict: [String: T] = [:]
var didSetHandler: ((_ key: String, _ value: T) -> Void)?
func clear() {
dict.removeAll()
}
/// 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
protocol Reversible {
var isOn: Bool { get set }
mutating func reverse()
func reversed() -> Self
}
extension Reversible {
class FeedViewController: BaseViewController {
//...
override func viewDidLoad() {
super.viewDidLoad()
setupViews()
setupBindings()
sessionDidUpdate(appCoordinator.session)
}
import Foundation
import UIKit
/// A model representing a navigation destination.
indirect enum Navigation {
case tab(type: TabType)
case post(id: String, partialPost: PartialPost?, fetcher: FeedFetcher?)
case feed(parameter: FeedParameter)
case safari(url: URL)
case applicationOpen(url: URL)