मैं स्वयं के अंदर के ब्लॉक के उपयोग से भ्रमित हो रहा हूं, मैं ऐप्पल के कुछ दस्तावेजों से गुजरता हूं लेकिन अभी भी सही जवाब नहीं मिल रहा है।क्या हमेशा ब्लॉक के अंदर स्वयं को कमजोर संदर्भों का उपयोग करना आवश्यक है ..?
कुछ लोगों को हमेशा ब्लॉक के अंदर कमजोर स्वयं का प्रयोग करते हैं, लेकिन कुछ ब्लॉकों कि कॉपी कर रहे हैं, हमेशा उपयोग करने के लिए neassary नहीं में कमजोर स्वयं प्रयोग करते हैं।
नमूना 1:
self.handler = ^(id response, NSError *error)
{
self.newresponse = response; //use weak self here
};
नमूना 2:
कमजोर स्वयं का उपयोग करना;
__weak myViewController *weakSelf = self;
[UIView animateWithDuration:interval delay:0.0 options:curve animations:^
{
[weakSelf.view.superview setTransform:CGAffineTransformMakeTranslation(0, -106)];
//in above is it use of weak is neassary
}
completion:^(BOOL finished)
{
}];
कमजोर स्वयं के बिना;
__weak myViewController *weakSelf = self;
[UIView animateWithDuration:interval delay:0.0 options:curve animations:^
{
[myViewController.view.superview setTransform:CGAffineTransformMakeTranslation(0, -106)];
}
completion:^(BOOL finished)
{
}];
उपरोक्त नमूने में, जो सही हैं ...? ** मैं एआरसी
\ _ \ _ कमजोर ऑब्जेक्ट (आईओएस 5 + एआरसी) के बिना ब्लॉक में संभवतः [[स्वयं किसी भी समारोह \] को पास करने के संभावित संभव डुप्लिकेट (http://stackoverflow.com/questions/9003600/possible-to-pass- स्वयं-असफलता-इन-ब्लॉकों-बिना-कमजोर-ऑब्जेक्ट-आईओएस -5-आर्क) – Abizern
http://stackoverflow.com/questions/20030873/always-pass-weak-reference-of-self-into का डुप्लिकेट -ब्लॉक-इन-आर्क –