Skip to content

Instantly share code, notes, and snippets.

View danurna's full-sized avatar

Daniel Witurna danurna

  • Vienna, Austria
View GitHub Profile

Keybase proof

I hereby claim:

  • I am danurna on github.
  • I am danurna (https://keybase.io/danurna) on keybase.
  • I have a public key whose fingerprint is D8A2 86C8 271B C4B8 FBF2 E708 2B00 DB00 119C 94CB

To claim this, I am signing this object:

@danurna
danurna / RealmSwift+Extension.swift
Last active September 26, 2017 07:29
Cascade Delete Realm Swift
import Foundation
import Realm
import RealmSwift
public extension Realm {
func cascadeDelete(_ entity: RLMObjectBase) {
guard let entity = entity as? Object else { return }
entity.objectSchema.properties.forEach { property in
@danurna
danurna / AttachingObserver.swift
Last active December 19, 2018 09:35
AttachingObserver (Weak KVO)
// Based on https://gist.github.com/joerick/a0b87607e69071fa6a3c
class AttachingObserver: NSObject {
typealias ChangeHandler = (NSObject, [NSKeyValueChangeKey: Any]?) -> Void
weak var observedObject: NSObject?
let keyPath: String
let changeHandler: ChangeHandler
init(observe object: NSObject, keyPath: String, changeHandler: @escaping ChangeHandler) {
self.observedObject = object
self.keyPath = keyPath
@danurna
danurna / CatsUIView.swift
Created July 26, 2022 09:25
CatsUIView Sample
class CatsUIView: UIView {
private var catsView: CatsView?
private var hostingViewController: UIViewController?
...
override func didMoveToSuperview() {
super.didMoveToSuperview()
guard hostingViewController == nil else { return }
@danurna
danurna / CatViewController.swift
Created July 26, 2022 09:26
CatViewController Sample
class CatViewController: UIViewController {
lazy var stackView: UIStackView = {
let stackView = UIStackView(arrangedSubviews: [
titleLabel,
catsView
])
stackView.axis = .vertical
stackView.distribution = .fill
return stackView
}()