Skip to content

Instantly share code, notes, and snippets.

View steipete's full-sized avatar

Peter Steinberger steipete

View GitHub Profile
@steipete
steipete / Test.m
Last active August 29, 2015 13:57
[PSPDFHUDView updatePageLabelFrameAnimated:] resizes a label that is inside PSPDFHUDView by calling sizeToFit. This triggers layoutSubviews on PSPDFHUDView. That's something I would like to prevent. What could I do here? Followup: https://gist.github.com/steipete/9725247
(lldb) bt
* thread #1: tid = 0x6e9f, 0x0036d774 PSPDFCatalog`-[PSPDFDebugLayer setNeedsLayout](self=0x1656a190, _cmd=0x302e001d) + 44 at PSPDFDebugHelper.m:456, queue = 'com.apple.main-thread', stop reason = breakpoint 14.1
frame #0: 0x0036d774 PSPDFCatalog`-[PSPDFDebugLayer setNeedsLayout](self=0x1656a190, _cmd=0x302e001d) + 44 at PSPDFDebugHelper.m:456
frame #1: 0x2f9763e8 QuartzCore`CA::Layer::property_did_change(CA::Transaction*, unsigned int) + 1188
frame #2: 0x2f975f1c QuartzCore`CA::Layer::end_change(CA::Transaction*, unsigned int, objc_object*) + 64
frame #3: 0x2f976a54 QuartzCore`CA::Layer::set_bounds(CA::Rect const&, bool) + 540
frame #4: 0x2f976776 QuartzCore`-[CALayer setBounds:] + 110
frame #5: 0x2f97789c QuartzCore`-[CALayer setFrame:] + 636
frame #6: 0x2fcf6336 UIKit`-[UIView(Geometry) setFrame:] + 254
frame #7: 0x2fd075f4 UIKit`-[UIView(Geometry) sizeToFit] + 304
@steipete
steipete / gist:9919240
Created April 1, 2014 17:45
keybase.md
### Keybase proof
I hereby claim:
* I am steipete on github.
* I am steipete (https://keybase.io/steipete) on keybase.
* I have a public key whose fingerprint is 9876 AB22 6B7E 965A 8343 18AC 91F6 4410 6993 72A4
To claim this, I am signing this object:
@steipete
steipete / CoreFoundationSurprises.m
Last active August 29, 2015 13:59
Testing "if you use a default allocator, and default callbacks, CF will generate an NS collection instead". (https://twitter.com/Catfish_Man/status/455592839334723584). We currently only have that on Mavericks, but since it the same codebase I'm 100% sure this will be in iOS 8 as well.
// Code using the default allocator and callbacks now actually returns an NSArray (__NSArrayM), and no longer a toll-free-bridged object.
NSArray *test = CFBridgingRelease(CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks));
NSArray *test3 = CFBridgingRelease(CFArrayCreate(kCFAllocatorDefault, NULL, 0, &kCFTypeArrayCallBacks));
// This is custom and will always return __NSCFArray
NSArray *test2 = CFBridgingRelease(CFArrayCreateMutable(kCFAllocatorDefault, 0, NULL));
// This will return __NSArrayI.
NSArray *test4 = [NSArray array];
// 64-bit helper from <tgmath.h>
// Extracted because those overrides won't work with Modules.
#undef fmin
#define fmin(__x, __y) __tg_fmin(__tg_promote2((__x), (__y))(__x), \
__tg_promote2((__x), (__y))(__y))
#undef fmax
#define fmax(__x, __y) __tg_fmax(__tg_promote2((__x), (__y))(__x), \
__tg_promote2((__x), (__y))(__y))
static void UIImagePickerEnsureViewIsInsidePopover(UIImagePickerController *self) {
if ([self isKindOfClass:UIImagePickerController.class]) {
// Ignore check on iPhone
if (UIDevice.currentDevice.userInterfaceIdiom != UIUserInterfaceIdiomPad) return;
// Ignore if property is set.
if ([[self _valueForProperty:@"_UIImagePickerControllerAllowAnySuperview"] boolValue]) return;
if (self.view.window && ![UIPopoverView popoverViewContainingView:self.view]) {
@throw [NSException exceptionWithName:NSInvalidArgumentException reason:[NSString stringWithFormat:@"On iPad, %@ must be presented via UIPopoverController", NSStringFromClass(self.class)] userInfo:nil];
// +[_UIPopoverView popoverViewContainingView:] looks similar to this:
static BOOL UIPopoverView_popoverViewContainingView(UIView *view ){
do {
if ([view isKindOfClass:UIPopoverView.class]) return YES;
}while((view = view.superview));
return NO;
}
// Add our own handler for didMoveToWindow.
[NSClassFromString(@"PLLibraryView") aspect_hookSelector:@selector(didMoveToWindow) withOptions:0 usingBlock:^(id instance, NSArray *arguments) {
// The lookup is ugly, but works well for this example.
UIImagePickerController *picker = instance;
while (picker && ![picker isKindOfClass:UIImagePickerController.class]) {
picker = (id)[picker nextResponder];
}
PSUIImagePickerEnsureViewIsInsidePopover(imagePicker);
} error:NULL];
- (void)testRelativeURLs {
PSPDFDocument *document = [[PSPDFTestAssetLoader new] documentWithName:@"Testcase-relative-links.pdf"];
NSArray *annotations = [document annotationsForPage:0 type:PSPDFAnnotationTypeLink];
PSPDFLinkAnnotation *link = annotations[0];
NSString *const referenceString = @"Testcase-relative-links/Simple.txt";
XCTAssertEqualObjects(link.URL.absoluteString, referenceString, @"URL should be correct");
PSPDFViewController *pdfController = [[PSPDFViewController alloc] initWithDocument:document];
__block NSURL *showPreviewURL = nil;
- (void)testSparkInspectorCompatibility {
PSPDFDocument *document = [[PSPDFTestAssetLoader new] documentWithName:@"Testcase_Metadata.pdf"];
// Spark swizzles this method and calls description on the target. Let's simulate this for this test case, and then clean up.
id<Aspect> token = [NSNotificationCenter aspect_hookSelector:@selector(addObserver:selector:name:object:) withOptions:0 usingBlock:^(id instance, NSArray *args) {
[args.firstObject description];
} error:NULL];
// Load the document. This failed because of side effects in description when called during init.
UIImage *image = [document imageForPage:0 size:CGSizeMake(100, 100) clippedToRect:CGRectZero annotations:nil options:nil receipt:NULL error:NULL];
@steipete
steipete / gist:a5f4d335f9713ee7a603
Created May 21, 2014 15:44
There's a lot of stuff added to NSObject at runtime by Apple...
(lldb) po [[[UIApplication sharedApplication] delegate] _shortMethodDescription]
<NSObject: 0x10c930450>:
in NSObject:
Class Methods:
+ (id) aspect_hookSelector:(SEL)arg1 withOptions:(unsigned long)arg2 usingBlock:(id)arg3 error:(id*)arg4; (0x10e669fb0)
+ (void) performSelectorWithNonRetainedTarget:(id)arg1 selector:(SEL)arg2 withObject:(id)arg3 afterDelay:(double)arg4; (0x10046e7fc)
+ (void) cancelPreviousPerformRequestsWithNonRetainedTarget:(id)arg1 selector:(SEL)arg2 object:(id)arg3; (0x10046e866)
+ (void) cancelPreviousPerformRequestsWithNonRetainedTarget:(id)arg1; (0x10046ead2)
+ (id) replacementObjectForPortCoder:(id)arg1; (0x10130bc73)
+ (objc_method_description*) instanceMethodDescriptionForSelector:(SEL)arg1; (0x1012dc040)