What are some good Xcode scripts to speed up development?

前端 未结 6 509
情深已故
情深已故 2021-01-31 12:54

Xcode allows you to create automated scripts for performing repetitive tasks. What scripts have you written to speed up development?

6条回答
  •  粉色の甜心
    2021-01-31 13:01

    Here's one to log a method and its arguments any time it's executed (Select the method definition up through the lie with the opening brace and execute the script). If FIXME shows up in the output it means it's an unrecognized type. You can either add it to the script or choose the proper format specifier manually.

    #!/usr/bin/python
    
    # LogMethod
    # Selection
    # Selection
    # Insert after Selection
    # Display in Alert
    
    import sys
    import re
    
    input = sys.stdin.read()
    
    methodPieces = re.findall("""(\w*:)""", input)
    vars = re.findall(""":\(([^)]*)\)[ ]?(\w*)""", input)
    
    outputStrings = ["\n  NSLog(@\""]
    
    # Method taking no parameters
    if not methodPieces:
        outputStrings.append(re.findall("""(\w*)[ ]?{""", input)[0])
    
    for (methodPiece, var) in zip(methodPieces, vars):
        type = var[0]
        outputStrings.append(methodPiece)
        if "**" in type:
            outputStrings.append("%p")
        elif "*" in type:
            if "char" in type:
                outputStrings.append("%c")
            else:
                outputStrings.append("%@")
        else:
            if "int" in type or "NSInteger" in type or "BOOL" in type:
                outputStrings.append("%i")
            elif "NSUInteger" in type:
                outputStrings.append("%u")
            elif "id" in type:
                outputStrings.append("%@")
            elif "NSTimeInterval" in type:
                outputStrings.append("%f")
            elif "SEL" in type:
                outputString.append("%s")
            else:
                outputStrings.append('"FIXME"')
        if not methodPiece == methodPieces[-1]:
            outputStrings.append('\\n"\n         @"')
    
    outputStrings.append("\"")
    
    for var in vars:
        name = var[1]
        outputStrings.append(",\n         ")
        outputStrings.append(name)
    
    outputStrings.append(");")
    
    print "".join(outputStrings),
    

提交回复
热议问题