Skip to content

Instantly share code, notes, and snippets.

View lalkrishna's full-sized avatar
🤩

Lal Krishna lalkrishna

🤩
View GitHub Profile
@lalkrishna
lalkrishna / TableView+Extensions.swift
Last active August 5, 2022 05:02
Tableview Extensions for Making dequeuing easier.
extension UITableView {
func register<T: UITableViewCell>(_ cellClass: T.Type) {
register(T.self, forCellReuseIdentifier: String(describing: T.self))
}
func reusableCell<T: UITableViewCell>(for indexPath: IndexPath) -> T {
// swiftlint:disable force_cast
dequeueReusableCell(withIdentifier: String(describing: T.self), for: indexPath) as! T
}
@lalkrishna
lalkrishna / CurrencyFormatter.swift
Created January 11, 2023 09:50
amount formatter based on user's locale.
extension Double {
func formattedAsCurrency(_ currencySymbol: String? = nil) -> String {
let formatter = NumberFormatter()
formatter.numberStyle = .currency
formatter.locale = Locale(identifier: "id_ID")
if let currencySymbol {
formatter.currencySymbol = currencySymbol
}
let price = NSNumber(value: self)
@lalkrishna
lalkrishna / Instantiatable.swift
Created January 17, 2023 07:33
instantiate viewcontroller using identifier.
protocol Instantiatable {
static var storyboard: Storyboard { get }
static func instantiate() -> Self
}
extension Instantiatable where Self: UIViewController {
static func instantiate() -> Self {
// swiftlint:disable force_cast
UIStoryboard(storyboard).instantiateViewController(withIdentifier: String(describing: Self.self)) as! Self
}
@lalkrishna
lalkrishna / MenuItem.swift
Created January 17, 2023 07:50
MenuBuilder
protocol MenuItem { }
struct MenuItemSeparator: MenuItem { }
struct MenuItemModel: MenuItem {
let icon: UIImage?
let title: String
// var instance: Instantiatable.Type
fileprivate var instance: ViewControllerConvertable