Skip to content

Instantly share code, notes, and snippets.

struct UserSettings: Codable {
let someBool: Bool
let someDate: Date
}
var userSettings: UserSettings? {
get {
guard let data = UserDefaults.standard.object(forKey: "userSettings") as? Data else { return nil }
return try? JSONDecoder().decode(UserSettings.self, from: data)
}
@hlung
hlung / git-commit-auto-msg
Last active November 6, 2019 07:23
Do git add and commit with auto generated message. For laziness reasons 😂.
# Do git add and commit with auto generated message. For laziness reasons 😂.
# It simply reads `git status -s`, converts the beginning M -> Update, A -> Add, and D -> Delete, and use it as a commit message.
# Example:
# git status: M updated.txt
# generated message: Update updated.txt
#
# For debugging sed part:
# echo "M updated.txt\nA added.txt\nD deleted.txt\nR events/BaseEvents.yml -> events/AppEvents.yml" | sed "s/^M /Update/;s/^A /Add/;s/^D /Delete/;s/^R /Rename/;s/->/to/"
alias gaca='git add .; git status -s | sed "s/^M /Update/;s/^A /Add/;s/^D /Delete/;s/^R /Rename/;s/->/to/" | git commit --file -'
lane :replace_podspec_version do |options|
# Input file (content) => "s.version = '0.1.0'"
# Input new_version => "0.2.0"
# Output file (content) => "s.version = '0.2.0'"
# Note: For debugging, you can remove -i to make it print output to console without editing file in place.
# Somehow backup file *.bak has to be created for edit in-place (-i) option, otherwise sed command will fail.
sh("cd ..; sed -i bk \"s/\\(s.version.*['\\\"]\\).*\\(['\\\"]\\)/\\1#{options[:new_version]}\\2/g\" #{options[:file]}")
end
lane :get_podspec_version do |options|
class ArticleView: UIView {
var totalCommentCount: Int = 0 {
didSet {
setNeedsLayout()
}
}
var hasComment: Bool = false {
didSet {
import Foundation
final class DiscoverCategoryFetcher: PagedResponseFetcher<PaginationParameter, DiscoverCategoryResponse, DiscoverCategory> {
}
import Foundation
protocol Pageable {
/// Moves the receiver's value to next set
mutating func next(cursor: String?)
}
// Represents a paged response from API.
protocol PagedResponse {
associatedtype Element
import Foundation
import RxSwift
import RxCocoa
class SimplifiedPagedResponseFetcher<LoaderInput, LoaderOutput>
where LoaderInput: Pageable, LoaderOutput: PagedResponse {
/// The main actor here 🤘. Sends all the Elements currently available.
let elementsRelay = BehaviorRelay<[LoaderOutput.Element]>(value: [])
lazy var elements: Driver<[LoaderOutput.Element]> = { return elementsRelay.asDriver() }()
@discardableResult func perform(_ navigation: Navigation) -> Bool {
guard let navigationController = currentNavigationController() else { return false }
// Check first if we can perform the navigation.
let currentNavigation = (navigationController.visibleViewController as? NavigationSource)?.sourceNavigation
let nextNavigation = navigation.redirectIfNeeded(from: currentNavigation)
switch nextNavigation {
case .tab(let tabType):
for viewController in tabBarController.viewControllers ?? [] {
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)
class FeedViewController: BaseViewController {
//...
override func viewDidLoad() {
super.viewDidLoad()
setupViews()
setupBindings()
sessionDidUpdate(appCoordinator.session)
}