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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:24:23+00:00 2026-05-25T14:24:23+00:00

When coding Objective-C, is it allowed to do sth. like: { UIView *viewOne =

  • 0

When coding Objective-C, is it allowed to do sth. like:

{
  UIView *viewOne = [[UIView alloc] init];
  // do stuff with view
  [self addSubview:viewOne];
  [viewOne release];
} //View 1

{
  UIView *viewTwo = [[UIView alloc] init];
  // do stuff with view
  [self addSubview:viewTwo];
  [viewTwo release];
} //View 2

When i once did something like this, XCode does not complain and it runs on iOS 4.3.3.
My question is, if this makes my code incompatible to iOS 3.1.3 or something, because this looks to me like it may be blocks i am using.
I’d like to use this mainly for code readability and folding.

  • 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-25T14:24:24+00:00Added an answer on May 25, 2026 at 2:24 pm

    All you are doing there is creating separate scopes. Anything declared inside the first scope won’t be available to the second scope.

    This is perfectly legal C (and since Objective-C is simply a strict superset of C, its fine there too).

    I’ve seen it done in a lot of projects I’ve worked on. However, I’ve never used it myself, as it can be seen as a way of separating parts of a method that aren’t particularly related and can be an indication of poor code quality – not that I’m saying your code is poor!

    Also these are not C blocks, as in “closures”, a C block looks like

    ^{
        //code
    }
    

    in it’s most basic form.

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

Sidebar

Related Questions

Here's a coding problem for those that like this kind of thing. Let's see
I've been coding alot of web-stuff all my life, rails lately. And i can
I'm coding in Objective-C for the iPhone and I am trying create an array
Sometimes when coding in Objective C for the iPhone I wonder if I should
Although I'm coding in Objective C, this is more of a general programming question.
Has anyone used the Pragmatic Programmers screencast series Coding in Objective-C 2.0 ? They
hopefully this is an easy one. I'm coding in objective-c and i'm wondering if
Google Coding Standard for Objective C says we should not throw exceptions , what
After several months of coding in Objective-C, I completely understand when I need an
Currently I'm hard coding another object directly when needed and I'd like the ability

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.