Skip to content

Instantly share code, notes, and snippets.

# force tag to another commit
git tag --force v1.0 <ID-of-commit-127>
# then force push
git push --force --tags
# pod cache clean all
pod cache clean --all
pod lib lint
pod spec lint
@chanonly123
chanonly123 / SimpleObservable.swift
Created November 4, 2019 12:01
Simple and lite Observable protocol, with weak storage
//
// SimpleObserver.swift
//
// Created by Chandan Karmakar on 15/10/19.
// Copyright © 2019 Chandan Karmakar. All rights reserved.
//
import Foundation
fileprivate let rTargets = NSMapTable<AnyObject, AnyObject>(keyOptions: .weakMemory,
@chanonly123
chanonly123 / UserDefaultsExtended.swift
Last active April 12, 2020 12:45
Simple propertyWrapper for UserDefaults
@propertyWrapper
class UserDefaultsExtended<Type: Codable> {
let key: String
let loc: UserDefaults
var actualValue: Type?
init(key: String, loc: UserDefaults = UserDefaults.standard) {
self.key = key
self.loc = loc
}
@chanonly123
chanonly123 / UIViewControllerInitFromStoryboard.swift
Last active May 2, 2020 07:12
Wrapping up boilerplate code - Interface builder
import UIKit
extension UIViewController {
// must override to provide storyboard
@objc class var fromStoryboard: UIStoryboard? { return nil }
// optional override to provide storyboardId
@objc class var storyboardId: String { return String(describing: self) }
static func instantiate() -> Self {
@chanonly123
chanonly123 / UIViewInitFromXib.swift
Last active May 2, 2020 07:13
Instantiating custom UIView from xib
import UIKit
extension UIView {
static func initViewFromNib() -> Self {
let nibName = String(describing: self)
let index = 0
let view = Bundle.main.loadNibNamed(nibName, owner: nil, options: nil)![index]
if let castedView = view as? Self {
return castedView
} else {
@chanonly123
chanonly123 / UITableViewDequeueCell.swift
Created May 2, 2020 07:15
Dequeue UITableView cell using class name
import UIKit
extension UITableView {
func dequeueReusableCell<T: UITableViewCell>(type: T.Type) -> T {
let identifier = String(describing: type)
if let reusableCell = self.dequeueReusableCell(withIdentifier: identifier) {
if let cell = reusableCell as? T {
return cell
} else {
assertionFailure("tableview cell cannot be casted to \(identifier)")
@chanonly123
chanonly123 / UIViewXib.swift
Last active May 27, 2020 09:00
Designable view from xib, without optimisation
@IBDesignable
class UIViewXib: UIView {
override init(frame: CGRect) {
super.init(frame: frame)
loadViewFromNib()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
@chanonly123
chanonly123 / UIViewXib.swift
Last active May 27, 2020 08:59
Designable view from xib, with optimisation
@IBDesignable
class UIViewXib: UIView {
override init(frame: CGRect) {
super.init(frame: frame)
loadViewFromNib()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
@chanonly123
chanonly123 / StoredPropertiesExtenstion.swift
Last active December 17, 2023 19:47
Stored properties in Swift Extensions in Swifty way
import Foundation
import UIKit
extension CustomView {
// can make private
static let storedProperties = WeakDictionary<UIView, Properties>()
struct Properties {
var url: String = ""