Skip to content

Instantly share code, notes, and snippets.

View ConditionTester.swift
import Foundation
// Swift translation of https://pspdfkit.com/blog/2016/running-ui-tests-with-ludicrous-speed/
class ConditionTester {
typealias TestCondition = () -> (Bool)
private let condition: TestCondition
private var fulfilled: Bool { return condition() }
private var currentRunLoop: CFRunLoop {
return RunLoop.current.getCFRunLoop()
@alemar11
alemar11 / libdispatch-efficiency-tips.md
Created Oct 7, 2021 — forked from tclementdev/libdispatch-efficiency-tips.md
Making efficient use of the libdispatch (GCD)
View libdispatch-efficiency-tips.md

libdispatch efficiency tips

The libdispatch is one of the most misused API due to the way it was presented to us when it was introduced and for many years after that, and due to the confusing documentation and API. This page is a compilation of important things to know if you're going to use this library. Many references are available at the end of this document pointing to comments from Apple's very own libdispatch maintainer (Pierre Habouzit).

My take-aways are:

  • You should create very few, long-lived, well-defined queues. These queues should be seen as execution contexts in your program (gui, background work, ...) that benefit from executing in parallel. An important thing to note is that if these queues are all active at once, you will get as many threads running. In most apps, you probably do not need to create more than 3 or 4 queues.

  • Go serial first, and as you find performance bottle necks, measure why, and if concurrency helps, apply with care, always validating under system pressure. Reuse

View TraitCollectionBasedAdjustments.swift
// Bigger iPhones = any Max, any Plus, iPhone XR, iPhone 11
switch (UITraitCollection.current.horizontalSizeClass, UITraitCollection.current.verticalSizeClass) {
case (.compact, .compact):
// Smaller iPhones in landscape
case (.compact, .regular):
// Bigger iPhones in portrait
// iPads in portrait during any split screen,
@alemar11
alemar11 / openssl-build.h
Created Jul 15, 2021 — forked from steipete/openssl-build.h
Updated script that builds OpenSSL with Bitcode enabled (tested with Xcode 7.0b3)
View openssl-build.h
#!/bin/bash
# This script downlaods and builds the iOS and Mac openSSL libraries with Bitcode enabled
# Credits:
# https://github.com/st3fan/ios-openssl
# https://github.com/x2on/OpenSSL-for-iPhone/blob/master/build-libssl.sh
# Peter Steinberger, PSPDFKit GmbH, @steipete.
set -e
View dynamicReplacement.swift
// a.swift
public dynamic func f() {
print("original")
}
// b.swift
import a
@_dynamicReplacement(for: f())
public func f_b() {
@alemar11
alemar11 / gist:2a28acd1b166dd452f81e7abfd8521fc
Created Apr 27, 2021 — forked from horseshoe7/gist:e85bbb90278f626bea2f827ee5228703
Incremental MHWMigrationManager extended for optional finalDestinationURL
View gist:2a28acd1b166dd452f81e7abfd8521fc
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
@class MHWMigrationManager;
@protocol MHWMigrationManagerDelegate <NSObject>
NS_ASSUME_NONNULL_BEGIN
@optional
- (void)migrationManager:(MHWMigrationManager *)migrationManager migrationProgress:(float)migrationProgress;
View JCMMemoryEfficientMigrationManager.h
@import CoreData;
/**
A subclass of NSMigrationManager that is more memory efficient than
NSMigrationManager itself.
This class maintains its own source and destination instance association
tables, which store only the URI representation of the instances's object IDs,
rather than the objects themselves. This means that objects do not accumulate
@alemar11
alemar11 / multiple-deploy-keys-multiple-private-repos-github-ssh-config.md How to configure multiple deploy keys for different private github repositories on the same computer without using ssh-agent
View multiple-deploy-keys-multiple-private-repos-github-ssh-config.md

How to configure multiple deploy keys for different private github repositories on the same computer without using ssh-agent

Let's say alice is a github.com user, with 2 or more private repositories repoN. For this example we'll work with just two repositories named repo1 and repo2

https://github.com/alice/repo1

https://github.com/alice/repo2

You need to be to pull from these repositories without entering a passwords probably on a server, or on multiple servers.

@alemar11
alemar11 / AuthenticatingSceneDelegate.swift
Created Jan 3, 2021 — forked from shaps80/AuthenticatingSceneDelegate.swift
A UIWindowSceneDelegate that provides lifecycle events and an API for deferring specific tasks automatically for you. Simplifies the implementation of LocalAuthentication or some other authentication implementation.
View AuthenticatingSceneDelegate.swift
import UIKit
/// Defines a token for determining the validity of a session
public protocol AuthenticationToken: Codable {
/// The token is currently valid
var isValid: Bool { get }
/// An encoded representation for storage
var encoded: Data? { get }
}
@alemar11
alemar11 / FourColumns.swift
Created Dec 30, 2020 — forked from douglashill/FourColumns.swift
A sample UIKit app that sets up a four column layout with new iOS 14 API on UISplitViewController.
View FourColumns.swift
import UIKit
class FourColumnsContainerViewController: UIViewController {
let outerSplitViewController = UISplitViewController(style: .tripleColumn)
let innerSplitViewController = UISplitViewController(style: .doubleColumn)
let primary = makeContentViewController("App")
let secondary = makeContentViewController("Files")
let mainContent = makeContentViewController("File Content")
let inspector = makeContentViewController("Inspector")