iphone - 自动将所有方法放入.h文件中

标签 iphone objective-c methods

在实现文件 (.m) 中,我有 30.. 方法。如何将它们的描述(全部)自动放入 .h 文件中?

最佳答案

接缝很难用正则表达式正确完成,但你可以用 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 ";"
    }
  } 
}

关于iphone - 自动将所有方法放入.h文件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9192431/

相关文章:

iphone - 如何在没有 AutoLayout 的情况下很好地适应 iOS 中 View 的高度和位置?

objective-c - NSData writeToFile 读取时未完全写入

java - 是否可以使方法连续运行直到我输入特殊字符

iphone - 如何制作如附图所示的 View ?

ios - 如何更改 App store 上 iphone 应用程序的设备兼容性?

iphone - UITextView 在第一次点击时不显示 InputAccessoryView

iphone - UI 元素可以包含在 .a 库中吗?

objective-c - 在 Objective-C 中实现分水岭分割

java - 等于方法: Comparing 2 Objects

java - 如何使用名称访问 Java 中的变量?