Skip to content

Instantly share code, notes, and snippets.

View MochaTheCoder's full-sized avatar

MochaTheCoder

View GitHub Profile
class VC: UIViewController {
private let asyncButton = UIButton()
func doAsyncAction() {
// Change button to display loading when we click on it
asyncButton.isEnabled = false
asyncButton.setTitle("Loading", for: .disabled)
asyncButton.setTitleColor(.red, for: .disabled)
networkManager.makeRequest() { response in
@MochaTheCoder
MochaTheCoder / AVC
Last active May 9, 2019 21:11
reloadData Handler cellForRowAt debug
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
window = UIWindow(frame: UIScreen.main.bounds)
let aVC = AViewController()
let nav = UINavigationController(rootViewController: aVC)
window!.rootViewController = nav
window!.makeKeyAndVisible()
return true
}
@MochaTheCoder
MochaTheCoder / UIView+Util.swift
Created April 12, 2019 18:41
Generic extension for UIViews to use custom .xib files for custom views
// Assuming .xib name is the same as class name
extension UIView {
func nibView<T>(for: T.Type) -> UIView? {
let nib = UINib(nibName: String(describing: T.self), bundle: nil)
let view = nib.instantiate(withOwner: self, options: nil).first as? UIView
return view
}
func addNibView<T>(from: T.Type) -> UIView? {
@MochaTheCoder
MochaTheCoder / UITableView+Util.swift
Last active April 12, 2019 17:32
Generic tableview extension to register and deque cells
extension UITableView {
func registerNib<T>(from: T.Type) {
register(UINib(nibName: String(describing: T.self), bundle: nil), forCellReuseIdentifier: String(describing: T.self))
}
func dequeReusableCell<T>() -> T? {
return dequeueReusableCell(withIdentifier: String(describing: T.self)) as? T
}
}
// To Use: