Skip to content

Instantly share code, notes, and snippets.

@alextud
alextud / Notifications.swift
Last active September 25, 2018 09:16
Notifications with generics
enum Notifications {
public class Notification<T, Identifier: Equatable> {
private var allObservers: [WeakContainer] = []
public var observers: [RegisteredObserver] {
observersRegisteredByOwners = observersRegisteredByOwners.filter({ $0.owner != nil }) // remove observers where owner is nil
let aliveObservers = allObservers.compactMap({ $0.value })
if aliveObservers.count != allObservers.count {
allObservers = allObservers.filter({ $0.value != nil }) // remove dead observers
@alextud
alextud / gist:bfbf7f73efabb976e206b8a87805fdd9
Created March 27, 2018 09:48
JSONSerialization how to check for bool type
import UIKit
import Foundation
let string = "{\"bool\" : true, \"int\": 1 }"
let json = try! JSONSerialization.jsonObject(with: string.data(using: .utf8)!, options: [])
if let dict = json as? [String: Any] {
dict["bool"] is NSNumber
dict["int"] is NSNumber
@alextud
alextud / install_mergepbx.sh
Last active December 10, 2015 09:43 — forked from kaneshin/install_mergepbx.sh
To install mergepbx. This script is under the MIT License.
#!/bin/sh
MERGEPBX_TARGET=mergepbx
MERGEPBX_PREFIX=/usr/local/bin
MERGEPBX_BUILD_DIR=/tmp
MERGEPBX_REPO=https://github.com/simonwagner/mergepbx.git
build()
{
cd $MERGEPBX_BUILD_DIR/$MERGEPBX_TARGET