Skip to content

Instantly share code, notes, and snippets.

@neonichu
Last active December 26, 2015 16:59
Show Gist options
  • Select an option

  • Save neonichu/7183605 to your computer and use it in GitHub Desktop.

Select an option

Save neonichu/7183605 to your computer and use it in GitHub Desktop.
"What is the only* public class in the cocoa frameworks that has no methods of its own?" https://twitter.com/NSLondonMeetup/status/394473852094259200
#!/bin/sh
FWK_PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/System/Library/Frameworks"
clang -o FindClasses -std=c99 -framework Foundation FindClasses.m
headers="`find "$FWK_PATH" -name '*.h'`"
for class in `./FindClasses 2>&1|cut -d" " -f4`
do
grep $class $headers >/dev/null 2>&1
if [ $? -eq 0 ]
then
echo $class
fi
done
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
int main(int argc, char *argv[]) {
@autoreleasepool {
int numClasses;
Class * classes = NULL;
classes = NULL;
numClasses = objc_getClassList(NULL, 0);
if (numClasses > 0 )
{
classes = malloc(sizeof(Class) * numClasses);
numClasses = objc_getClassList(classes, numClasses);
for (int i = 0; i < numClasses; i++) {
unsigned int numMethods;
Method *methods = class_copyMethodList(classes[i], &numMethods);
free(methods);
if (numMethods == 0) {
NSString* className = NSStringFromClass(classes[i]);
if ([className rangeOfString:@"_"].location == NSNotFound) {
NSLog(@"%@", className);
}
}
}
free(classes);
}
}
}
@neonichu
Copy link
Author

$ ./find.sh
NSURLSessionDataTask
NSURLSessionUploadTask
NSURLSessionDownloadTask

(and, yes, the answer is semi-wrong because the program runs on OS X and the script examines iOS headers)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment