objective-c-blocks

UIButton repeated pressing

霸气de小男生 提交于 2019-12-12 18:54:00
问题 I have a UITableViewCell and I have a UIButton in it. Each time I press the button, there is a network call and it updates a label (increments or decrements the count), something similar to the Facebook 'like' concept. The problem is when the user repeatedly presses the UIButton, the values keep incrementing or decrementing. I tried toggling the userInteraction and also setting the setEnabled state. Still doesnt work. I then tried using blocks as this link suggested. Still not working. I'm

Restkit Get with Params & Block with Shared Client

﹥>﹥吖頭↗ 提交于 2019-12-12 17:08:32
问题 It won't let me attached the params to the request, what am I doing wrong? Params is a Dictionary and endString adds to the sharedClient baseURL. [[RKClient sharedClient] get:endString usingBlock:^(RKRequest *loader){ loader.params = [RKParams paramsWithDictionary:params]; loader.onDidLoadResponse = ^(RKResponse *response) { [self parseJSONDictFromResponse:response]; }; loader.onDidFailLoadWithError = ^(NSError *error) { NSLog(@"error2:%@",error); }; }]; I get this error: RestKit was asked to

Why is this block not global?

三世轮回 提交于 2019-12-12 11:18:35
问题 Consider the following code: #include <stdio.h> typedef void (^block)(); block foo() { char a = 'a'; return [^{ printf("%c\n", a); } copy]; } block bar() { const char a = 'a'; return [^{ printf("%c\n", a); } copy]; } This is what that compiles to for armv7: _foo: @ BB#0: push {r7, lr} mov r7, sp sub sp, #24 movw r3, :lower16:(L__NSConcreteStackBlock$non_lazy_ptr-(LPC0_0+4)) movt r3, :upper16:(L__NSConcreteStackBlock$non_lazy_ptr-(LPC0_0+4)) movw r1, :lower16:(___foo_block_invoke_0-(LPC0_1+4))

Objective C Block Generics

醉酒当歌 提交于 2019-12-12 10:25:39
问题 I'm trying to implement a datasource that can be used to customize several different classes of cells for a tableview, but I'm having trouble with a generic type in a block that I'm passing to the constructor. Here is the implementation of the header file of the datasource : @interface ABParseDatasource<__covariant ObjectType: UITableViewCell *> : NSObject <UITableViewDataSource> - (instancetype)initWithCellIdentifier:(NSString *)identifier parseQuery:(PFQuery *)query tableView:(UITableView *

Calling objective C code block from delphi

点点圈 提交于 2019-12-12 10:06:23
问题 I'm trying to make background fetch work in my firemonkey application. I've gotten so far that my perfromFetchWithCompletionHandler gets called and downloads new information. The problem comes when I'm done with my fetch and need to call the completionHandler code block, the app hangs and I don't get any exception (that I can read at least) Setup: TBackgroundFetchResultHandlerC = procedure ( AResult : NSUInteger ); cdecl; .. .. procedure performFetchWithCompletionHandler(self : id; _cmd : SEL

Reference Counting of self in Blocks

百般思念 提交于 2019-12-12 08:58:11
问题 I'm trying to get my head around how object lifetime and reference counting interact with code blocks. In the following code I'm just doing a simple animation that flashes as the top view on a UINavigationController's stack is swapped. The tricky part is that the popped view controller is the one where this code is defined . [UIView animateWithDuration:0.2 animations:^{self.navigationController.view.alpha = 0.0;} completion:^(BOOL finished){ UINavigationController *navController = self

Double pointer as Objective-C block parameter

被刻印的时光 ゝ 提交于 2019-12-12 07:58:35
问题 Is it possible (and if so, safe) to create/use a block which takes a double pointer as an argument? For instance: - (void)methodWithBlock:(void (^)(NSError **error))block; Additional context, research, and questions: I'm using ARC. When I declare the method above and attempt to call it, XCode autocompletes my method invocation as follows: [self methodWithBlock:^(NSError *__autoreleasing *error) {}]; What does __autoreleasing mean here and why is it being added? I presume it has something to

Setting up a block property in custom class

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 05:15:56
问题 I have a third party API that exposes an imageBlock property. I am new to Blocks - how should I set this Block in my class? @property (copy) NSString *(^imageBlock)(NSString *key, NSString *value, BOOL *send); 回答1: Your syntax is correct, however, for sanity and readability I would recommend a typedef to create another name for this Block signature: // MyClass.h typedef NSString * (^ImageBlock)(NSString * key, NSString * value, BOOL * send); Your property declaration then becomes: @property

Does a passing of an object to a block guarantee that its lifecycle will be retained?

陌路散爱 提交于 2019-12-12 04:59:13
问题 Let's assume I have the following typedef: typedef void (^myBlock)(id); And I have some method myMethod accepting myBlock as an argument and yielding some id variable to it: void myMethod(id myObj, myBlock block) { // ... block(myObj); // ... } So if I have the following: - (void) someMethod { __block id myObj; // Some initialization local to the scope of someMethod; // myObj = ... some assignment to myObj so it is not nil... dispatch_async(someQueue(), ^{ // (*) Some long, possibly multi

iOS - Concatenating asynchronous block-based operations

淺唱寂寞╮ 提交于 2019-12-12 04:13:19
问题 How would you perform N asynchronous operations, such as network calls, working with completion block operations and no delegates/notifications? Given N methods like this: - (void)methodNWithCompletion:(void (^)(Result *))completion { Operation *operation = [Operation new]; // ... // Asynchronous operation performed here // ... return; } A straightforward solution would be to call each operation in the completion block of the previous one: [self method1WithCompletion:^(Result *result) { // ..