objective-c-blocks

Under ARC, keep getting EXC_BAD_ACCESS after using ARC, because of using Block?

一个人想着一个人 提交于 2020-01-06 07:59:27
问题 Issue: I keep getting EXC_BAD_ACCESS. And after I open NSZombieEnabled, I saw this [FeatureCommentListViewController respondsToSelector:]: message sent to deallocated instance 0x7c1dc30 Before I changed my project to ARC, there is no such error, but after I changed to ARC, this error appeared. I declare a ViewController in a Block and push it into navigation Controller. Will this reason case it's lifetime shorter? UIBlockButton is from this post UIBlockButton *lbGood3 = [[UIBlockButton alloc]

Objective-C Blocks, Variables and CLGeocoder and/or CLPlacemark

拈花ヽ惹草 提交于 2020-01-06 05:42:09
问题 I'm new to Objective-C and my C/C++ skills are quite rusty. What better time to learn iOS development(!) I'm trying to reverse geolocate a position using the CLGeocoder class in iOS. I can successfully get the data I'm interested in (street address) inside the block/callback, however when I try to use that data to populate my variable (outside of the block) the data isn't there. It's as if the object in the block disappears before the MapView object calls it. I'm using __block which as I

How can I retain a local variable that is set in a block?

故事扮演 提交于 2020-01-05 10:09:39
问题 So I have: @interface testAppControl : NSObject { NSString *s; } and then in my block I want to do [SendAPI setGroupWithName:groupName completionHandler:^(NSArray *errors) { s = @"something"; }]; NSLog(@"%@", s); //<--- s is null So I want to keep the value "something" after I leave my block. Is this possible with ARC? 回答1: Declare it as a __block variable, then you can use it outside the block and alter it inside the block. __block NSString *s = nil; void(^block)(void) = ^ { s = @"something"

EXC_BAD_ACCESS when using weakSelf in block / blocks

若如初见. 提交于 2020-01-04 05:25:41
问题 I have been struggeling with this issue for a while since i don't think i fully understand the retain cycles. I am totally new to this and i'm trying to learn more about it. I am getting the EXC_BAD_ACCESS message with the following code. I started using the weakSelf because i get 2 warnings about the retain cycle if i just use self.successBLock();. The exact warning is: Capturing 'self' strongly in this block is likely to lead to a retain cycle Maybe i shouldn't even bother using the weak

How to convert a delegate-based callback system into block-based?

廉价感情. 提交于 2020-01-03 11:46:48
问题 I have a class, which has a delegate based system for sending different type of requests. it uses delegate to tell the object when the request is complete and also if it was a success o an error. Now, I also have to check what type of request was it in response to take appropriate action. I have wrapper class that should give me a block based interface for the same. I pass a completion-block and an error-block to a request method which should internally use this delegate based class. And when

How to convert a delegate-based callback system into block-based?

僤鯓⒐⒋嵵緔 提交于 2020-01-03 11:45:02
问题 I have a class, which has a delegate based system for sending different type of requests. it uses delegate to tell the object when the request is complete and also if it was a success o an error. Now, I also have to check what type of request was it in response to take appropriate action. I have wrapper class that should give me a block based interface for the same. I pass a completion-block and an error-block to a request method which should internally use this delegate based class. And when

Objective-C - Is there a way for an Object to execute a method IMP directly as if it were its own?

夙愿已清 提交于 2020-01-03 03:54:17
问题 Presume I have an Object, an instance of MyClass. In Objective-C one can ask the Object to "perform" a selector by either sending it a message or using NSObject's "perform". This selector has to be defined at compile time as part of the Class definition, more precisely as an Instance method of that class OR with the help of the Obj-C Runtime, have the method added to the (entire) MyClass at runtime with class_addMethod. My question is as follows: Would it be possible to send an object the IMP

How to Retrieve the Results of “FBSDKGraphRequest” to Use Outside?

左心房为你撑大大i 提交于 2020-01-03 03:15:14
问题 I am using Facebook SDK for iOS. I can output the results with "NSLog" but I do not know how to retrieve the values of the results from FBSDKGraphRequest outside since they are located in a completion block. I need these values for the later manipulations. I tried to put them in NSArray or NSMutableArray but could not make it. The code for the illustration is given below: __block NSMutableArray *results; __block NSArray *obj; if ([[FBSDKAccessToken currentAccessToken] hasGranted:@"user_groups

Cancel block in UIView animateWithDuration

笑着哭i 提交于 2020-01-02 05:40:15
问题 - (void) startLoading { [self blink]; } - (void) blink { [UIView animateWithDuration:0.5 delay: 0.0 options: UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionCurveEaseOut animations:^{ //animate stuff } completion:^(BOOL finished){ [self blink]; }]; } - (void) stopLoading { //What goes here? } In my UIView's initWithFrame , I build some loader graphics then start the loader animation from [self startLoading] . The question is now, how do I stop this 'infinite loop'? or what

Objective-C blocks and variables

我是研究僧i 提交于 2020-01-02 02:01:32
问题 I've started using Objective-C blocks today. I wrote the following code: NSArray *array = @[@25, @"abc", @7.2]; void (^print)(NSUInteger index) = ^(NSUInteger index) { NSLog(@"%@", array[index]); }; for (int n = 0; n < 3; n++) print(n); Which works properly. I needed to change the array variable after its declaration, though, so I tried using the following code: NSArray *array; void (^print)(NSUInteger index) = ^(NSUInteger index) { NSLog(@"%@", array[index]); }; array = @[@25, @"abc", @7.2];