objective-c-blocks

Return bool inside pfcloud function

梦想的初衷 提交于 2019-12-08 04:15:58
问题 I'm creating a method that checks if the user has any friends who are already registered to the app. However, when I'm trying to return from within this block, i get a compiler error saying: Incompatible block pointer types sending 'BOOL (^)(__strong id, NSError *__strong)' to parameter of type 'PFIdResultBlock' (aka 'void (^)(__strong id, NSError *__strong)') This is when I run the code below: -(BOOL)hasFriend:(NSArray*)phoneNums{ [PFCloud callFunctionInBackground:@"checkUsers"

How to avoid retain cycle with delaying block invocation on iOS

做~自己de王妃 提交于 2019-12-08 04:02:07
问题 I am really stumped with this one. I have been reading all the info I can get my hands on about how to properly handle variables inside blocks. Note: I am not using arc. So, say I have an animation that looks like this: [UIView animateWithDuration:.5 animations:^{ textCard.alpha = 1.f; self.dotView.alpha = 1.f; self.subtitles.alpha = 0; }completion:^(BOOL finished){ [self.playerLayer removeFromSuperlayer]; self.playerLayer = [AVPlayerLayer playerLayerWithPlayer:self.vidPlayer]; self

Geocoding Multiple Locations - Knowing When “All” Completion Blocks Have Been Called

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-08 02:53:45
问题 I am using the CoreLocation's geocoder to get the CLLocation coordinates for multiple map items. The geocoder calls a completion block on completion for each item. How do I create a similar block functionality which is called when all of these containing asynchronous geocoder calls have been completed? (I could use a manual counter. But there must be a more elegant solution) Here's my geocoding function so far. It loops through an array of location items and starts a new geocoding process for

What is a block in C++? [duplicate]

痴心易碎 提交于 2019-12-08 02:00:59
问题 This question already has an answer here : Closed 7 years ago . Possible Duplicate: What is (double (^)(int))foofoo I've tried searching for a definition on Google and SO and I found examples in which they are used but not clearly defined. By "block" I mean the caret symbol ( ^ ). I found it on a site where cdecl they described: (double (^)(int, long long )) foo as cast foo into block(int, long long) returning double I've never once seen this symbol used before today. Can anyone clearly

iOS Background Fetch and completion block

旧时模样 提交于 2019-12-08 01:54:49
问题 I am trying to define this method - (void)backgroundFetchWithCompletion:(void(^)(UIBackgroundFetchResult))completionHandler; However I am getting an error on UIBackgroundFetchResult saying a parameter list without types is only allowed, I was following this tutorial and this tutorial and that is how they define their method. 回答1: After executing some operation at the end you must call one in list. Objective-C completionHandler(UIBackgroundFetchResultNewData); completionHandler

Reading CGImageRef in a background thread crashes the app

空扰寡人 提交于 2019-12-08 00:19:51
问题 i have a big jpeg image that i want to load in tiles asynchronously in my opengl engine. Everything works well if its done on the main thread but its slow. When i try to put the tile loading on an NSOperationBlock, it always crashes when trying to access the shared image data pointer that i previously loaded on the main thread. There must be something i don't get with background operation because i assume i can access memory sections that i created on the main thread. What i try to do is the

loading images in table using blocks - dispatch_async return value

我的未来我决定 提交于 2019-12-07 20:47:27
I have looked around on SO and the web and have not found a specific answer. Quite simply, I have a table loading images info from Flickr. I want to display a thumbnail of the image on the left side of each cell. In order to do this without blocking the main (UI) thread, I am using blocks: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"top50places"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; //getting the selected row image NSDictionary*

Recursive block gets deallocated too early

我怕爱的太早我们不能终老 提交于 2019-12-07 20:00:41
问题 I have written a recursive block following these guidelines: NSMutableArray *groups = [NSMutableArray arrayWithArray:@[@"group1", @"group2", @"group3", @"group4"]; __block CommunicationCompletionHandler completion = [^{ [groups removeObjectAtIndex:0]; if ([groups count] > 0) { // This will send some information to the network, and calls the completion handler when it receives a response [mySocket saveGroup:groups[0] completion:completion]; } } copy]; // Removing copy here doesn't work either

Calling objective-C typedef block from swift

主宰稳场 提交于 2019-12-07 18:56:43
问题 I'm trying to call a method from swift. The method is in a singleton written in objective-C the block in the header file: typedef void(^VPersonResultBlock)(Person *person, NSError *error); - (void)askForMe:(VPersonResultBlock)block; and here's the implementation of that method. - (void)askForMe:(VPersonResultBlock)block { if (_me) block(_me,nil); else { [Person getMeWithBlock:^(PFObject *person, NSError *error) { if (!error) { _me = (Person *)person; block(_me,nil); } else if (error) { block

What is a simple rule to avoid objective-c block retain cycle memory leaks?

試著忘記壹切 提交于 2019-12-07 17:55:14
问题 I've had it with memory leaks arising from block retain cycles. I would just like a simple rule that I can apply to my code to make sure I avoid them. On the other hand, I don't want to update half of my code base base to __weak pointers without it being necessary. Here is what I have up to now: There can be no memory leaks when you use the following: dispatch_async(queue, ^{...}); // GCD call. [Foo bar:^{...}]; // Class "+" methods with completion block. However, these cases will cause block