Skip to content

Instantly share code, notes, and snippets.

View Koze's full-sized avatar
:octocat:
Refactoring

Koze Koze

:octocat:
Refactoring
View GitHub Profile
@Koze
Koze / PrintClassHierarchy.m
Created April 4, 2015 16:30
Print Class Hierarchy
#import <objc/runtime.h>
void PrintClassHierarchy(Class cls) {
printf("// Class Hierarchy of %s\n", class_getName(cls));
Class superClass = cls;
while (superClass) {
printf("%s", class_getName(superClass));
superClass = class_getSuperclass(superClass);
if (superClass) {
printf(" : ");
@Koze
Koze / UIGestureRecognizerTarget.h
Last active August 29, 2015 14:18
UIGestureRecognizerTarget
@interface UIGestureRecognizerTarget : NSObject {
id _target;
SEL _action;
}
- (NSString *)description;
@end
@Koze
Koze / LogGesture.m
Last active June 30, 2017 09:12
Simple Log of UIGestureRecognizer
#import <objc/runtime.h>
void LogGesture(UIGestureRecognizer *gestureRecognizer) {
id object = [[gestureRecognizer valueForKey:@"targets"] firstObject];
id target = [object valueForKey:@"target"];
Ivar ivar = class_getInstanceVariable([object class], "_action");
SEL action = (__bridge void *)object_getIvar(object, ivar);
NSMutableString *mString = [NSMutableString stringWithFormat:@"%@; action=%@; target=%@;",
NSStringFromClass(gestureRecognizer.class),
NSStringFromSelector(action),
@Koze
Koze / MethodExhange1.m
Created April 8, 2015 15:01
Example for method_exchangeImplementations
#import "ViewController.h"
#import <objc/runtime.h>
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
Class cls = self.class;
Method m1 = class_getInstanceMethod(cls, @selector(methodA));
@Koze
Koze / HookAddGestureRecognizer.m
Last active August 29, 2015 14:18
Hook addGestureRecognizer:
#import "ViewController.h"
#import <objc/runtime.h>
static NSMutableDictionary *_stack;
NSString *LogGesture(UIGestureRecognizer *gestureRecognizer);
@interface UIView (LogGesture)
- (void)exchangedAddGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer;
@end
@Koze
Koze / MPMusicPlayerControllerPrivate.m
Last active July 13, 2021 18:00
Private volume API with MPMusicPlayerController
// MPMusicPlayerController has private method setVolume: and setVolumePrivate:
// The following KVO works on iOS 8.3.
MPMusicPlayerController *playerController = [MPMusicPlayerController systemMusicPlayer];
[playerController setValue:@(0.1) forKey:@"volume"];
[playerController setValue:@(0.2) forKey:@"volumePrivate"];
@Koze
Koze / test1.m
Last active August 29, 2015 14:19
Invisible Characters in Xcode
- (NSString *)test
{
NSString *string = @"whitespace is invisible";
return string;
}
@Koze
Koze / gist-embed.css
Last active February 9, 2021 05:25
Unminified Gist CSS
.gist {
color: #333;
font-size: 16px;
}
.gist .markdown-body {
overflow: hidden;
font-family: "Helvetica Neue", Helvetica, "Segoe UI", Arial, freesans, sans-serif;
font-size: 16px;
line-height: 1.6;
word-wrap: break-word;
@Koze
Koze / Basic.xccolortheme.plist
Last active August 29, 2015 14:19
/Applications/Xcode.app/Contents/OtherFrameworks/XcodeEdit.framework/Resources/Basic.xccolortheme
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Colors</key>
<dict>
<key>Background</key>
<string>1.000 1.000 1.000</string>
<key>InsertionPoint</key>
<string>0.000 0.000 0.000</string>
@Koze
Koze / Basic.dvtcolortheme.plist
Created April 15, 2015 11:00
~/Library/Developer/Xcode/UserData/FontAndColorThemes/Basic.dvtcolortheme
<?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>DVTConsoleDebuggerInputTextColor</key>
<string>0 0 0 1</string>
<key>DVTConsoleDebuggerInputTextFont</key>
<string>Menlo-Bold - 11.0</string>
<key>DVTConsoleDebuggerOutputTextColor</key>
<string>0 0 0 1</string>