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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:44:38+00:00 2026-06-16T03:44:38+00:00

New to objective-c. When I write code in strongly-typed OO languages, I like to

  • 0

New to objective-c. When I write code in strongly-typed OO languages, I like to make my design as explicit as possible in the code, I also like to make sure that I’m maintaining program correctness by checking parameter value ranges, etc (for example, at the beginning of a method make sure that an object reference is not null, use constants as much as possible..). These simple checks, have helped my colleagues and I to catch issues during dev time.

Now working in objective-c, I’m really tempted to check to make sure that a selector is supported before sending a message to a protocol implementation. Or manually check for type compatibility of objects in an NSArray.

Are these types of checks normal in objective-c programs? When do you deem these checks necessary?

Thanks in advance.

  • 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-16T03:44:39+00:00Added an answer on June 16, 2026 at 3:44 am

    What you’re trying to do is totally acceptable, although not necessarily the bread and butter of every programmer’s approach. (I don’t always do this, although perhaps I should.)

    The way you’d check would be like so:

    if([someObject respondsToSelector:@selector(someSelector)]){
      [someObject someSelector];
    }
    

    If you send a message to an object that it doesn’t respond to, you’ll get a runtime crash. If you check ahead of time, your logic might be totally off. (A common example is when you think you’re dealing with one object, when you are in fact, working with something entirely different. This introduces the tradeoff between crashes during development versus expected values/behavior at runtime.

    If you code carefully, you’ll go a lot farther than verbose checking.

    Edit:

    Thinking about your question a little more, the runtime also offers the conformsToProtocol: method, which allows you to check if a class or an instance conforms to a protocol. This would seem to be exactly what you want.

    A place where this is actually essential to not crashing, no matter how careful you are, is when you add support for new iOS features while maintaining backwards compatibility. (In such cases you weak link against new frameworks and use these very same checks to ensure compatibility.  

    As others have noted, you do get some form of compile-time checking when it comes to protocols. If a method isn’t denoted as @optional, the Xcode will warn you of an incomplete implementation.

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

Sidebar

Related Questions

I'm new in objective-c, and I'm now trying to write a simple user-sign-in program
I am trying to write a bit of Objective-C (which is new for me,
I'm sure there is a correct way to do this, I'm new to objective-c
I am just trying to write my very first code in Objective C. I
I am quite new to blocks and objective-c, and i am trying to write
New to objective-c. Wrote a code-snippet to better understand the init mechanism, and ended
I'm new to Objective-c. I wrote a few lines of code to access a
I'm new to Objective-C and XCode, but I was happy to see that XCode
I'm new to iPhone and Objective C programming but I'm able to make my
I'm new to Objective-C, I feel like I'm probably just making a dumb mistake,

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.