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

  • Home
  • SEARCH
  • 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 559209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:12:51+00:00 2026-05-13T12:12:51+00:00

In the current book I am reading, the author implements an IBAction for a

  • 0

In the current book I am reading, the author implements an IBAction for a slider in the following way (see below V001). To my eye, it seemed a little over complicated so I re-factored the code (V002). Am I right in thinking that sender is a pointer to the object that fired the event? Also, is there any downside to casting sender in the header, rather than leaving it as sender and casting it in the method body?

v001

-(IBAction)sliderChange:(id)sender {
    UISlider *slider = (UISlider *)sender;
    int progressAsInt = (int)([slider value] + 0.5f);
    NSString *newText = [[NSString alloc] initWithFormat:@"%d", progressAsInt];
    [sliderLabel setText:newText];
    [newText release];      
}

v002

-(IBAction)sliderChange:(UISlider*)sender {
    NSString *newText = [[NSString alloc] initWithFormat:@"%d",(int)[sender value]];
    [sliderLabel setText:newText];
    [newText release];
}

gary

  • 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-13T12:12:51+00:00Added an answer on May 13, 2026 at 12:12 pm

    id a special type that can hold any object. The nuance is that you don’t have well-defined type safety. You can call any selector on any object, and if it exists it will be invoked.

    In V001, doing [slider value] instead of [sender value] makes more logical sense which I think is probably why you took to refactoring in the first place because it didn’t appear to be called.

    In V002 [sender value] retrieves the float property of the same UISlider but hides the fact that you may not be getting a a slider object, and it could be on any object.

    This is a matter of style and discrimination. I am pretty diligent in my own code to determine which concrete object I am trying to access a selector, and will even go so far as calling isKindOfClass, and verifying I am calling the selector on the correct UISlider object. To answer your downside question: the type of the object isn’t obviated as it should be when using id.

    Why? I want multiple sliders on the same view handling the slider event, I don’t want one slider to impact the data of both, even if I may want to handle them in the same way.

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

Sidebar

Related Questions

I'm reading a book a little above my level. The book's author is showing
I'm reading a book about C++. The author shows this enum: [Flags] enum class
I need to create a form class,I'm following the symfony book in http://symfony.com/doc/current/book/forms.html I
so im reading the internals documentation for symfony2 http://symfony.com/doc/current/book/internals.html and i dont understand this
I have the following source snippet from a book that I'm reading now. So
I read this: http://symfony.com/doc/current/book/service_container.html It said: $mailer = $this->get('my_mailer'); As an added bonus, the
I'm trying to follow this documentation on Symfony : http://symfony.com/doc/current/book/forms.html ok so here is
CF: Carry Flag ZF: Zero Flag i'm current read a book on intel x86
Current version of Twiiter has a tab bar as shown below. When I select
I'm just starting out in Ruby (Rails actually) and the book I'm reading covers

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.