This is a collection of knowledge I have built up regarding browser powered drag and drop functionality
- timing: once as drag is starting
event.target
: draggableElement
import SWBShared2 | |
import Metal | |
import AppKit | |
import CoreImage | |
import CoreGraphics | |
import QuartzCore | |
@globalActor | |
public struct CALayerToMetalRendererActor { |
import Foundation | |
import InterposeKit | |
import OSLog | |
/// Hack tow work around Assertion failure in -[NSTouchBarLayout setLeadingWidgetWidth:], NSTouchBarLayout.m:78 | |
/// This sometimes happens when macOS restores a window. | |
/// This even runs if there is no OS-level touch bar. | |
class MacOSWorkarounds { | |
static let logger = Logger(category: "MacOSWorkarounds") |
struct Foo: Codable { | |
let type: String | |
let value: String | |
} | |
struct Bar: Codable { | |
let type: String | |
let value: Int | |
} | |
protocol Item { } |
Foundation offers a Thread class, internally based on pthread
, that can be used to create new threads and execute closures.
// Detaches a new thread and uses the specified selector as the thread entry point.
Thread.detachNewThreadSelector(selector: Selector>, toTarget: Any, with: Any)
// Subclass
class MyThread: Thread {
// A loading spinner. | |
// By @marcedwards from @bjango. | |
void setup() { | |
size(300, 300, P2D); | |
frameRate(30); | |
smooth(8); | |
noFill(); | |
stroke(255); | |
strokeWeight(6); |
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
// UICollectionView Objective-C example | |
- (void)viewWillAppear:(BOOL)animated { | |
[super viewWillAppear:animated]; | |
NSIndexPath *selectedIndexPath = [[self.collectionView indexPathsForSelectedItems] firstObject]; | |
if (selectedIndexPath != nil) { | |
id<UIViewControllerTransitionCoordinator> coordinator = self.transitionCoordinator; | |
if (coordinator != nil) { | |
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) { |
import UIKit | |
import Cartography // https://github.com/robb/Cartography | |
/** | |
This is an example of self sizing `UICollectionView` cells using AutoLayout, | |
where the width of cells is always the width of the parent, to mimic `UITableView`. | |
*/ | |
fileprivate let items: [String] = (0..<100) | |
.map { _ in Lorem.sentences(Int.random(min: 1, max: 8)) } // Using https://github.com/lukaskubanek/LoremSwiftum/blob/master/Sources/LoremSwiftum.swift |