This file contains hidden or 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
extension URLSession { | |
func send<T: Decodable>(_ request: URLRequest, | |
completion: @escaping ((Result<T, Error>) -> Void)) { | |
let task = dataTask(with: request) { (data, response, error) in | |
if let data = data { | |
do { | |
let decoded = try JSONDecoder().decode(T.self, from: data) | |
completion(.success(decoded)) | |
} | |
catch let error { |
This file contains hidden or 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
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) | |
} |
This file contains hidden or 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
# 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 -' |
This file contains hidden or 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
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| |
This file contains hidden or 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
class ArticleView: UIView { | |
var totalCommentCount: Int = 0 { | |
didSet { | |
setNeedsLayout() | |
} | |
} | |
var hasComment: Bool = false { | |
didSet { |
This file contains hidden or 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
import Foundation | |
final class DiscoverCategoryFetcher: PagedResponseFetcher<PaginationParameter, DiscoverCategoryResponse, DiscoverCategory> { | |
} |
This file contains hidden or 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
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 |
This file contains hidden or 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
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() }() |
This file contains hidden or 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
@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 ?? [] { |