Cycript 笔记

cycript -p "appname"

查看view结构:

?expand
[[UIApp keyWind] recursiveDescription]

窗口操作:

ctl + c 取消(cancel)一个方法
ctrl + d 退出 cycript 或者用 ?exit

CYON(Cycript Object Notation) 和 ?命令

?syntax 切换语法高亮
 ?exit 退出 cycript
 ?expand 切换字符串打印方法,对于 \n 这样的字符是否解析成换行。?expand to toggle the behavior of whether the console attempts to print string syntax or string values.
 ?debug 切换显示 crcript 的解析处理过程
 ?gc 或者 gc() 强制触发 javascript 的垃圾回收机制

tab 补全

Class.messages 返回该类的所有方法
(instance).constructor 返回该实例的类

为类添加方法

NSNumber.prototype.add5 = function() { return this + 5; }

访问 ivar

c = [[UIApp windows][0] contentView]

c->_subviewCache

*c // 显示所有 ivar, 包括私有的

异常处理

var a; try { [@[0] setObject:nil atIndex:0]; } catch (e) { a = e; throw e; }

获取方法签名

NSObject.messages[@selector(description)].type
@selector(description).type(NSObject) // @encode(id(id,SEL))

Category

@implementation NSObject (MyCategory)  
- description { return "hello"; }     // 覆盖已有的方法不需要指明返回值和参数  
- (double) f:(int)v  { return v * 0.5; } // 定义新方法需要指明返回值和参数  
@end

o = [new NSObject init] // “hello”
[o f:3] // 1.5

创建一个类

@implementation A : NSObject {  
     int field;  
}  
- (int) message { return this->field; }  
@end 

添加新评论

返回顶部