objective-c-blocks

Using sendAsynchronousRequest:queue:completionHandler: for URL request

送分小仙女□ 提交于 2019-12-11 17:08:14
问题 I'm working on an update of an iOS app that another developer created. He was using ASIHTTPRequest to handle http requests. However, the version of the app I have to work with crashes. Since ASIHTTPRequest is not being updated anymore, I thought then that I should switch to using AFNetworking, but it's far too complicated for me to figure out. So finally I thought I could just use NSURLConnection on its own. Here is the original code that I'm trying to replace: -(NSArray*)readUTF16LEFeed:

Crash when using (animation) blocks in switch statements

浪尽此生 提交于 2019-12-11 16:19:08
问题 This code works (if-statement with animations): // works if (_camOrientation == UIDeviceOrientationPortrait) { [UIView animateWithDuration:0.5f animations:^(void){ [_distanceView setTransform:CGAffineTransformMakeRotation(degreesToRadian(0.0))]; }]; } else if (_camOrientation == UIDeviceOrientationLandscapeLeft) { [UIView animateWithDuration:0.5f animations:^(void){ [_distanceView setTransform:CGAffineTransformMakeRotation(degreesToRadian(90.0))]; }]; } This also works (switch-statement

How to return the ouput if method is using NSURLConnection Asynchronous calls with blocks

本小妞迷上赌 提交于 2019-12-11 14:50:12
问题 I am sending request to server to get response using NSURLConnection blocks method. I am not able to use return YES or return NO in the block. How can i fix this? -(BOOL)checkForValidUrl:(NSString *)url { __block int httpStatus=0; NSMutableURLRequest *request=[[NSMutableURLRequest alloc]initWithURL:[NSURL URLWithString:url]]; [request setValue:@"application/json" forHTTPHeaderField:@"content-type"]; [request setValue:@"application/json" forHTTPHeaderField:@"Accept"]; [NSURLConnection

IOS dispatch_get_main_queue() is called multiple times

本小妞迷上赌 提交于 2019-12-11 14:23:20
问题 I test internet connection with Reachability and dispatch_async(dispatch_get_main_queue() when I test the following code it works but it is called multiple times. Parent: @protocol RootViewDelegate <NSObject> @optional -(void)internetIsDownGoToRoot; @end - (void)testInternetConnection { internetReachableFoo = [ReachabilityTony reachabilityWithHostname:@"www.google.com"]; __weak typeof(self) weakSelf = self; // Internet is reachable internetReachableFoo.reachableBlock = ^(ReachabilityTony

Turning a NSDictionary into a string using blocks?

余生长醉 提交于 2019-12-11 13:56:59
问题 I'm sure there is a way to do this using blocks, but I cant figure it out. I want to to turn an NSDictionary into url-style string of parameters. If I have an NSDictionary which looks like this: dict = [NSDictionary dictionaryWithObjectsAndKeys:@"blue", @"color", @"large", @"size", nil]]; Then how would I turn that into a string that looks like this: "color=blue&size=large" EDIT Thanks for the clues below. This should do it: NSMutableString *parameterString; [dict

Return type “NSComparaisonResult” after the XCode update

空扰寡人 提交于 2019-12-11 10:00:56
问题 I have a problem similar to the one outlined here: Has xcode 4.5 changed sortedArrayUsingComparator + blocks? int index = [AAjouter indexOfObject:match inSortedRange:NSMakeRange(0, [AAjouter count]) options:NSBinarySearchingInsertionIndex usingComparator:^(id obj1, id obj2) { Match *match1 = (Match *) obj1; Match *match2 = (Match *) obj2; if ([match1.matchDate isEqualToDate:match2.matchDate]) { if ([match1.paysCompetition isEqualToString:match2.paysCompetition]) { if ([[NSNumber numberWithInt

How do I return a value determined within a delay_after block? [duplicate]

做~自己de王妃 提交于 2019-12-11 09:19:13
问题 This question already has answers here : Returning method object from inside block (3 answers) Closed 5 years ago . Very new to Objective-C and having a rough time figuring out how to accomplish the following. I come from a javascript background, so I may not be approaching this in the correct way. In my view controller I'm making a call to a class method getLuminosity . I want to collect some float 's from the camera for 7 seconds, average them, and then return that average but have no clue

Getting variable from the inside of block [duplicate]

試著忘記壹切 提交于 2019-12-11 09:15:35
问题 This question already has answers here : How do I return a variable from a block inside a method? (3 answers) AFHTTPRequestOperationManager return data in block (1 answer) Closed 5 years ago . I'm using AFNetworking 2 to GET data from server and I need to get back the responseObject but no matter what I do i still get <null> . Here is the method which is sending GET request to server and in response it gets NSDictionary which I want to use in another method... - (void

How to invoke Objective-C block property in Swift

▼魔方 西西 提交于 2019-12-11 08:48:34
问题 I am rewriting some Objective-C code in Swift . It is a subclass from an open library called ActionSheetPicker. So here is my Objective-C code: #import "XXActionSheetStringPicker.h" @implementation XXActionSheetStringPicker + (instancetype)pickerWithTitle:(NSString *)title rows:(NSArray *)strings initialSelection:(NSInteger)index doneBlock:(ActionStringDoneBlock)doneBlock cancelBlock:(ActionStringCancelBlock)cancelBlockOrNil origin:(id)origin { XXActionSheetStringPicker *picker = [[self alloc

Background task with Completion block in IOS

纵饮孤独 提交于 2019-12-11 08:46:58
问题 I am doing some database operations in IOS. Basically I want to do this in a background thread. I tried using GCD. But the issue for me is I want to get some values from this process after it is finished. Say before inserting an item to database I check whether the item already exists. Please see code below __block Boolean isExisting = false; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, (unsigned long)NULL), ^(void) { NSString *path = [SqliteManager initDatabase];