Skip to content

Instantly share code, notes, and snippets.

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
@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")
View Readme.markdown

CFRunLoopSource is cool. It lets you build behavior similar to the mechanisms that drive setNeedsLayout and setNeedsDisplay in UIKit.

I found myself in need of something like this a couple of times. It's great to know that no matter how many times I say I need to update something, I will get a single callback at the end of the run loop that gives me a chance to perform my work.

Here is a little Swift wrapper that makes the API easier to deal with.

View ProgrammerAssertions.swift
//
// ProgrammerAssertions.swift
// Assertions
//
// Created by Mohamed Afifi on 12/20/15.
// Copyright © 2015 mohamede1945. All rights reserved.
//
import Foundation
@alemar11
alemar11 / libdispatch-efficiency-tips.md
Created Jul 19, 2020 — forked from tclementdev/libdispatch-efficiency-tips.md
Making efficient use of the libdispatch (GCD)
View libdispatch-efficiency-tips.md

libdispatch efficiency tips

I suspect most developers are using the libdispatch inefficiently due to the way it was presented to us at the time it was introduced and for many years after that, and due to the confusing documentation and API. I realized this after reading the 'concurrency' discussion on the swift-evolution mailing-list, in particular the messages from Pierre Habouzit (who is the libdispatch maintainer at Apple) are quite enlightening (and you can also find many tweets from him on the subject).

My take-aways are: