LightNight
LightNight

Reputation: 1625

Put all methods into .h file automatically

In implementation file (.m) I have 30.. methods. How can I put their description (all of them) into .h file automatically?

Upvotes: 2

Views: 174

Answers (3)

Mattias Wadman
Mattias Wadman

Reputation: 11425

Seams hard to do properly with a regex, but you can do it with awk:

https://gist.github.com/1771131

#!/usr/bin/env awk -f
# print class and instance methods declarations from implementation
# Usage: ./printmethods.awk class.m or awk -f printmethods.awk class.m

/^[[:space:]]*@implementation/ {
  implementation = 1;
}

/^[[:space:]]*@end/ {
  implementation = 0;
}

/^[[:space:]]*[\-\+]/ {
  if(implementation) {
    method = 1;
    collect = "";
  }
}

/[^[:space:]]/ {
  if(implementation && method) {
    p = index($0, "{");
    if(p == 0) {
      if(collect == "")
        collect = $0
      else
        collect = collect $0 "\n";
    } else {
      method = 0;
      # trim white space and "{" from line end
      gsub("[\{[:space:]]*$", "", $0);
      collect = collect $0;
      # trim white space from start
      gsub("^[[:space:]]*", "", collect);
      print collect ";"
    }
  } 
}

Upvotes: 2

Janardan Yri
Janardan Yri

Reputation: 751

The program Accessorizer (on the Mac App Store for $5) is specifically intended for these obnoxious grunt work issues in Xcode. It can generate prototypes as well as property synthesizes, accessors, inits, etc.

Caveat: it's been a bit touchy and rough around the edges in my experience. It might, for example, not realize that a function is inside a multi-line comment, and thus provide an unwanted prototype for it. But even with those quirks in mind, it's saved me way more than $5 worth of time.

Their website: http://www.kevincallahan.org/software/accessorizer.html

Upvotes: 0

Alex Terente
Alex Terente

Reputation: 12036

Write a piece of code that will extract all the methods definitions (Use regular expressions to detect them) and then just added it to the h file and "\; \n".

Upvotes: 0

Related Questions