objective-c-blocks

__block attribute on instance variable issue.

被刻印的时光 ゝ 提交于 2019-12-23 22:48:30
问题 I have encountered the following error while compiling an Objective-C class: VideoView.h:7: error: __block attribute can be specified on variables only Also here is the important part of the header file: #import <UIKit/UIKit.h> #import <AVFoundation/AVFoundation.h> @interface VideoView :UIView{ @private __block AVPlayer *player; } ... Is there any explanation why g++ thinks that I'm applying the __block attribute on a non-variable object ? 回答1: You can't have __block on an instance variable

Passing blocks to asynchronous methods

自古美人都是妖i 提交于 2019-12-23 20:07:26
问题 I'm passing a block to an asynchronous method which executes this block later. My app crashes if I don't copy the block before passing it to someMethod:success:failure: Is there a way to copy the blocks in forwardInvocation: instead of copying it before passing it to someMethod:success:failure: ? The flow is someMethod:success:failure: -> forwardInvocation: -> httpGet:success:failure httpGet:success:failure: executes the success or the failure block depending on the HTTP status code. //

How to skip objects while iterating in a ruby like Map method for obj-c

有些话、适合烂在心里 提交于 2019-12-23 19:46:28
问题 Using the answer here this method achieves something similar to ruby's map in obj-c: - (NSArray *)mapObjectsUsingBlock:(id (^)(id obj, NSUInteger idx))block { NSMutableArray *result = [NSMutableArray arrayWithCapacity:[self count]]; [self enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { [result addObject:block(obj, idx)]; }]; return result; } my question is how can i skip an object if something wrong happens while applying the block? Typically to skip something in an

Swift Cast AnyObject to Block

南楼画角 提交于 2019-12-23 19:04:11
问题 So I am using the Salesforce SDK and built bridging headers for the entire SDK. They provide a block syntax which hasn't translated into the most usable code. For instance, func sendRESTRequest(request: SFRestRequest!, failBlock: SFRestFailBlock!, completeBlock: AnyObject!) The complete block is AnyObject!. I was able to get around this with var block : @objc_block (dataResponse :AnyObject!) -> Void = { dataResponse in //I handle the response} restService.sendRESTRequest(request, failBlock: {

Objective-C++ block vs Objective-C block

拜拜、爱过 提交于 2019-12-23 15:07:14
问题 In Objective-C I have the valid code: TestTwo.h: @interface TestTwo : NSObject -(void)test; @end TestTwo.m: @implementation TestTwo -(void)test { void (^d_block)(void) = ^{ int n; }; } @end What I really want is an Objective-C++ class that defines a method similar to test . This is simplification, but illustrates the intent. So, in Objective-C++ I have: Test.h: class Test { public: void TestIt(); }; Test.mm: #include "Test.h" void Test::TestIt() { void (^d_block)(void) = ^{ int n; }; } I get

Objective C Blocks as Async-callbacks & BAD ACCESS

无人久伴 提交于 2019-12-23 07:55:21
问题 I've got a serious doubt. Suppose the following scenario: You have a UIViewController onscreen. The app initiates, say, a backend call using a block as a callback You use a 'self' surrogate, to prevent retain cycles. The user hits 'Back', and the UIViewController gets dealloc'ed. Sooner or later, the callback block gets executed >> BAD ACCESS Before iOS 4, we dealt with this kind of situation by setting to nil the delegate property of... i don't know, whatever class you were using. But

Get Friends list from openfire Server

送分小仙女□ 提交于 2019-12-23 06:39:07
问题 How to get all friends programmatically from openfire server in objective C, I am using XMPP Framework for chat Functionality. 回答1: Here is a function to fetch friends. Add your host name in below function. func getList() { let query = try! XMLElement(xmlString: "<query xmlns='http://jabber.org/protocol/disco#items' node='all users'/>") let iq = XMPPIQ(type: "get", to: XMPPJID(string: "Your Host Name"), elementID: xmppStream.generateUUID(), child: query) iq?.addAttribute(withName: "id",

can anyone tell flow of execution of blocks in objective c? [closed]

假装没事ソ 提交于 2019-12-23 06:23:10
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . Hi iam working with Blocks in objective-c. I have just learn syntax, and how to write blocks. But i didn't understand execution flow. I googled it for flow of execution, i can't find. I used the following code :

UIImagePickerController not showing (taking more time to load) camera preview in ios7

做~自己de王妃 提交于 2019-12-23 05:33:15
问题 I am using GCD in my app to fetch lot of images and data in the background queue and when I present uiimagepickercontroller it takes more time to show the camera preview. After googling around, I found that many have faced this issue with iOS 7 and here is one more post that made some sense to me. (iOS 7 UIImagePickerController Camera No Image). The solution was to stop the background threads and then present the picker controller. But I am really stumped and don't know how to stop or pause

How to wait for threading blocks to finish

回眸只為那壹抹淺笑 提交于 2019-12-23 05:27:40
问题 I am having issues with threading in my app. This is the first time I have used both AFNetworking and Parse. The problem is that I am calling both features and they both are required to finish before moving onto the next segue. Here is my code. The first block is for the network request using AFHTTP and the second is the parse request. AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; NSDictionary *parameters = @{@"foo": @"bar"}; [manager POST:@"http://example