Skip to content

Instantly share code, notes, and snippets.

View desmondmc's full-sized avatar
🐢

Desmond McNamee desmondmc

🐢
View GitHub Profile
@desmondmc
desmondmc / Updateable.swift
Last active September 6, 2016 12:59
Updateable Realm Object
extension Updateable where Self: RLMObject {
static func persistJSON(json: NSDictionary) {
let update = Self.partialUpdateDicWithJSON(json)
let realm = RealmPersister.realm
realm.beginWriteTransaction()
Self.createOrUpdateInRealm(realm, withValue: update)
try! realm.commitWriteTransaction()
}
}
@desmondmc
desmondmc / CollectionViewMagic.swift
Last active October 29, 2016 13:16
Super CollectionView/TableView nib loading with protocols and generics.
//
// CollectionViewMagic.swift
// bodytonic-ios
//
// Created by Desmond McNamee on 2016-10-29.
// Copyright © 2016 Stadium Studio. All rights reserved.
//
import UIKit
@desmondmc
desmondmc / KeyboardHeight.swift
Created September 14, 2016 13:33
RxSwift wrapper for keyboard height.
//
// KeyboardHeight.swift
// bodytonic-ios
//
// Created by Desmond McNamee on 2016-08-28.
// Copyright © 2016 Stadium Studio. All rights reserved.
//
import UIKit
import RxSwift
@desmondmc
desmondmc / RetainCycle.swift
Created September 15, 2016 09:49
An example of a retain cycle using swift blocks.
//
// ViewController.swift
// RetainCylceTests
//
// Created by Desmond McNamee on 15/09/16.
// Copyright © 2016 Teamplace. All rights reserved.
//
import UIKit
@desmondmc
desmondmc / RxDelegate.swift
Last active February 4, 2017 12:12
Simple example of replacing the delegate pattern with Observable pattern.
//
// UITextView+Rx.swift
// bodytonic-ios
//
// Created by Desmond McNamee on 2017-02-04.
// Copyright © 2017 Stadium Studio. All rights reserved.
//
import Foundation
import UIKit
@desmondmc
desmondmc / TestViewController.swift
Last active February 3, 2017 18:15
Micro ViewModel+View Recipe RxSwift
class TestViewModel {
struct Inputs {
let tap = PublishSubject<Void>()
}
struct Outputs {
let someString: Observable<String?>
}
let inputs: TestViewModel.Inputs
@desmondmc
desmondmc / NoDepsRouter.swift
Created March 15, 2017 11:14
No Dependencies Swift Router
import Foundation
public protocol RequestConvertible {
var asRequest: NSMutableURLRequest { get }
}
enum NoDepsRouter: RequestConvertible {
case thing(id: String)
case postThings(id: String)
@desmondmc
desmondmc / git_aliases
Created March 16, 2017 13:58
Git Aliases
[alias]
co = checkout
br = branch
st = status
visual = log --graph --full-history --all --pretty=format:%h%x09%d%x20%s
branch-name = !git rev-parse --abbrev-ref HEAD
publish = !git push -u origin $(git branch-name)
@desmondmc
desmondmc / Sequence+Desmond.swift
Last active March 21, 2017 13:10
Sequence Extensions
public extension Sequence {
func scan<T>(_ seed: T, function:(T, Iterator.Element) -> T) -> T {
var current: T = seed
for element in self {
current = function(current, element)
}
return current
}
@desmondmc
desmondmc / LinkedList.swift
Created March 21, 2017 13:07
Linked List Implementation
indirect enum LinkedListNode<T> {
case value(element: T, next: LinkedListNode<T>)
case end
}
extension LinkedListNode: Sequence {
func makeIterator() -> LinkedListIterator<T> {
return LinkedListIterator(current: self)
}
}