Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8521971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:58:34+00:00 2026-06-11T06:58:34+00:00

When programming for iOS, I frequently find myself faced with the following situation: –

  • 0

When programming for iOS, I frequently find myself faced with the following situation:

- (void)someMethod
{
    [self performSomeAnimation];

    //below is an action I want to perform, but I want to perform it AFTER the animation
    [self someAction];
}

- (void)performSomeAnimation
{
    [UIView animateWithDuration:.5 animations:^
    {
        //some animation here
    }];
}

Faced with this situation, I usually end up just copy/pasting my animation code so that I can use the completion block handler, like so:

- (void)someMethod
{
    [self performSomeAnimation];


    //copy pasted animation... bleh
    [UIView animateWithDuration:.5 animations:^
    {
        //same animation here... code duplication, bad.
    }
    completion^(BOOL finished)
    {
        [self someAction];
    }];
}

- (void)performSomeAnimation
{
    [UIView animateWithDuration:.5 animations:^
    {
        //some animation here
    }];
}

What is the proper way to solve this problem? Should I be passing a block of code to my -(void)performSomeAction method, like below, and executing that block on completion of the animation?

- (void)someMethod
{
    block_t animationCompletionBlock^{
        [self someAction];
    };

    [self performSomeAnimation:animationCompletionBlock];
}

- (void)performSomeAnimation:(block_t)animationCompletionBlock
{
    [UIView animateWithDuration:.5 animations:^
    {
        //some animation here
    }
    completion^(BOOL finished)
    {
        animationCompletionBlock();
    }];
}

Is that the proper way to solve this problem? I guess I have been avoiding it because I’m not THAT familiar with block usage (not even sure if I declared that block properly) and it seems like a complicated solution to a simple problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T06:58:36+00:00Added an answer on June 11, 2026 at 6:58 am

    You could also do this:

    - (void)performSomeAnimationWithCompletion:(void(^)(void))animationCompletionBlock
    {
        [UIView animateWithDuration:.5 animations:^
        {
            //some animation here
        }
        completion^(BOOL finished)
        {
            animationCompletionBlock();
        }];
    }
    

    And instead of explicitly defining a block and passing it as parameter, you can call it directly like this (this is how block animations work for UIView, for example):

    - (void)someMethod
    {
        [self performSomeAnimationWithCompletion:^{
    
            [self someAction];
    
        }];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm following the iOS Programming guide on Providing Launch Images for Different Orientations and
I am a novice to IOS programming hence struggling a bit with the below
I am very new to IOS programming. I have a task to find if
I am reading about iOS programming and I bought the Programming iOS 4 book.
I'm a new iOS programming and I'm developing a simple iPhone game that needs
I'm new to programming for iOS and on MacOs, so excuse me for asking
I'm new to IOS programming, I don't know how to judge the swinging direction
I am newbie for iOS programming. I'm trying to create an array of arrays
I'm new to iOS programming and I need to implement a location aware application.
I'm new to iOS programming. I want to know how a database is created

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.