Skip to content

Instantly share code, notes, and snippets.

@nicklockwood
nicklockwood / gist:9605636
Last active December 11, 2019 15:17
Singleton Category implementation
Singleton.h
-------------
@protocol Singleton
@optional
+ (instancetype)sharedInstance;
@end
@drance
drance / gist:9613950
Last active August 29, 2015 13:57
Got tired of semaphore/runloop boilerplate for async unit tests
- (void)sleepRunLoopForInterval:(NSTimeInterval)interval whileRunningAsynchronousTest:(void (^)(dispatch_semaphore_t semaphore))test {
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
NSAssert((test != NULL), @"Passed a NULL test block");
test(semaphore);
while(dispatch_semaphore_wait(semaphore, DISPATCH_TIME_NOW)) {
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:interval]];
}
}
@steipete
steipete / gist:d76549ec262430354e7c
Last active December 3, 2018 23:56
Our set of warnings in PSPDFKit
//
// Warnings.xcconfig
//
// The list of warnings we (don’t) use, and the reasons why.
//
// :MARK: Warnings in use:
// :MARK: -everything
// We want the best possible diagnostics, so we simply enable everything that exists, and then opt–out of what doesn’t make sense for us.
//
// :MARK: - Warnings not to be promoted:
@Ben-G
Ben-G / DynamicInit.swift
Last active May 27, 2023 13:30
Dynamically create instance based on type in Swift
protocol Initializable {
init()
}
class A : Initializable {
var content:String
required init() {
content = "TestContent"
}
@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
//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?
@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?> {
@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
@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

@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 {}