objective-c-blocks

Return Result of Completion Block

孤街醉人 提交于 2019-12-28 07:03:54
问题 So I'm trying to build a layer on top of the Twitter API (among others) for a project and I need to find a way to return the result of the Twitter actions to the layer of abstraction. Right now my setup is something like this, for example: -(NSDictionary *)sendTweet:(Tweet *)tweet { __block NSMutableDictionary *responseDictionary; NSLog(@"Sending tweet"); NSMutableDictionary *twitterRequestDictionary = [[NSMutableDictionary alloc] init]; [twitterRequestDictionary setObject:tweet.tweetBody

iPhone App Crash with error [UIApplication _cachedSystemAnimationFenceCreatingIfNecessary:]

这一生的挚爱 提交于 2019-12-28 06:32:07
问题 I have an iPhone App in the app store which is using Touch ID. If Touch ID is enabled, the user is authenticated with it, else user needs to enter his PIN to login to the application. After IOS 10.1 release, when I checked the crash report, the crash count has increased. From the crash report, it is pointing on [UIApplication _cachedSystemAnimationFenceCreatingIfNecessary:] and when I opened the app in Xcode, it is focussing on [self dismissViewControllerAnimated:YES completion:nil]; . The

Declare a block method parameter without using a typedef

我与影子孤独终老i 提交于 2019-12-28 04:40:07
问题 Is it possible to specify a method block parameter in Objective-C without using a typedef? It must be, like function pointers, but I can't hit on the winning syntax without using an intermediate typedef: typedef BOOL (^PredicateBlock_t)(int); - (void) myMethodTakingPredicate:(PredicateBlock_t)predicate only the above compiles, all these fail: - (void) myMethodTakingPredicate:( BOOL(^block)(int) ) predicate - (void) myMethodTakingPredicate:BOOL (^predicate)(int) and I can't remember what other

Assigning a variable value from an Objective-C Block

送分小仙女□ 提交于 2019-12-25 18:53:29
问题 In Swift I can give a variable a value using an anonymous closure: let thumbnailImageView: UIImageView = { let imageView = UIImageView() imageView.backGroundColor = UIColor.blueColor() return imageView; } addSubView(thumbnailImageView) thumbnailImageView.frame = CGRectMake(0,0,100,100) I am trying to do the same in Obj-C, but this results in an error when adding the subview and setting its frame: UIImageView* (^thumbnailImageView)(void) = ^(void){ UIImageView *imageView = [[UIImageView alloc]

Can __weak self turn nil in the middle of the block?

情到浓时终转凉″ 提交于 2019-12-25 08:58:20
问题 When using a __weak self reference in my block that runs on a background thread, do I only need to check for nil in the beginning, or can the __weak self become nil even during execution after the first nil test has passed? I want to access some ivars from self in the block and I need the latest values at the time the block is executing. 回答1: If no one is holding a reference to self then yes. You can mitigate this by taking a strong reference in the block __weak __typeof(self) weakSelf = self

creating UITableViews in array block enumeration causes crash

一曲冷凌霜 提交于 2019-12-25 06:49:51
问题 so the story goes like this :) i am trying to block enumerate objects in an NSArray and dynamically create UITableViews for each of them and add them in UIScrollView. i am using Lighter View Controllers from www.objc.io for the sake of readability and reusability. the dataSource gets created for each UITableView separately. the problem is i crash all the time with -[NSObject(NSObject) doesNotRecognizeSelector:] i found out from posts on stack that objects in block enumeration are weak

The program flow going wrong

拈花ヽ惹草 提交于 2019-12-25 02:57:10
问题 In this code snippet the flow of program goes out of for loop first then only goes inside the block resultBlock:^(ALAsset *asset). The code prints the NSLog at the bottom first then executes the block inside the loop. What's happening here? ALAssetsLibrary *lib=[ALAssetsLibrary new]; _sizeOfSelectedImage=0; for (int i=0; i<assets.count; i++) { ALAsset *asset=assets[i]; FileOP *fileMgr=[[FileOP alloc]init]; NSString *baseDir=[fileMgr GetDocumentDirectory]; //STORING FILE INTO LOCAL [lib

Grand Central Dispatch and functions

自古美人都是妖i 提交于 2019-12-25 02:43:35
问题 I've been looking at this question to try to solve the problem I have here. The tl;dr is I want to use GCD to let me show a "Waiting" screen while I preform some tasks, then hide the screen when it's done. Right now, I have - (void) doStuff { // Show wait on start [self.waitScreen setHidden:NO]; dispatch_queue_t queue = dispatch_queue_create("com.myDomain.myApp",null); dispatch_async(queue, ^{ dispatch_async(dispatch_get_main_queue(), ^{ // Double nesting the dispatches seems to allow me to

block execution iOS and assigning variable

为君一笑 提交于 2019-12-25 01:52:39
问题 I am using the drupal-ios-sdk (based on AFNetworking) and my app has a Tab Bar Controller created with storyboard. When loading one of the view controllers I am creating a request in initWithCoder with drupal-ios-sdk and assigning an instance variable in the success block . Later in viewDidLoad I try to print this variable and I'm interested in why I have to retain the instance variable in the success block, even if I define the variable with autorelease. This is not ARC! Not using retain in

How to make UIBlockButton suit with ARC?

我怕爱的太早我们不能终老 提交于 2019-12-25 01:39:54
问题 I am using the UIBlockButton code from this post: typedef void (^ActionBlock)(); @interface UIBlockButton : UIButton { ActionBlock _actionBlock; } -(void) handleControlEvent:(UIControlEvents)event withBlock:(ActionBlock) action; @implementation UIBlockButton -(void) handleControlEvent:(UIControlEvents)event withBlock:(ActionBlock) action { _actionBlock = Block_copy(action); [self addTarget:self action:@selector(callActionBlock:) forControlEvents:event]; } -(void) callActionBlock:(id)sender{