Skip to content

Instantly share code, notes, and snippets.

View chbeer's full-sized avatar

Christian Beer chbeer

View GitHub Profile
@zoul
zoul / OSStatus.m
Created October 19, 2010 08:21
Decode OSStatus error codes into strings.
NSString *NSStringFromOSStatus(OSStatus errCode)
{
if (errCode == noErr)
return @"noErr";
char message[5] = {0};
*(UInt32*) message = CFSwapInt32HostToBig(errCode);
return [NSString stringWithCString:message encoding:NSASCIIStringEncoding];
}
@danieleangeli
danieleangeli / NSManagedObjectArchiving.h
Created May 11, 2012 11:20 — forked from robertjpayne/NSManagedObjectArchiving.h
NSManagedObject Archiving and Unarchiving
#import <Foundation/Foundation.h>
@interface NSManagedObjectArchiver : NSObject
/*
* Takes a NSManagedObject and converts it to a NSData archive - it traverses all relationships ( including circular ) and archives it
*/
+ (NSData *)archivedDataWithRootObject:(NSManagedObject *)pObject;
@end
@drance
drance / gist:4546014
Created January 16, 2013 09:57
Workaround to vanilla UICollectionView+UICollectionViewFlowLayout using non-integral origins, leading to blurry cells.
@implementation BHSCollectionViewFlowLayout
- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect {
NSArray *allAttrs = [super layoutAttributesForElementsInRect:rect];
for (UICollectionViewLayoutAttributes *attributes in allAttrs) {
attributes.frame = CGRectIntegral(attributes.frame);
}
return allAttrs;
}
@MrRooni
MrRooni / gist:4988922
Created February 19, 2013 19:16
UITableView and NSFetchedResultsController: Updates Done Right
@interface SomeViewController ()
// Declare some collection properties to hold the various updates we might get from the NSFetchedResultsControllerDelegate
@property (nonatomic, strong) NSMutableIndexSet *deletedSectionIndexes;
@property (nonatomic, strong) NSMutableIndexSet *insertedSectionIndexes;
@property (nonatomic, strong) NSMutableArray *deletedRowIndexPaths;
@property (nonatomic, strong) NSMutableArray *insertedRowIndexPaths;
@property (nonatomic, strong) NSMutableArray *updatedRowIndexPaths;
@end
@alexrepty
alexrepty / gist:5183042
Created March 17, 2013 18:54
Useful macappstore:// links
Updates page: macappstore://showUpdatesPage?scan=true
Featured page: macappstore://itunes.apple.com/
Direct app link (1): macappstore://itunes.apple.com/app/id%@?mt=12 (ex. macappstore://itunes.apple.com/app/id537386512?mt=12)
Direct app link (2): macappstore://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=%@&mt=12 (ex. macappstore://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=537386512&mt=12)
@alloy
alloy / gist:6453958
Last active December 22, 2015 09:48
Prototype of an assertion that checks a NSManagedObject is being used on the queue belonging to its NSManagedObjectContext. This should obviously only be used during development.
/////////// Header
#import <CoreData/CoreData.h>
@interface NSManagedObject (FTCoreDataQueueContainmentAssertions)
+ (void)FTCDQCA_enableAssertions:(Class)klass;
@end
/////////// Implementation
@jverkoey
jverkoey / NSManagedObjectContext+DebugSwizzling.m
Created April 14, 2014 11:52
Core Data Managed Object Context Debugging
// NSManagedObjectContext+DebugSwizzling.h
#import <CoreData/CoreData.h>
#if DEBUG
/**
* Toggles debugging of Core Data managed object contexts.
*
* When enabled, will fire NSLogs in the following cases:
/*!
* Loads the data for a URL request and executes a handler block when the request completes
* or fails.
*
* @param aRequest A CPURLRequest object
* @param aQueue A CPOperationQueue object (currently not implemented)
* @param completionHandler A function passed in that will receive the request once it has returned.
*
* The completion handler will receive three arguments:
*<pre>
@schwa
schwa / SwiftUI for macOS Missing Features.md
Last active January 31, 2024 02:45
SwiftUI for macOS Missing Features

https://mastodon.social/@schwa/111801520286334341

My list:

  • Tap location for contextual menus. A lot of apps need to know exactly where a context menu is being triggered from (e.g. canvas style editors etc).
  • Modifier key observation during button presses/gestures etc.
  • Cursor support
  • Native Undo Manager support (SwiftUI has Environment.undoManager but it just exposes Cocoa's UndoManager which doesn't feel very SwiftUI like).
  • Expanded File Dialog options (e.g. adding buttons to the dialog).
  • The outline variant of List (List(… children: …)) is missing a lot of the flexibility of NSOutlineView (TODO: flesh this out with concrete example).