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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:16:14+00:00 2026-05-13T17:16:14+00:00

I have some code that gets the URL from an array and stores it

  • 0

I have some code that gets the URL from an array and stores it as a string then uses that string to load up the URL.

NSString *first = [urls objectAtIndex:[sender clickedRow]];
NSLog(@"%@", first);
[[webview mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:first]]];

However, when I run this I get this error:

-[NSURL length]: unrecognized selector sent to instance 0x164dc0

The link in this case is http://www.digg.com

I know that the bug is in the line

NSString *first = [urls objectAtIndex:[sender clickedRow]];

because I tried setting the string’s value directly to the URL instead of the array and it worked.

  • 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-13T17:16:14+00:00Added an answer on May 13, 2026 at 5:16 pm

    However, when I run this I get this error:

    -[NSURL length]: unrecognized selector sent to instance 0x164dc0
    

    First off, that’s an exception, not an error.

    When you get a message like this, read what it says:

    -[NSURL
    

    The object you sent this message to was an NSURL object.

    length]:
    

    The selector of the message was length.

    Now, why would you send a length message to an NSURL object? You wouldn’t, and you didn’t do so yourself. Something else did.

    But you would send a length message to a string object. So, you have an NSURL object, and you passed it somewhere that expected a string.

    There’s only one passage in the code you showed:

    [NSURL URLWithString:first]
    

    The exception tells you that first is already an NSURL; it is not a string. You do not need to create an NSURL from it, since it already is one, and trying to treat it as a string in any way will cause an exception.

    You may be about to object to my claim on the grounds of this previous line:

    NSString *first = [urls objectAtIndex:[sender clickedRow]];
    

    Your objection would be that the declaration clearly says that first is a pointer to an NSString, so I must be wrong.

    But that is not so. You declared first as a pointer to an NSString. That is to say, you told the compiler that the variable first would hold a pointer to an NSString.

    But then you put a pointer to an NSURL into the variable.

    In many cases, the compiler would warn you that you have lied to it, but it didn’t in this case because the object came through objectAtIndex:, which returns id; thus, the compiler doesn’t know what type of object you’re putting into the variable. The compiler, assuming that you told the truth and really are putting an NSString here, does not warn for this initialization.

    But you’re not. The object is an NSURL, as you found out at run time.

    The fix is two-fold:

    1. Restore truth to the declaration, by declaring the variable as NSURL *, not NSString *.
    2. Don’t attempt to create an NSURL here, because you already have one.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code that gives a user id to a utility that then
I have some code that uses the shared gateway pattern to implement an inversion
I have some code that uses the Oracle function add_months to increment a Date
I have some code that raises PropertyChanged events and I would like to be
I have some code that looks like: template<unsigned int A, unsigned int B> int
I have some code that generates image of a pie chart. It's a general
I have some code that effectively does this : File file = new File(C:\\Program
I have some code that I am putting in the code-behind of a master
I have some code that prints out databse values into a repeater control on
I have some code that produces a set of primary key values that I

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.