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 This is not an ARC! It does not make any difference in declaring the variable with There are several things in this code about 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 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 Finally, the object pointed out by In addition, you should use the Then in conclusion, this would be more: 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.
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:
__ block . how are you?
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.
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.
Page goes to HTML and
feedback .
viewData has been leaked, as you have a strong reference to (you
new ) But do not release it.
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:
- (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
Post a Comment