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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:17:50+00:00 2026-05-23T17:17:50+00:00

In objective-c, is for (Foo *foo in fooList) … more like which of the

  • 0

In objective-c, is

for (Foo *foo in fooList) ...

more like which of the following

@interface Bar : Foo ...

for (Foo *f in fooList) {
    // A:
    if ([f isMemberOfClass:[Foo class]]) ... // dont include Bar's

    // B:
    if ([f isKindOfClass:[Foo class]]) ... // both Foos and Bars
}
  • 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-23T17:17:50+00:00Added an answer on May 23, 2026 at 5:17 pm

    It’s not like either.

    The type of foo in the for() part is only a hint to the compiler so it can give out the relevant error messages. At run time, all the objects are just objects and as long as they all implement the methods used in the block, there will be no errors. For example:

    NSString* aString = @"20";
    [anArray addObject: aString];
    for (NSNumber* foo in anArray)
    {
        NSLog(@"%d", [foo intValue]);
    }
    

    will iterate over all the objects in the array and send intValue to each one no matter what type they are including the NSString at the end. If every object implements intValue it will work just fine (as NSString does). If there is an object in the array that does not implement intValue, an exception will most likely be thrown.

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

Sidebar

Related Questions

Say I have the following Objective-C class: @interface Foo { int someNumber; NSString *someString;
@interface Foo : NSObject { } - (Bar)bar; At runtime, given [Foo class], how
In objective-c I can do the following: NSTask* foo = [NSTask alloc]init]; [foo setLaunchPath:@/usr/bin/open];
So I have a custom class Foo that has a number of members: @interface
I have the following files. foo.h (C++ header file) foo.mm (C++ file) test_viewcontroller.h (objective
The following is an example of hidden method in Objective-C: MyClass.m #import "MyClass.h" @interface
is there in objective-c something similar to ruby's: foobar = foo || bar while
Can I not do this in objective c? @interface Foo : NSObject { int
I would like to define the following function in Objective-C. I have provided pseudo-code
I have a NSArray of Foo objects. @interface Foo : NSObject { } -

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.