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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:11:34+00:00 2026-06-13T14:11:34+00:00

In Objective-C, there are at least two ways to get (or create? Hence the

  • 0

In Objective-C, there are at least two ways to get (or create? Hence the question) a selector: @selector(foo:bar:), or NSSelectorFromString(@"foo:bar:"). But what is the lifetime of a selector?

Since selectors know (at least) their name, they are unlikely to be copiable values of a fixed size that can be shuffled around the program. This means that someone needs to allocate and possibly deallocate them. Most objects from the Cocoa framework have retain-release semantics, which make their ownership explicit and relatively easy to track. However, I see no clear concept of ownership for selectors.

I expect that selectors obtained with the first syntax live as globals for the whole life of the program (like literal strings), but what about the other? If I create/get a selector with NSSelectorFromString(@"foo:bar:"), will it be valid for the whole life of my program too?

  • 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-13T14:11:35+00:00Added an answer on June 13, 2026 at 2:11 pm

    It’s “get”, not “create”. Both of those simply retrieve the selector, which is created and owned by the runtime system. The SEL‘s lifetime is therefore effectively immortal.

    If you wanted to create a selector yourself, you would need to use the runtime function sel_registerName(). This function is used by NSSelectorFromString() if you pass it a name which is as yet unknown to the runtime.

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

Sidebar

Related Questions

The objective is to get an array of MemberExpressions from two LambdaExpressions. The first
I am using Objective-C and Java for this, but I think the question is
In Objective-C on Apple there is something called Key-Value Coding that allows you to
Are there standard optimization tricks for Objective-C to make for faster execution along the
Is there a way in objective-c/Cocoa to alloc an object when the class name
Is there any way to use global int constants in Objective C that work
Is there any simple way how to initialize String in Objective-C with int such
Is there a canonical way to randomize an array in Objective-C?
Is there anyway we can take input from command line in Objective-C, the way
Is there any pdf which tells about coding guidelines in objective C. For Example...

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.