Created
December 9, 2012 11:31
-
-
Save Kr1sso/4244369 to your computer and use it in GitHub Desktop.
Enum debugging automation for Objective C, eg. with a TextExpander snippet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
def NSStringFromEnum(input) | |
inputArray = input.lines.collect | |
typeNameLine = inputArray[-1] | |
typeName = typeNameLine.match(/(\w+);/)[1] | |
output = "NSString* NSStringFrom#{typeName}(#{typeName} value) {\n switch (value) {\n"; | |
constantLines = inputArray[1..-2] | |
constantLines.each {|constantLine| | |
constantName = constantLine.match(/(\w+)/)[1] | |
output += " case #{constantName}:\n"; | |
output += " return @\"#{constantName}\";\n"; | |
output += " break;\n"; | |
} | |
output += " default:\n"; | |
output += " return [NSString stringWithFormat:@\"<unknown #{typeName}: %d>\", value];\n"; | |
output + " }\n}" | |
end | |
clipboard = %x{__CF_USER_TEXT_ENCODING=$UID:0x8000100:0x8000100 pbpaste}.strip | |
print NSStringFromEnum(clipboard) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As seen on: http://rentzsch.tumblr.com/post/37512716957/enum-nsstring
This makes it super easy to use with TextExpander. Copy paste your enum definition, type your TextExpander command and this will create the enum debugging help in place.