介绍一个很有趣的工具ObjCViz,这个工具的作用简单说来,就是把Objective-C的类转化为图表(参见正文中的图形),这样就可以清晰的看出各个类之间的关系和参数、类成员之间的关系。
比如如下的Objective-C的类:
@interface
{
NSString*
}
@end
@interface
{
id
}
@end
@implementation
-(id)init
{
[super
obj
return
}
@end
@interface
{
NSString* d;
id
}
@end
@implementation
-(id)init
{
[super
e
[e
return
}
@end
@interface
{
NSString* strIvar;
NSMutableArray* arrayIvar;
NSMutableDictionary* dictIvar;
Zo*
}
@end
@implementation
-(id)init
{
[super
strIvar
boIvar
arrayIvar
dictIvar
initWithObjectsAndKeys:boIvar,@"Key1",@"Obj2",@"Key2",nil];
return
}
@end
可以将其转化为下面格式的文本:
digraph ObjC {
L001 [label="Ga", style=rounded, shape=box];
L001 -> L002 [label="boIvar",fontsize=12];
L001 -> L003 [label="strIvar",fontsize=12];
L001 -> L004 [label="arrayIvar",fontsize=12];
L001 -> L007 [label="dictIvar",fontsize=12];
L002 [label="Zo", style=rounded, shape=box];
L002 -> (null) [label="d",fontsize=12];
L002 -> (null) [label="superclassIvar",fontsize=12];
L002 -> L009 [label="e",fontsize=12];
L003 [label="@\"aString\""];
L004 [label="{NSCFArray|{|}}",shape=Mrecord];
L005 [label="@\"aStringInArray\""];
L006 [label="NSCFDate", style=rounded, shape=box];
L007 [label="{NSCFDictionary|{ Key2| Key1}}",shape=Mrecord];
L007:f0 -> L008 [label="Key2",fontsize=12];
L007:f1 -> L002 [label="Key1",fontsize=12];
L008 [label="@\"Obj2\""];
L009 [label="NSConcreteScanner", style=rounded, shape=box];
L009 -> L010 [label="scanString",fontsize=12];
L009 -> L011 [label="skipSet",fontsize=12];
L009 -> (null) [label="invertedSkipSet",fontsize=12];
L009 -> (null) [label="locale",fontsize=12];
L010 [label="@\"scannedString\""];
L011 [label="NSBuiltinCharacterSet", style=rounded, shape=box];
L011 -> L012 [label="expandedset",fontsize=12];
L012 [label="NSCFCharacterSet", style=rounded, shape=box];
L013 [label="nil"];
}
而这段文本可以通过GraphViz这个图表工具转化为下面的图表:
工具的作者是Olivier Gutknecht,下载地址为:
http://people.no-distance.net/ol/software/objcviz/
点击左侧的Source Code可以下载。