objective-c-blocks

Does assigning a weak pointer to a strong pointer copy the object?

自作多情 提交于 2019-12-12 03:45:20
问题 The common pattern to avoid capturing self within a Block is to create a weak self outside the Block and use this to create a "locally strong" version of self within the Block (inner self). __weak ClassX *weakSelf = self; [someOtherObject methodThatTakesCOmpletionBlock: ^{ ClassX innserSelf = weakSelf; //innserSelf creation? [someObject send:innerSelf.prop;}]; What happens when the innserSelf creation line is executed? Is innerSelf a copy of self at the time the method

app starts ignores user interaction events when i call animateWithDuration:delay:options:animations:completion:

元气小坏坏 提交于 2019-12-12 02:48:16
问题 I have a button that glows in my app (subclass of UIButton). To animate the glowing i use the following method - (void)glow { [UIView animateWithDuration:1.0f delay:0.0f options:UIViewAnimationOptionCurveEaseInOut animations:^(void){ if (glowingImageView_.alpha != 1.0f) { [glowingImageView_ setAlpha:1.0f]; } else { [glowingImageView_ setAlpha:0.3f]; } } completion:^(BOOL finnished){ if (on_) { [self glow]; } }]; } It works fine running on iOS 5, but in iOS 4.3 my app stops handling any user

Objective C to Swift - DoWithBlock

末鹿安然 提交于 2019-12-12 02:23:55
问题 I am trying to only create an array in Swift when an objective C class function is completed. I am using a DoWithBlock in the objective C function but I am am new to IOS and am trying to work out if it is actually running in the correct order. I got help to come up the solution on here but I am not sure if what I did to extend on that answer is correct and I believe it should be a new question. In the objective C class I am calling the function with the block like this: - (void

Trouble with adding item into an NSMutableArray inside a block

断了今生、忘了曾经 提交于 2019-12-12 02:04:02
问题 UPDATE: I just found a tricky part... if I do something like this, it works: [_friendsArrayInBlock insertObject:@"Bla" atIndex:itemIndex]; But it doesn't: [_friendsArrayInBlock insertObject:friend atIndex:itemIndex]; Why I cannot add a custom object, but I can add NSString? What's the problem ORIGINAL PART: Here you can see the relevant code part: @implementation ORGFriendsTableViewController { NSMutableArray *_friendsArray; } - (void)viewDidLoad { [super viewDidLoad]; _friendsArray =

UIImage is not transitioning using fade with animation block transition

不想你离开。 提交于 2019-12-12 01:49:34
问题 I am doing an image transition using an animation block like this [UIView animateWithDuration:1.0f delay:0.0f options:UIViewAnimationOptionTransitionCrossDissolve animations:^{ self.songTitleLabel.text = currentSong.songTitle; self.artistNameLabel.text = currentSong.songArtist; self.songImageView.image = currentSong.songArtwork; }completion:^(BOOL finished){ self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:currentSong.songLocation error:nil]; [self.player setVolume:1.0]; [self

How to asynchronously download images in ios?

余生长醉 提交于 2019-12-12 01:44:42
问题 I want to first create imageview onto the scroll view.there i set placeholder image or give Background color of imageview.so all image view are display. - (void)LoadDataInScrollView { dispatch_queue_t imageQueue = dispatch_queue_create("Image Queue",NULL); //totalImageGetDict into count total Number of object and generate imageview. for (int ivalue = 0; ivalue < [totalImageGetDict count]; ivalue++) { dispatch_async(imageQueue, ^{ //define x value CGFloat xOrigin =ivalue *ascrollView.frame

EXC_BAD_ACCESS for an object created inside a Block

為{幸葍}努か 提交于 2019-12-12 01:42:12
问题 I have always been nervous when it comes to blocks and GCD because my mind tells me that it looks very complex! I am getting a crash inside a block which ideally looks alright to me: #pragma mark - -(void)fetchOrdersListWithInfoDict:(NSDictionary*)infoDict completionBlock:(CompletionBlock)completionBlock errorBlock:(ErrorBlock)errorBlock { __weak VTVehicleServiceNetworkManager *weakSelf = self; TaskBlock fetchOrdersListTaskBlock = ^() { __block __strong HLOrdersDataProvider

Retain cycle on an Obj-C block using itself

风流意气都作罢 提交于 2019-12-12 01:04:24
问题 I have a block to use as a completionHandler for an NSURLConnection asynchronous request whose main job is to spawn a new asynchronous request using the same block for the new requests completion handler. I am doing this because it effectively solves another problem which is to line up a sequence of asynchronous calls and have them fired off in the background. This is working marvelously for us, but we have a warning I am concerned about. Namely, XCode thinks I have a retain cycle. Perhaps I

Wrapping blocks based API in convenience methods

你离开我真会死。 提交于 2019-12-11 23:13:56
问题 I'm using AFNetworking 2.0 to access a web api (although this would apply to NSURLSession as well), and currently I have a bunch of code that looks like this: [self.rottenTomatoesManager GET:@"movies.json" parameters:@{@"q" : searchString, @"apikey" : [self.rottenTomatoesManager apiKey]} success:^(NSURLSessionDataTask *task, id responseObject) { NSHTTPURLResponse *response = (NSHTTPURLResponse *)task.response; if(response.statusCode == 200){ NSDictionary *responseData = responseObject; self

Recursive Blocks and a Bad Memory Leak

纵然是瞬间 提交于 2019-12-11 20:36:54
问题 I am using recursive blocks to fetch tweets via the Twitter API and do encounter a bad memory leak: 50 recursive fetches lead to a memory footprint > 500 MB. This method is called from inside my view controller and controls the lists of which the timelines should be fetched: - (void)fetchTweetsForUsersInList:(List*)list withCompletionHandler: (simpleCompletionBlock)completionBlock { [self.managedDocument.managedObjectContext performBlock:^{ NSFetchRequest *request = [NSFetchRequest