Skip to content

Instantly share code, notes, and snippets.

View markd2's full-sized avatar

Mark Dalrymple markd2

View GitHub Profile
@markd2
markd2 / runtime.m
Created July 9, 2013 20:55
Objective-C runtime metadata dumper.
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
#import "typestring.h"
// clang -g -fobjc-arc -Wall -framework Foundation -o runtime typestring.m runtime.m
// Runtime reference, at least until Apple breaks the link
// http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/ObjCRuntimeRef/Reference/reference.html
@markd2
markd2 / indexedivars.m
Created July 9, 2013 21:00
Example showing the use of accessing the indexed ivars.
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
// This stuff won't work with ARC, so make sure it's turned off.
// clang -g -fno-objc-arc -framework Foundation -o indexedivars indexedivars.m
@interface Stuffage : NSObject {
int _extraCount;
}
@markd2
markd2 / trssnd.m
Created July 14, 2013 14:41
Getting to the bottom of some odd compiler behavior.
#import <Foundation/Foundation.h>
// clang -g -Wall -framework Foundation -o trssnd trssnd.m
@interface A : NSObject
@property (assign, readonly, nonatomic) NSInteger blah;
@property (assign, nonatomic) NSInteger hasIvar;
@markd2
markd2 / NSObject+setValuesForKeysWithJSONDictionary.h
Created July 18, 2013 13:44
Support files for Inside the Bracket Part 6, showing an actual use of the objective-C runtime API.
//
// NSObject+setValuesForKeysWithJSONDictionary.h
//
// Created by Tom Harrington on 12/29/11.
// Tweaked by Mark Dalrymple
//
// Copyright (c) 2011 Atomic Bird, LLC. All rights reserved.
//
#import <Foundation/Foundation.h>
@markd2
markd2 / swizzle.m
Created July 25, 2013 14:18
Support file for Inside the Bracket, part 7, the final chapter, part two. This time, it's swizzling.
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
// clang -g -fobjc-arc -Wall -framework Foundation -o swizzle swizzle.m
// Swap two methods
void SwizzleMethod (Class clas, SEL originalSelector, SEL newSelector) {
Method originalMethod =
class_getInstanceMethod (clas, originalSelector);
@markd2
markd2 / addstuff.m
Created July 25, 2013 14:21
Support file for Inside the Bracket part 7, adding some methods to classes at runtime.
// Add some methods with the runtime.
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
// clang -g -fobjc-arc -Wall -framework Foundation -o addstuff addstuff.m
@interface Glorn : NSObject
@end
@markd2
markd2 / gist:9956630
Created April 3, 2014 15:31
Dangly Bits inside of UIKit
UIKit: 00596e34 t -[UIView(AdditionalLayoutSupport) _potentiallyHasDanglyConstraints]
UIKit: 001eb5b8 t -[UIView(AdditionalLayoutSupport) _setPotentiallyHasDanglyConstraints:]
UIKit: 000fa8e4 T __UIViewConstraintWithItemsIsPotentiallyDangly
UIKit: 00009edc t __UIViewRemoveConstraintsMadeDanglyByChangingSuperview
UIKit: 00596f78 t -[UIView(AdditionalLayoutSupport) _potentiallyHasDanglyConstraints]
UIKit: 001ebe9c t -[UIView(AdditionalLayoutSupport) _setPotentiallyHasDanglyConstraints:]
UIKit: 000fb05c T __UIViewConstraintWithItemsIsPotentiallyDangly
UIKit: 0000a474 t __UIViewRemoveConstraintsMadeDanglyByChangingSuperview
UIKit: 00000000006280fc t -[UIView(AdditionalLayoutSupport) _potentiallyHasDanglyConstraints]
UIKit: 000000000021836c t -[UIView(AdditionalLayoutSupport) _setPotentiallyHasDanglyConstraints:]
@markd2
markd2 / launchHandler.m
Created July 2, 2014 19:33
Simple utility that uses Launch Services to see what applications would be interested in editing a given file.
@import Foundation;
@import CoreServices;
// clang -g -fobjc-arc -fmodules launchHandler.m -o launchHandler
int main (int argc, const char *argv[]) {
// Rudimentary argument checking.
if (argc != 2) {
printf ("usage: %s filename\n", argv[0]);
@markd2
markd2 / gist.txt
Created August 19, 2014 19:31
hello extension!
Mikey Rules™
@markd2
markd2 / gist.txt
Created August 19, 2014 20:02
hello extension!
There once was a Wookiee named Mikey