forked from appfoundry/Reliant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnipets.txt
200 lines (140 loc) · 7.38 KB
/
snipets.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
Doxygen script
==============
# Build the doxygen documentation for the project and load the docset into Xcode.
# Use the following to adjust the value of the $DOXYGEN_PATH User-Defined Setting:
# Binary install location: /Applications/Doxygen.app/Contents/Resources/doxygen
# Source build install location: /usr/local/bin/doxygen
# If the config file doesn't exist, run 'doxygen -g $SOURCE_ROOT/doxygen.config' to
# a get default file.
if ! [ -f $SOURCE_ROOT/doxygen.config ]
then
echo doxygen config file does not exist
$DOXYGEN_PATH -g $SOURCE_ROOT/doxygen.config
fi
# Append the proper input/output directories and docset info to the config file.
# This works even though values are assigned higher up in the file. Easier than sed.
cp $SOURCE_ROOT/doxygen.config $TEMP_DIR/doxygen.config
echo "INPUT = $SOURCE_ROOT/Reliant" >> $TEMP_DIR/doxygen.config
echo "OUTPUT_DIRECTORY = $SOURCE_ROOT/DoxygenDocs.docset" >> $TEMP_DIR/doxygen.config
echo "GENERATE_DOCSET = YES" >> $TEMP_DIR/doxygen.config
echo "DOCSET_BUNDLE_ID = be.oakcs.reliant.Doxygen" >> $TEMP_DIR/doxygen.config
# Run doxygen on the updated config file.
# Note: doxygen creates a Makefile that does most of the heavy lifting.
$DOXYGEN_PATH $TEMP_DIR/doxygen.config
# make will invoke docsetutil. Take a look at the Makefile to see how this is done.
make -C $SOURCE_ROOT/DoxygenDocs.docset/html install
# Construct a temporary applescript file to tell Xcode to load a docset.
rm -f $TEMP_DIR/loadDocSet.scpt
echo "tell application \"Xcode\"" >> $TEMP_DIR/loadDocSet.scpt
echo "load documentation set with path \"/Users/$USER/Library/Developer/Shared/Documentation/DocSets/\"" >> $TEMP_DIR/loadDocSet.scpt
echo "end tell" >> $TEMP_DIR/loadDocSet.scpt
# Run the load-docset applescript command.
osascript $TEMP_DIR/loadDocSet.scpt
exit 0
MAcros
______
#ifdef __IPHONE_NA
#import <UIKit/UIKit.h>
#warning ussing UIKit
#else
#warning not using UIKit
#endif
/usr/local/bin/appledoc --project-name ${PRODUCT_NAME} --project-company "Oak Consultancy Services" --company-id be.oakcs --output ~/help --logformat xcode --exit-threshold 2 --no-merge-categories .
Failed attempt, but usefull to check how to do invocations with varargs
/*Class granny = [self superclass];
IMP grannyImp = class_getMethodImplementation(granny, _cmd);
va_list args;
va_start(args, _cmd);
id result = grannyImp(super, _cmd, args);
va_end(args);
*/
/*
Method calledMethod = class_getInstanceMethod([orig class], _cmd);
NSUInteger numberOfArgs = method_getNumberOfArguments(calledMethod);
NSMethodSignature *methodSignature = [[orig class] instanceMethodSignatureForSelector:_cmd];
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:methodSignature];
invocation.target = orig;
invocation.selector = NSSelectorFromString([NSString stringWithFormat:@"swizzled_%@", selector]);
if (numberOfArgs > 2) {
va_list args;
va_start(args, _cmd);
NSUInteger size;
NSUInteger alignment;
//The following code is made to correctly position ourselves in de va list. We cannot use va_arg here, because we cannot rely on va_arg's sizeof mechanism as we don't know the exact type of the argument at compile time.
//We need to first detect the
for (int i = 2; i < numberOfArgs; i++) {
const char * argumentEncoding = [methodSignature getArgumentTypeAtIndex:i];
NSGetSizeAndAlignment(argumentEncoding, &size, &alignment);
switch (argumentEncoding[0]) {
case '{':
[invocation setArgument:args atIndex:i];
break;
default:
//OK, we don't have a special case, we take de current argument
[invocation setArgument:&((void **)args)[0] atIndex:i];
break;
}
args += size;
}
va_end(args);
}
[invocation invoke];
id returnValue;
//Return type of the method must be an id
[invocation getReturnValue:&returnValue];
NSLog(@"Dynamic method for %@ with selector %@ and result %@(end)", orig, selector, returnValue);
return returnValue;*/
/*static void swizzleEntireClass(Class c, BOOL (^filterBlock) (Method)) {
NSUInteger count;
Method *methods = class_copyMethodList(c, &count);
for (int i = 0; i < count; i++) {
Method m = methods[i];
if (filterBlock(m)) {
SEL selector = method_getName(m);
//TODO exclude . methods (ARC), property methods
if (class_respondsToSelector(c, selector)) {
SEL swizzleSelector = NSSelectorFromString([NSString stringWithFormat:@"swizzled_%@", NSStringFromSelector(selector)]);
const char *typeEncoding = method_getTypeEncoding(m);
NSLog(@"Adding method %@ with encoding %s", NSStringFromSelector(selector), typeEncoding);
class_addMethod(c, swizzleSelector, (IMP) dynamicIDMethodIMP, typeEncoding);
Swizzle(c, selector, c, swizzleSelector);
}
}
}
free(&methods);
}*/
/*static void dynamicForwardInvocation(id self, SEL _cmd, NSInvocation *invocation) {
Ivar var = class_getInstanceVariable([self class], "__ocs_proxy_reference");
id proxy = object_getIvar(self, var);
//Send the message to the real object, but change the "self" into our standin
invocation.target = proxy;
//[invocation setArgument:&self atIndex:0];
[invocation invoke];
}
static BOOL dynamicRespondsToSelector(id self, SEL _cmd, SEL selector) {
Ivar var = class_getInstanceVariable([self class], "__ocs_proxy_reference");
id proxy = object_getIvar(self, var);
return [proxy respondsToSelector:selector];
}
static NSMethodSignature *dynamicMethodSignatureForSelector(id self, SEL _cmd, SEL selector) {
Ivar var = class_getInstanceVariable([self class], "__ocs_proxy_reference");
id proxy = object_getIvar(self, var);
NSMethodSignature* signature = [proxy methodSignatureForSelector:selector];
return signature;
}
static Class addProxiedClass(Class c, id proxy) {
char *dest = malloc(strlen("OCSReliantExtended_") + strlen(class_getName(c)) + 1);
dest = strcpy(dest, "OCSReliantExtended_");
const char *name = strcat(dest, class_getName(c));
Class extendedClass = objc_allocateClassPair([NSObject class], name, 0);
BOOL ok = class_addIvar(extendedClass, "__ocs_proxy_reference", sizeof(id), log2(sizeof(id)), @encode(id));
objc_registerClassPair(extendedClass);
Method m = class_getInstanceMethod([NSObject class], @selector(forwardInvocation:));
ok = class_addMethod(extendedClass, @selector(forwardInvocation:), (IMP) dynamicForwardInvocation, method_getTypeEncoding(m));
m = class_getInstanceMethod([NSObject class], @selector(respondsToSelector:));
ok = class_addMethod(extendedClass, @selector(respondsToSelector:), (IMP) dynamicRespondsToSelector, method_getTypeEncoding(m));
m = class_getInstanceMethod([NSObject class], @selector(methodSignatureForSelector:));
ok = class_addMethod(extendedClass, @selector(methodSignatureForSelector:), (IMP) dynamicMethodSignatureForSelector, method_getTypeEncoding(m));
free(&dest);
return extendedClass;
}*/