IOS block 记录

1.需要使用 @property(....,copy) 而不是其他的

2.self.request=[ASIHTTPRequest requestWithURL:[NSURL URLWithString:url]];

[_request setRequestMethod:@"GET"];

__weak ASIHTTPRequest *_requestCopy = _request;

__weak RegistUserViewController *this = self;

[_request setCompletionBlock:^{

this.mobileField.enabled= YES;

this.nextStepBtn.enabled = YES;

NSInteger statusCode = [_requestCopy responseStatusCode];

NSString *result = [_requestCopy responseString];

}];

或者  直接__weak ASIHTTPRequest req = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://www.baidu.com"]];

3.

对于property就用点操作符 bself.xxx
对于非property的成员变量就用->操作符 bself->xxx

最后总结,所有的这些都是围绕一点,block会retain相应的变量,我们要使用用弱引用修饰的变量

原文地址:https://www.cnblogs.com/rollrock/p/4643027.html