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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T14:01:30+00:00 2026-06-02T14:01:30+00:00

I downloaded a code to test whether an nsobject is empty or not The

  • 0

I downloaded a code to test whether an nsobject is empty or not

The test is something like this:

-(BOOL) isNotEmpty
{


return !(self == nil
         || [self isKindOfClass:[NSNull class]]
         || ([self respondsToSelector:@selector(length)]
             && [(NSData *)self length] == 0)
         || ([self respondsToSelector:@selector(count)]
             && [(NSArray *)self count] == 0));

};

This part puzzles me:

(NSData *)self length

How can the author just typecast NSData from NSObject like that?

  • 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-02T14:01:34+00:00Added an answer on June 2, 2026 at 2:01 pm

    The Objective-C runtime doesn’t really care what the actual type of the object it, it’s going to send it the message anyway (though of course if the object doesn’t respond to it, things will go poorly). The compiler sees “oh, NSArray responds to count, they claim this is an NSArray, and they’re sending -count, so this must be ok!”.

    That said, this is pretty gross, and casting to (id) instead of (NSArray *) after checking respondsToSelector: is a much clearer way to say “we don’t know what this is, other than that it implements this method”.

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

Sidebar

Related Questions

I have a java file Test.java (below) which uses Guava's HashMultiMap (downloaded from http://code.google.com/p/guava-libraries/
I have downloaded the sample code from this site for FTP Client http://www.lysesoft.com/products/andftp/index.html But
I'm trying to force a download so this is my code: $file = 'test.m4r';
If you have downloaded any android source code, you would see a test folder
I have downloaded and installed linq-to-sqlite from http://sqlite.phxsoftware.com/ But the following test code: [
If this is not out of place here, would like to know about the
This simple code is not producing any sound on a couple of machines that
I need files to be downloaded to /tmp/cron_test/. My wget code is wget --random-wait
I have downloaded a code when I am building the program, a message window
I have downloaded sample code from Apple Center.I also have gone through following question:

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.