Skip to content

Instantly share code, notes, and snippets.

View steipete's full-sized avatar

Peter Steinberger steipete

View GitHub Profile
@objc func _needsDoubleUpdateConstraintsPass() -> Bool {
return true
}
override var intrinsicContentSize: CGSize {
  return attributedText?.size(forWidth: (engineBounds ?? bounds).width) ?? .zero
}
var engineBounds: CGRect? {
let objcSelector = "_nsis_compatibleBoundsInEngine:")
@ian-mcdowell
ian-mcdowell / Info.plist
Last active February 14, 2022 11:13
Keynote DAVFileProvider
<?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">
<dict>
<key>CFBundleName</key>
<string>KeynoteDAVFP</string>
<key>CFBundleIdentifier</key>
<string>com.apple.Keynote.KeynoteDAVFP</string>
<key>CFBundleDisplayName</key>
<string>WebDAV</string>
import UIKit
let keyPath = "continuous" + "Corners"
extension CALayer {
var infiniteCorners: Bool {
get { return value(forKeyPath: keyPath) as! Bool }
set { setValue(newValue, forKeyPath: keyPath) }
}
}
func dragInteraction(_ interaction: UIDragInteraction, itemsForBeginning session: UIDragSession)
let itemProvider = NSItemProvider()
itemProvider.registerFileRepresentation(forTypeIdentifier: kUTTypeJPEG as String, fileOptions: [.openInPlace], visibility: .all){ completionHandler in
//Get Url
let url = Attachement.url(forName: self.contactCard.name)
completionHandler(url, true, nil)
return nil
}
@smileyborg
smileyborg / InteractiveTransitionCollectionViewDeselection.m
Last active November 3, 2024 16:25
Animate table & collection view deselection alongside interactive transition (for iOS 11 and later)
// 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) {
@ian-mcdowell
ian-mcdowell / DebuggingOverlay.m
Last active February 27, 2021 19:04
UIDebuggingInformationOverlay for iOS 10, 11, and 12
#import <objc/runtime.h>
@interface DebuggingOverlay: NSObject
@end
@implementation DebuggingOverlay
+ (void)toggleOverlay {
id debugInfoClass = NSClassFromString(@"UIDebuggingInformationOverlay");
@KyNorthstar
KyNorthstar / NSWindow+Fade.swift
Last active April 7, 2025 22:28 — forked from indragiek/NSWindow+Fade.h
NSWindow+Fade - Animator proxy based NSWindow fading
//
// NSWindow+Fade.swift
// BH Bezel Notification
//
// Created by Ben Leggiero on 2017-11-09.
// Translated to Swift 4 from the original (ObjC): https://gist.github.com/indragiek/1397050
// Copyright © 2017 Ben Leggiero. All rights reserved.
//
import Foundation
@hborders
hborders / GenericIsKindOfClass.m
Created October 23, 2017 14:27
How to use Objective-C Generics with -isKindOfClass:
#import "MyNonClusteredClass.h"
@interface GenericIsKindOfClass<ObjectType : MyNonClusteredClass *> : NSObject
+ (instancetype _Nonnull)new NS_UNAVAILABLE;
- (instancetype _Nonnull)init NS_UNAVAILABLE;
- (instancetype _Nonnull)initWithInstanceOfObjectType:(ObjectType _Nonnull)instanceOfObjectType NS_DESIGNATED_INITIALIZER;
- (ObjectType _Nullable)typeSafeDowncastOrNil:(NSObject * _Nonnull)object;
As of iOS 11/macOS High Sierra, and only including ones in Foundation and CoreFoundation
Strings:
_NSCFString - a CFStringRef or CFMutableStringRef. This is the most common type of string object currently.
- May have 8 bit (ASCII) or 16 bit (UTF-16) backing store
_NSCFConstantString - a compile time constant CFStringRef, like you'd get with @"foo"
- May also be generated by dynamic string creation if matches a string in a pre-baked table of common strings called the StringROM
NSBigMutableString - an NSString backed by a CFStorage (https://github.com/opensource-apple/CF/blob/master/CFStorage.h) for faster handling of very large strings
NSCheapMutableString - a very limited NSMutableString that allows for zero-copy initialization. Used in NSFileManager for temporarily wrapping stack buffers.
@Catfish-Man
Catfish-Man / lockcachecontention.m
Last active July 5, 2017 07:00
Benchmark showing how locks sharing a cache line will contend with each other
#import <Foundation/Foundation.h>
#import <time.h>
#import <os/lock.h>
#define ITERS 2000
#define NSEC_PER_ITER(time) (((double)time * (double)NSEC_PER_SEC) / (double)ITERS)
#define TEST(body, name) do {\
start = [NSDate date];\
for (int i = 0; i < ITERS; i++) {\