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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:22:00+00:00 2026-05-12T09:22:00+00:00

I’d like to change the value of a parameter at runtime and curious how

  • 0

I’d like to change the value of a parameter at runtime and curious how this works in Obj-C.

I have a loop where value of ‘n’ is 0 increasing by 1 with each loop. How does one increment the passed parameter by 1 as n moves.

UIViewSubclass *uiViewSubclass = [[UIViewSubclass alloc] initWithValue:([value integerValue]) 
                                                   andPlacement:kPlacement0;

next time through loop I’d like 2nd argument to read as: andPlacement:kPlacement1;
and then: andPlacement:kPlacement2; and on…

do I make kPlacement a string and stringByAppendingString:[[NSNumber numberWithInt:n] stringValue]; ?

What’s the Obj-C/Cocoa approach?

  • 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-12T09:22:00+00:00Added an answer on May 12, 2026 at 9:22 am

    You can’t modify your source code or make up variable references at runtime. Objective-C isn’t that dynamic.

    If the values of kPlacement0 through kPlacementMax are sequential, you may be able to use a for loop to step through them directly:

    for (MyPlacement placement = kPlacement0; placement += kPlacementIncrement; placement <= kPlacementMax) {
        UIViewSubclass *instanceOfUIViewSubclass = [[UIViewSubclass alloc] initWithValue:([value integerValue])
                                                                            andPlacement:placement];
        //Do something with instanceOfUIViewSubclass.
        [instanceOfUIViewSubclass release];
    }
    

    (You will need to define kPlacementIncrement and kPlacementMax in addition to the kPlacement0, etc. constants. I’m using MyPlacement as the name of your enumeration type that the kPlacement0 etc. constants correspond to.)

    If they are not sequential, put them in a C array and iterate on that array:

    enum { numPlacements = <#Insert the number of placement constants here#> };
    MyPlacement placements[numPlacements] = {
        kPlacement0,
        kPlacement1,
        kPlacement2,
        ⋮
    }
    
    for (unsigned i = 0U; i < numPlacements; ++i) {
        UIViewSubclass *instanceOfUIViewSubclass = [[UIViewSubclass alloc] initWithValue:([value integerValue])
                                                                            andPlacement:placements[i]];
        //Do something with instanceOfUIViewSubclass.
        [instanceOfUIViewSubclass release];
    }
    

    You probably can come up with more-descriptive names than kPlacement0 etc. When you want to refer to them by number, do that; when you want to refer to them by name, give them good names.

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

Sidebar

Related Questions

No related questions found

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.