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 935977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:14:29+00:00 2026-05-15T21:14:29+00:00

This is from a category that I’m using to modify UIView. The code works,

  • 0

This is from a category that I’m using to modify UIView. The code works, but in the first method (setFrameHeight) I’m using a block and in the second method (setFrameWidth) I’m not. Is there any way to use blocks more efficiently in this example?

typedef CGRect (^modifyFrameBlock)(CGRect);

- (void) modifyFrame:(modifyFrameBlock) block {
    self.frame = block(self.frame);
}

- (void) setFrameWidth:(CGFloat)newWidth {
    modifyFrameBlock b = ^CGRect (CGRect frame) { 
        frame.size.width = newWidth;
        return frame; 
    };      
    [self modifyFrame:b];
}

- (void) setFrameHeight:(CGFloat)newHeight {
    CGRect f = self.frame;
    f.size.height = newHeight;
    self.frame = f;
}

The answer may be that blocks are not appropriate for such short methods, or something. The syntax sure seems funky.

  • 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-05-15T21:14:29+00:00Added an answer on May 15, 2026 at 9:14 pm

    The only thing you gain is not declaring the local variable for the new rect, in exchange you need to define a block. That is not a good deal, especially as it distracts from what you are doing.

    Note that your block-usage could be shortened a bit:

    [self modifyFrame:^(CGRect frame) {
        frame.size.width = newWidth;
        return frame; 
    }];
    

    Or even:

    [self modifyFrame:^(CGRect* frame) {
        frame->size.width = newWidth;
    }];
    

    With modifyFrame: being:

    CGRect frame;
    block(&frame);
    self.frame = frame;
    

    But i’d still limit such approaches to more complex methods that only require minor parts of the code to be different.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have this query that works perfectly: SELECT users.*, GROUP_CONCAT(categories.category_name) AS categories FROM
This snippet from official website works as expected: $treeObject = Doctrine::getTable('Category')->getTree(); $rootColumnName = $treeObject->getAttribute('rootColumnName');
I am having this Linq To SQL query which is taking Customer Category from
I'm having this Mysql query, It works: SELECT nom ,prenom ,(SELECT GROUP_CONCAT(category_en) FROM (SELECT
I want to design a new category this category will be separated from the
Following on from this question: Display ALL categories that a product belongs to in
Is this kind of mysql query possible? SELECT power FROM .$table. WHERE category IN
Following on from this question , I'm using a simple ViewModel class to test
I have a table that looks like this: category category_id name category_seo_friendly_url left_id right_id
Using: Rails 3.1.1 I have a controller/model/view called Category that is built up on

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.