block execution iOS and assigning variable -


I am using drupal-ios-sdk (based on AFNetworking) and in my app tab created with storyboard Bar is the controller. While loading one of the view controllers, I am making a request with drupal-ios-sdk in initWithCoder and specifying an instance variable in the success block . Later, viewDidLoad I try to print this variable and I'm interested in why I have to retain the frequency variable in the success block, even if I define variables with an array.

This is not an ARC!

No use to maintain success block

my VCH
  @interface AboutViewController: UIViewController {@private NSDictionary * response; NSString * aboutPageHTML; } @end   

my VC.m
  - (id) initWithCoder: (NSCoder *) aDecoder {if ((self = [super initWithCoder: aDecoder ])) {NSDictionary * viewData = [NSMutableDictionary new]; [ViewData setValue: @ "aboutse" for: @ "view_name"]; About page HTML = [[[NSString alloc] init] autorelease]; Zero (^ success block) (FHTPPRequest operation *, ID) = ^ (FHTPPKAESTA Operation * Operation, ID response object) {response = [response object copy]; AboutPageHTML = [Feedback value forKey: @ "body"]; NSLog (@ "% s -% @", __PRETTY_FUNCTION__, about page html); [About page html maintained]; // Important! }; [DIOSView viewGet: viewData Success: Successblocks Failure: ^ (FHTPPKAESTA Operation * Operation, NSERR * Error) {NSLog (@ "% s,% @", __PRETTY_FUNCTION__, error); }]; } Healthy return; } - (zero) viewDidoadload [[Super Viewedload]; // Setup an additional after loading the view NSLog (@ "% s -% @", __PRETTY_FUNCTION__, AboutPageHTML); NSLog (@ "% s -% f% f", __PRETTY_FUNCTION__, self .view.bound.edim; size.width, self.view.bounds.size.height); }   

Edit:

It does not make any difference in declaring the variable with __ block . how are you?

There are several things in this code about about page HTML a frequency variable That you want a strong reference (i.e. should be maintained). About aboutPageHTML = [[[NSString alloc] init] autorelease] You are not maintaining a strong context for it. This is incorrect.

And later, in your block of success (it is irrelevant that it is a block, it is only of any code that runs later), you can see about about page HTML = [ Forkey reaction: @ "tan"]; [About page html maintained]; which maintains the object stored in that frequency variable, so you are incompatible with memory management for the same instance variable in two places.

In addition, when you give another value in a referenced variable, then you should make sure that you have to leave the previous value, which you are not doing about both Page goes to HTML and feedback .

Finally, the object pointed out by viewData has been leaked, as you have a strong reference to (you new ) But do not release it.

In addition, you should use the setObject: forKey: and ObjectForreq: for dictionaries and you need to declare an unseen dictionary when You want a dictionary that you can change. (This is probably the reason why you decided to use (code incorrectly) setValue: forKey:

Then in conclusion, this would be more:

  - (id) initWithCoder: (NSCoder *) aDecoder {if ((self = [super initWithCoder: aDecoder])) {NSMutableDictionary * viewData = [NSMutableDictionary new]; [ViewData setObject: @ "aboutse" for: @ "view_name"]; AboutPageHTML = [[NSString alloc] init]; Zero (^ success block) (FHTPPRequest operation *, ID) = ^ (FHTPPKAESTA Operation * Operation, ID Response Object) {[Response Release]; Response = [response object copy]; [About HTML release]; About pageHTML = [[[Feedback objectForKey: @ "body"] maintained]; }; [DIOSView viewGet: viewData Success: Successblocks Failure: ^ (FHTPPKAESTA Operation * Operation, NSERR * Error) {NSLog (@ "% s,% @", __PRETTY_FUNCTION__, error); }]; [ViewData release]; } Healthy return; }    

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -