Skip to content

Instantly share code, notes, and snippets.

//
// Alamofire+Reactive.swift
// architecture
//
// Created by MakotoAoyama on 9/8/17.
//
import Foundation
import ReactiveSwift
import Alamofire
@mbuchetics
mbuchetics / json.swift
Created June 30, 2017 09:28 — forked from reckenrode/json.swift
Decoding arbitrary JSON with the new Decoder in Swift 4
enum JSON: Decodable {
case bool(Bool)
case double(Double)
case string(String)
indirect case array([JSON])
indirect case dictionary([String: JSON])
init(from decoder: Decoder) throws {
if let container = try? decoder.container(keyedBy: JSONCodingKeys.self) {
self = JSON(from: container)
@leojkwan
leojkwan / NativeObservable.swift
Created May 5, 2017 05:33
Native Observable Pattern in Swift
import UIKit
class PushedViewController: UIViewController {
var currentWeather: Observable<Double>!
private let disposeBag = MyDisposeBag()
override func viewDidLoad() {
super.viewDidLoad()
@ChristianVinterly
ChristianVinterly / Observers.swift
Last active July 12, 2017 15:15
Alternative observer pattern in swift, with playground example
//: Playground - noun: a place where people can play
import UIKit
private class Weak: Hashable {
let hashValue: Int
weak var value: AnyObject?
init(value: AnyObject) {
self.value = value
self.hashValue = ObjectIdentifier(value).hashValue
@einsteinx2
einsteinx2 / locking.swift
Last active March 2, 2019 17:25 — forked from kristopherjohnson/locking.swift
Simple synchronization functions for Swift, wrapping the Cocoa NSLocking classes
import Foundation
/// Protocol for NSLocking objects that also provide try()
public protocol TryLockable: NSLocking {
func `try`() -> Bool
}
// These Cocoa classes have tryLock()
extension NSLock: TryLockable {}
extension NSRecursiveLock: TryLockable {}
@hannesoid
hannesoid / swift-compile-times.md
Created November 16, 2016 13:39
Measure Swift Compile Times

List swift functions by slowest compile time (minimum 2-digit milliseconds):

$ xcodebuild -workspace MyProject.xcworkspace -scheme "MyProject" clean build OTHER_SWIFT_FLAGS="-Xfrontend -debug-time-function-bodies" | grep '^[0-9][0-9][0-9]*\.[0-9]*ms' | sort -n

If you want to see the compile times in Xcode build report add to build settings "other swift flags": -Xfrontend -debug-time-function-bodies

Sources

@zwaldowski
zwaldowski / Extra Logging for My Great App.mobileconfig
Last active March 28, 2025 03:47
Apple Configuration Profile for Logging in iOS 10 and macOS Sierra
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<!-- iOS 10, macOS Sierra, and friends bring a new logging subsystem that's
supposed to scale from the kernel, up to frameworks, and up to apps. It defaults
to a more regimented, privacy-focused approach that large apps and complex
systems need.
It, along with Activity Tracing introduced in iOS 8 and macOS Yosemite and the
Console app in macOS Sierra, hope to help you graduate from caveman debugging to
@flyinghyrax
flyinghyrax / FirebaseValue.swift
Last active April 2, 2017 08:41
Some firebase binding code
// FirebaseValue.swift
// Created by Matt Seiler on 7/14/16.
// Copyright © 2016 Matthew Seiler. All rights reserved.
import FitnetUtils
import FirebaseDatabase
import Foundation
class FirebaseValue<T>: Observable<T?> {
//some time, frc section may be need section offset
@objc public protocol MFetchedResultsControllerOffsetSectionDelegate{
func offsetSection() -> Int
}
class MFetchedResultsController: NSFetchedResultsController, NSFetchedResultsControllerDelegate {
weak var viewController: UIViewController? //UITableViewController UICollectionViewController
weak var scrollView: UIScrollView? //TableView CollectionView
weak var offsetSectionDelegate: MFetchedResultsControllerOffsetSectionDelegate?
@robertjpayne
robertjpayne / AppDelegate.swift
Last active August 29, 2015 14:21
Media Query Kit
//
// AppDelegate.swift
// MediaQueryKit
//
// Created by Robert Payne on 21/05/15.
// Copyright (c) 2015 Zwopple Limited. All rights reserved.
//
import UIKit