Skip to content

Instantly share code, notes, and snippets.

@barrettj
Created April 12, 2012 14:26
Show Gist options
  • Save barrettj/2367686 to your computer and use it in GitHub Desktop.
Save barrettj/2367686 to your computer and use it in GitHub Desktop.
TextExpander Applescript to turn Methods into Declarations (from Clipboard contents)
set clipText to (the clipboard as string)
set theItems to paragraphs of clipText
set ret to ""
on replaceText(find, replace, subject)
set prevTIDs to text item delimiters of AppleScript
set text item delimiters of AppleScript to find
set subject to text items of subject
set text item delimiters of AppleScript to replace
set subject to "" & subject
set text item delimiters of AppleScript to prevTIDs
return subject
end replaceText
on makeFuncDec(subject)
set ret to ""
if subject ends with " {" then
set ret to replaceText(" {", ";\n", subject)
else if subject ends with "{" then
set ret to replaceText("{", ";\n", subject)
else
set ret to subject & ";\n"
end if
return ret
end makeFuncDec
repeat with theLine in theItems
set p to theLine as string
if p starts with "- (" or p starts with "-(" or p starts with "+ (" or p starts with "+(" then
set ret to ret & makeFuncDec(p)
end if
end repeat
return ret
@barrettj
Copy link
Author

Setup

Make a TextExpander AppleScript snippet with this as the content, set the abbreviation (I'll assume you made it ;fdecs for the purpose of this ReadMe).

Usage

Copy your implementation to your clipboard

E.G:

- (void)handleLongPress:(UILongPressGestureRecognizer*)gesture {
    if (gesture.state == UIGestureRecognizerStateRecognized) {
        // DO SOMETHING
    }
}
- (void)didPressDone:(id)sender {
    // DO SOMETHING
}
- (void)didPressNext:(id)sender {
    // DO SOMETHING
}
- (void)didPressPrevious:(id)sender {
    // DO SOMETHING
}

Go you your header file and type your abbreviation, and it will output the declarations for the methods

E.G.

- (void)handleLongPress:(UILongPressGestureRecognizer*)gesture;
- (void)didPressDone:(id)sender;
- (void)didPressNext:(id)sender;
- (void)didPressPrevious:(id)sender;

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