Skip to content

Instantly share code, notes, and snippets.

Working from home

Leo Kwan leojkwan

Working from home
View GitHub Profile
View EmbeddableCustomView.swift
class EmbeddableCustomView: UIView, HasNib {
override init(frame: CGRect) {
super.init(frame: frame)
// Render xib view from code.
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
View HasNib_2.swift
// MARK: Support for instantiation from NIB
public extension HasNib where Self: UIView {
static var nib: UINib {
return UINib(nibName: String(describing: self), bundle: Bundle(for: self))
// Adds content loaded from the nib to the end of the
// receiver's list of subviews and adds constraints automatically.
func loadNibContent() {
leojkwan / HasNib.swift
Last active Jul 16, 2018
Initialize custom nib views in a type-safe-er way when .xib and implementation files are named the same.
View HasNib.swift
public protocol HasNib: class {
static var nib: UINib { get }
public extension HasNib {
static var nib: UINib {
return UINib(nibName: String(describing: self), bundle: Bundle(for: self))
leojkwan / NativeObservable.swift
Created May 5, 2017
Native Observable Pattern in Swift
View NativeObservable.swift
import UIKit
class PushedViewController: UIViewController {
var currentWeather: Observable<Double>!
private let disposeBag = MyDisposeBag()
override func viewDidLoad() {
View ViewController+InstaFoodService.swift
import UIKit
import Moya
class ViewController: UIViewController {
private let instaFoodProvider = MoyaProvider<InstaFoodService>()
override func viewDidLoad() {
leojkwan / RequestManager.swift
Last active Feb 20, 2017
Shared URLSession Networking Client
View RequestManager.swift
import UIKit
public typealias RequestResponse = (_ statusCode:Int, _ data:AnyObject?) -> Void
struct RequestManager {
static func makeHTTPSRequest(
_ token: String?,
postBody: AnyObject? = nil,
View HashableObjects.swift
struct Person {
var name:String
let leo = Person(name: "Leo")
let nicole = Person(name: "Nicole")
let leonardoButCalledLeo = Person(name: "Leo")
let ashton = Person(name: "Ashton")
View array-item-count.swift
import Cocoa
// MARK: Goal- Find the number of times any item appears in array
var tayLyrics = "Nice to meet you, where you been? I could show you incredible things Magic, madness, heaven, sin Saw you there and I thought Oh my God, look at that face You look like my next mistake Love’s a game, want to play? New money, suit & tie"
var stringArray = tayLyrics.componentsSeparatedByString(" ")
var intArray = [1,4,5,2,6,6,6]