Skip to content

Instantly share code, notes, and snippets.

View garohussenjian's full-sized avatar

Garo Hussenjian garohussenjian

View GitHub Profile
View ObjectObserver.swift
// ObjectObserver.swift
// Created by Garo Hussenjian on 2/21/16.
import Foundation
import CoreData
struct ObjectObserver<T: NSManagedObject> {
garohussenjian / main.swift
Last active August 27, 2016 04:34
Main.swift implementation to fix leaky coverage in Unit Tests (with Unit Tests)
View main.swift
// main.swift
// Created by Garo Hussenjian on 8/20/16.
// Copyright © 2016 Xapnet, Inc. All rights reserved.
import UIKit
extension ProcessInfo {
garohussenjian / EnumToArray
Last active May 25, 2017 05:48
Convert RawRepresentable / enum to an Array
View EnumToArray
import Foundation
protocol RawEnumerable: RawRepresentable {
static var first: Self? { get }
extension RawEnumerable where RawValue == Int {
static var first: Self? {
guard let first = Self(rawValue: 0) else {
garohussenjian / SegueInteractor.swift
Last active April 18, 2016 01:24
Bind closure to Storyboard Segues (Master-Detail example)
View SegueInteractor.swift
// SegueInteractor.swift
// SegueIdentifier enumerates just the segue ID strings in the storyboard. VC's don't switch on this...
private enum SegueIdentifier: String {
case ShowDetail
// SegueInteractor binds closures to segues. VC's switch on this instead!
enum SegueInteractor {
case PrepareShowDetail((EventEntity) -> Void)
garohussenjian / PanSelectGestureRecognizer
Created July 12, 2016 04:27
Stateful Gesture Recognizer subclass
View PanSelectGestureRecognizer
// PanSelectGestureRecognizer.swift
// Created by Garo Hussenjian on 6/24/15.
import UIKit
import UIKit.UIGestureRecognizerSubclass
garohussenjian /
Created February 13, 2017 17:33 — forked from JeOam/
iOS Core Animation: Advanced Techniques, Part 1: The Layer Beneath

1. The Layer Tree

Core Animation's original name is Layer Kit

Core Animation is a compositing engine; its job is to compose different pieces of visual content on the screen, and to do so as fast as possible. The content in question is divided into individual layers stored in a hierarchy known as the layer tree. This tree forms the underpinning for all of UIKit, and for everything that you see on the screen in an iOS application.

In UIView, tasks such as rendering, layout and animation are all managed by a Core Animation class called CALayer. The only major feature of UIView that isn’t handled by CALayer is user interaction.

There are four hierarchies, each performing a different role:

  • view hierarchy
  • layer tree
garohussenjian / PropertyObserver.swift
Last active January 6, 2018 20:06
Property observer unexpectedly firing?
View PropertyObserver.swift
// Property observer unexpectedly firing?
protocol MyProtocol {
var value: String { get set }
class MyClass: MyProtocol {
var value: String = "Value"
garohussenjian / Sequence+KeyPath.swift
Last active December 17, 2018 04:41
Sequence extensions for KeyPath
View Sequence+KeyPath.swift
extension Sequence {
/// Map over properties of sequence elements
/// ```
/// let counts = ["Hello", "World!"].map(\.count)
/// // returns [5, 6]
/// ```
/// - Returns: An array of element properties at the keypath
View PlaygroundLogger.swift
import Foundation
import PlaygroundSupport
import UIKit
public protocol Logger {
func log(_ values: Any...)
extension Logger {
public func log(_ values: Any...) {