objective-c-blocks

Execute a method after the completion of a block method

点点圈 提交于 2019-12-25 00:03:45
问题 I am using RNFrostedSidebar for leftmenu. While dismissing the sidebar, below block of code is executing - (void)handleTap:(UIPanGestureRecognizer *)recognizer { [self dismissAnimated:YES completion:nil]; } - (void)dismissAnimated:(BOOL)animated completion:(void (^)(BOOL finished))completion { void (^completionBlock)(BOOL) = ^(BOOL finished){ [self rn_removeFromParentViewControllerCallingAppearanceMethods:YES]; rn_frostedMenu = nil; if (completion) { completion(finished); } }; if (animated) {

MKNetworkKit and GCD dispatch_group_t

不羁的心 提交于 2019-12-24 19:46:30
问题 I am trying to use MKNetworkKit to fetch an array of links from a web service, then parse each response on a background thread, and use the dispatch_group_t of GCD to wait until all threads are finished processing. Where I'm stuck is I can't figure out why my dispatch_group_notify is not waiting for all threads in the group to complete. Running this code will print: results count: 0 added into results, count: 1 added into results, count: 2 The dispatch group is not waiting on its threads. I

iOS - prepareForSegue doesn't wait for the completionBlock to be completed

╄→尐↘猪︶ㄣ 提交于 2019-12-24 18:37:18
问题 What I like: Wait until data download completes then open TableView and show data . What I have: When prepareForSegue is called the TableView opens immediately without waiting for the data download although I have a completionBlock (which may not be implemented correctly I guess). Note: When I go back and open the TableView again I see the data . - (void)fetchEntries { void (^completionBlock) (NSArray *array, NSError *err) = ^(NSArray *array, NSError *err) { if (!err) { self.articlesArray =

BAD ACCESS after block within a block is called (iOS)

不羁岁月 提交于 2019-12-24 13:40:31
问题 I have a block where I am checking a user's status property from firebase. If the status property is 'free' I want to return from the block, otherwise I want to search for another user and check their status and do so until a 'free' user has been found: void( ^ myResponseBlock)(BOOL finished) = ^ void(BOOL finished) { if (finished) { if ([self.freedom isEqualToString: @"free"]) { NSLog(@"free!"); return; } else if ([self.freedom isEqualToString: @"matched"]) { NSLog(@"get another user"); /

Is accessing instance variables by reference safe?

我只是一个虾纸丫 提交于 2019-12-24 13:35:05
问题 What is the difference between the two code snippets below: 1. __block __weak NSMutableArray *arrBlock = self.arr ; [[AsyncRequest initRequest:url onCompletedBlock:^(NSMutableArray *arr) { arrBlock = arr; }]ExecuteRequest]; 2. id __weak weakself = self; [[AsyncRequest initRequest:url onCompletedBlock:^(NSMutableArray *arr) { weakself.arr = arr; }]ExecuteRequest]; Neither of them cause retain cycles, but Apple suggests using the first one. Is there a problem with the second one? 回答1: They have

iOS: Waiting for API Completion Block and returning the result

房东的猫 提交于 2019-12-24 12:26:08
问题 Using inheritance. I have a child class that calls a method in the parent class that runs calls the server API. -(IBAction)buttonPressed { [self methodInParentClassThatCallsTheAPI:param]; // This is where I would like the call back if (success from the server API) // do something with the UI else if (failure from the server API) // do so something else with the UI } Parent Class: - (void)methodInParentClassThatCallsTheAPI:(NSString *)param { //The method below calls the server API and waits

Is this the right way for a block inside a struct to access a member variable in the same struct?

柔情痞子 提交于 2019-12-24 06:45:02
问题 I'm experimenting with Obj-C blocks and trying to have a struct with two blocks in it where one block is to change what the other block does. this is a really roundabout way to do something simple... and there may be better ways to do it, but the point of the exercise is for me to understand blocks. here's the code , it doesn't work, so what am I missing/not understanding and/or doing wrong? //enumerate my math operation options so i can have something more understandable //than 0, 1, 2, etc.

How to change int value in block?

删除回忆录丶 提交于 2019-12-24 02:14:26
问题 How change int value in block, I have this : __block long long size = -1; ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset) { ALAssetRepresentation * rep = [myasset defaultRepresentation]; size = [rep size]; //here showed normal value NSLog(@"needed size : %lld",size); }; ALAssetsLibrary* assetslibrary = [[[ALAssetsLibrary alloc] init] autorelease]; [assetslibrary assetForURL:self.tmpVideoURL resultBlock:resultblock failureBlock:nil]; //but here remaind -1 NSLog(@"out

Calling a block though runtime, anything similar to NSInvocation?

空扰寡人 提交于 2019-12-24 01:45:24
问题 I have block of unknown type (as id ) and array of arguments that need to passed into that block. Arguments may be objects or numbers/structs boxed as NSNumber/NSValue. Block may also return an object, number or struct. This is a library code, and types of arguments are not known beforehand. Assuming that I can can dynamically read signature from the block descriptor, is there a way to construct something like an NSInvocation to call a block? 回答1: Surprisingly this works: CGAffineTransform (

Handle ContainerViewController's action in ParentViewController

家住魔仙堡 提交于 2019-12-24 00:41:17
问题 I have followed this link to implement the compleltionblock @interface : ParentViewController () @property (nonatomic, strong) ChildViewController *childViewController; @end In Parent View Controller's Table View Delegate method (didSelectRowAtIndexPath) I am adding container view as follows - (void) addChildView { ChildViewController * childViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"ChildViewController"];