Skip to content

Instantly share code, notes, and snippets.

@vinhnx
vinhnx / Fastfile
Created Sep 30, 2019
advance Fastfile config
View Fastfile
# This file contains the fastlane.tools configuration
# You can find the documentation at https://docs.fastlane.tools
#
# For a list of all available actions, check out
#
# https://docs.fastlane.tools/actions
#
# Uncomment the line if you want fastlane to automatically update itself
# update_fastlane
@vinhnx
vinhnx / Mocking.swift
Created Sep 18, 2019
Mocking in Swift
View Mocking.swift
// mocking in swift
// reference: https://www.vadimbulavin.com/real-world-unit-testing-in-swift/
struct User {}
class AuthService {
var client: HTTPClient
// init
init(_ client: HTTPClient) {
@vinhnx
vinhnx / GitHubAPISingle.swift
Created Aug 20, 2019
Simple RxSwift's usage of Single for async network events
View GitHubAPISingle.swift
enum GitHubAPIError: Error {
case userIsEmpty
case invalidData
}
func fetchGithubUser(_ user: String) -> Single<[String: Any]> {
guard user.isEmpty == false else { return Single.error(GitHubAPIError.userIsEmpty) }
return Single<[String: Any]>.create(subscribe: { completion in
let task = URLSession.shared
.dataTask(with: URLRequest(url: URL(string: "https://api.github.com/users/\(user)")!), completionHandler: { data, _, error in
@vinhnx
vinhnx / Codable+Extension.swift
Last active Jul 9, 2019
decode Swift enum and Date for Codable properties
View Codable+Extension.swift
import Foundation
protocol AssetTypeConvertible {
// conformer just need to declare conformance to `AssetTypeConvertible` and will be auto inferred as generic `Value`
// and Xcode auto completion just works
// see AssetType below
associatedtype Value = Self
static func convertToEnum(from rawValue: String) -> Value
}
@vinhnx
vinhnx / .swiftlint.yml
Last active Jul 5, 2019
my .swiftlint.yml configuration
View .swiftlint.yml
disabled_rules: # rule identifiers to exclude from running
- line_length
- todo
- trailing_whitespace
- identifier_name
- void_return
- colon
- notification_center_detachment
- discarded_notification_center_observer
- type_name
@vinhnx
vinhnx / RemoteImageLoader.swift
Last active Jul 3, 2019
simple remote image loader
View RemoteImageLoader.swift
import Foundation
import UIKit
typealias DataMemoryCache = NSCache<NSString, NSData>
class ImageCache: DataMemoryCache {
static let shared: DataMemoryCache = {
let cache = DataMemoryCache()
cache.name = "ImageCache"
cache.countLimit = 20 // 20 items
@vinhnx
vinhnx / tmux.md
Created Jul 3, 2019 — forked from andreyvit/tmux.md
tmux cheatsheet
View tmux.md

tmux cheat sheet

(C-x means ctrl+x, M-x means alt+x)

Prefix key

The default prefix is C-b. If you (or your muscle memory) prefer C-a, you need to add this to ~/.tmux.conf:

# remap prefix to Control + a
View SwiftUI Property Delegates.swift
/// `ObjectBinding` used as a way to create a `Binding` from a `BindableObject`. In this case the ViewModel
/// complies with `BindableObject` which is then translated into a `Binding` which is what `Toggle` is expecting
/// NOTE: Since it's a `DynamicViewProperty`, after its value is changed, the body will be updated.
class ViewModel: BindableObject {
let didChange = PassthroughSubject<ViewModel, Never>()
var isEnabled = false {
didSet {
didChange.send(self)
@vinhnx
vinhnx / URLBuilder.swift
Created Jun 10, 2019
simple URL builder in Swift
View URLBuilder.swift
import Foundation
class URLBuilder {
// MARK: - Properties
private var url: String = ""
// MARK: - Life Cycle
@vinhnx
vinhnx / function_builder.swift
Created Jun 10, 2019
@functionBuilder in Swift
View function_builder.swift
// reference https://blog.vihan.org/swift-function-builders/
@_functionBuilder class UIViewFunctionBuilder {
static func buildBlock(_ views: UIView...) -> UIView {
let containerView = UIView()
for view in views {
containerView.addSubview(view)
}
return containerView
You can’t perform that action at this time.