objective-c-blocks

Any way to have completionHandler style syntax using [facebook authorize] on iOS 5?

浪子不回头ぞ 提交于 2019-12-23 02:45:32
问题 The code below is trying to lazy login to Facebook right before posting a photo, but has an asynchronous problem. In the logs, the after isSessionValid block will appear before the fbDidLogin and then a facebookErrDomain error 10000 will happen ("OAuthException", "active access token must be used", etc). MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate]; if (![appDelegate.facebook isSessionValid]) { [appDelegate.facebook authorize:[NSArray

How to keep a strong reference inside of a block without having a retain cycle

一世执手 提交于 2019-12-23 02:19:06
问题 I have a block attached to a button (using this category): __unsafe_unretained typeof(UIImage) *weakPic = originalPic; [button addEventHandler:^{ switch (state) { case state1: { UIViewController *vc = //some VC vc.pic = weakPic; // weakPic is nil at this point // putting originalPic here would solve my problem // but then I would have a retain cycle } case state2: { // other stuff } } }]; the action associated with the button is different depending on the state. Here is the problem: I must

How manipulate Block Objective C in AFNetworking?

半城伤御伤魂 提交于 2019-12-22 18:36:56
问题 What I do is this: My class1 (called a method, and expects llamda) -> class2 (also called a method and waiting for a call) -> class3 (recently this class queries the JBoss server AFNetworking) . And use the method AFNetworking: - (AFHTTPRequestOperation *) POST: (NSString *) URLString parameters: (NSDictionary *) parameters constructingBodyWithBlock: (void (^) (id <AFMultipartFormData> FormData)) block success: (void (^) (* AFHTTPRequestOperation operation, responseObject id)) success failure

call a method in a block?

两盒软妹~` 提交于 2019-12-22 18:24:30
问题 I'm new to ARC. I want to call a method in a complete block, but I get the warning: Capturing 'self' strongly in this block is likely to lead to a retain cycle. . Code: - (void) handlerComplete { //... } - (void) loadData { ... operation.completeBlock = ^(NSInteger index) { [self handlerComplete]; }; } Any advice? Thanks. 回答1: Try with - (void) loadData { __weak MyClassType *myClass = self; operation.completeBlock = ^(NSInteger index) { [myClass handlerComplete]; }; } 回答2: Make a weak

Recursion with blocks in objective-c

隐身守侯 提交于 2019-12-22 10:09:05
问题 I am receiving EXC_BAD_ACCESS signal in my iOS application when doing a recursion that involves objective-c blocks. Here is the simplified code: - (void)problematicMethod:(FriendInfo*)friendInfo onComplete:(void(^)(NSString*))onComplete1 { [self doSomethingWithFriend:friendInfo onComplete:^(Response* response) { switch (response.status) { case IS_OK: onComplete1(message); break; case ISNT_OK: // Recursively calls the method until a different response is received [self problematicMethod

Strange ordering of Kiwi iOS context blocks

妖精的绣舞 提交于 2019-12-22 09:47:42
问题 I have a Kiwi spec file that looks something like this: #import "Kiwi.h" #import "MyCollection.h" SPEC_BEGIN(CollectionSpec) describe(@"Collection starting with no objects", ^{ MyCollection *collection = [MyCollection new]; context(@"then adding 1 object", ^{ MyObject *object = [MyObject new]; [collection addObject:object]; it(@"has 1 object", ^{ [collection shouldNotBeNil]; [collection.objects shouldNotBeNil]; [[theValue(collection.objects.count) should] equal:theValue(1)]; //failing test })

How can I perform the handler of a UIAlertAction?

a 夏天 提交于 2019-12-22 08:44:29
问题 I'm trying to write a helper class to allow our app to support both UIAlertAction and UIAlertView . However, when writing the alertView:clickedButtonAtIndex: method for the UIAlertViewDelegate , I came across this issue: I see no way to execute the code in the handler block of a UIAlertAction . I'm trying to do this by keeping an array of UIAlertAction s in a property called handlers @property (nonatomic, strong) NSArray *handlers; and then implement a delegate like such: - (void) alertView:

Executing Code Block In Place Of @selector

前提是你 提交于 2019-12-22 08:21:18
问题 I'm creating a barButton which when pressed should set the editing mode of a UITableView to yes. Here's my code: self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle: @"Edit" style: self.navigationController.navigationItem.leftBarButtonItem.style target: self action: ]; What I don't understand is what I need to put as an argument for the action part so that I can execute a code block there. I could easily enough put @selector(someMethod) but I'm only executing one

Accessing a core data NSManagedObject after resuming from background crashes the app

回眸只為那壹抹淺笑 提交于 2019-12-22 05:24:20
问题 I'm using core data and have found the app sometimes crashing after resuming from background. I've identified the crash occurring inside a block method body when I try to access a property on a NSManagedObject subclass. I have a property which holds a reference to a NSManagedObject subclass. @property(nonatomic,strong) CalItem *calObject; To reproduce the crash I first need to call the child viewController( NoteViewController ) passing a block ( NoteTextBlock ). NoteViewController

pass block as parameter in my case

依然范特西╮ 提交于 2019-12-22 01:48:26
问题 I have a function which takes a block as parameter: typedef void (^ MyBlock)(int); -(void)doTask:(MyBlock)theBlock{ ... } I need to run above function on another thread, I want to use - performSelector:onThread:withObject:waitUntilDone: , my current code: NSThread *workerThread = [[NSThread alloc] init]; [workerThread start]; [self performSelector:@selector(doTask:) onThread:workerThread withObject:??? waitUntilDone:NO]; BUT, How can I pass MyBlock parameter with this approach? (Please don't