Skip to content

Instantly share code, notes, and snippets.

View IniongunIsaac's full-sized avatar

Isaac Iniongun IniongunIsaac

View GitHub Profile
@IniongunIsaac
IniongunIsaac / BaseRealmDatasource.swift
Created April 24, 2021 09:43
A combination of Realm and Rx with easy, out of the box CRUD abstractions. Depends on 'RealmSwift, RxRealm and RxSwift'
import RxSwift
import RealmSwift
import RxRealm
class BaseRealmDatasource {
var kRealm: Realm { preconditionFailure("Subclass of BaseRealmDatasource must provide an instance of Realm!") }
func getAll<T: Object>(obj: T.Type) -> Observable<[T]> {
Observable.array(from: kRealm.objects(T.self))
@IniongunIsaac
IniongunIsaac / RectangularDashedView.swift
Created June 23, 2021 10:52
View with dashed borders
import UIKit
class RectangularDashedView: UIView {
@IBInspectable var viewCornerRadius: CGFloat = 0 {
didSet {
layer.cornerRadius = viewCornerRadius
layer.masksToBounds = viewCornerRadius > 0
}
}
@IniongunIsaac
IniongunIsaac / SwiftUISystemColors.swift
Created June 24, 2021 09:15
System Colors in SwiftUI
import UIKit
import SwiftUI
extension Color {
//MARK: - App Colors
static let primaryColor = Color.color("#008577")
//MARK: - Color from HexString
static func color(_ hex: String, alpha: CGFloat = 1.0) -> Color { Color(UIColor(hex, alpha)) }
@IniongunIsaac
IniongunIsaac / Loader.swift
Created August 25, 2023 09:53
Horizontal loading animation
import UIKit
open class Loader: UIView {
static let shared = Loader()
private var viewTag = 1234567890
public override init(frame: CGRect) {
super.init(frame: frame)
backgroundColor = progressBarColor.withAlphaComponent(0.1)
tag = viewTag
@IniongunIsaac
IniongunIsaac / UIView+.swift
Last active August 25, 2023 09:58
UIView Constraint Extensions
typealias VoidAction = (() -> Void)
class UIViewTapGestureRecognizer: UITapGestureRecognizer {
var action: VoidAction? = nil
}
struct AnchoredConstraints {
var top, leading, bottom, trailing, width, height: NSLayoutConstraint?
}
@IniongunIsaac
IniongunIsaac / MockURLProtocol.swift
Created August 25, 2023 10:04
Simple Networking Setup with XCTests
final class MockURLProtocol: URLProtocol {
static var data: Data?
static var error: Error?
static var urlResponse: URLResponse?
override class func canInit(with request: URLRequest) -> Bool {
true
}
@IniongunIsaac
IniongunIsaac / Toast.swift
Created August 25, 2023 10:07
Toast view for showing messages
import UIKit
func generateHapticFeedback(style: UIImpactFeedbackGenerator.FeedbackStyle = .light) {
UIImpactFeedbackGenerator(style: style).impactOccurred()
}
var notchHeight: CGFloat { UIApplication.shared.statusBarFrame.height }
enum ToastType {
case success, error