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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T19:43:55+00:00 2026-06-18T19:43:55+00:00

So, I have this: @interface Foo @property(nonatomic, readonly, retain) NSArray* bars; @end @implementation Foo

  • 0

So, I have this:

@interface Foo
@property(nonatomic, readonly, retain) NSArray* bars;
@end

@implementation Foo
@synthesize bars = _bars;
// ... more stuff here ...
@end

So Foo fills up bars with instances of Bar, and the instance of Foo lives in a container object. And then I say:

[container valueForKeyPath:@"foo.bars.@count"]

Which I expect to give me a nice boxed number. However I instead get:

Exception: [<Bar 0xc175b70> valueForUndefinedKey:]: this class is not key value coding-compliant for the key bars.

So, why? I wouldn’t expect to have to implement anything special on Bar to make an NSArray of Bars countable, but that’s what this error message is implying. The documentation only has trivial examples, but I would expect this to just work in the same manner.

  • 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-18T19:43:56+00:00Added an answer on June 18, 2026 at 7:43 pm

    How does my code differ from yours? Because this works…

    //  Foo.h
    #import <Foundation/Foundation.h>
    
    @interface Foo : NSObject
    @property(nonatomic, readonly, retain) NSArray* bars;
    @end
    
    
    //  Foo.m
    #import "Foo.h"
    
    @interface Foo ()
    // extended property decl here, to be readable, but this didn't seem to matter in my test
    @property(nonatomic, retain) NSArray* bars;
    @end
    
    
    @implementation Foo
    
    - (id)init {
    
        self = [super init];
        if (self) {
            _bars = [NSArray arrayWithObjects:@"bar one", @"bar none", nil];
        }
        return self;
    }
    
    @end
    

    Then, in my container class:

    // .h
    @property (strong, nonatomic) Foo *foo;
    
    // .m
    _foo = [[Foo alloc] init];
    NSNumber *c = [self valueForKeyPath:@"foo.bars.@count"];
    NSLog(@"count is %@", c);
    

    Logs => “count is 2”

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

Sidebar

Related Questions

@interface foo: NSObject @property (nonatomic, retain) NSMutableArray *aMutableArray; @end @implementation @synthesize aMutableArray -(void)somefunction {
In my interface (.h) file, I have @property(readonly) NSString *foo; and in my implementation
If I have a class @interface Foo { NSString *temp; } @property(nonatomic, copy) NSString
Assume that I have this piece of code: @interface Foo : NSObject { Bar
I have this type of class hierarchy: public interface IA{} public interface IB{void Foo();}
I have created a class named Foo : @interface Foo:NSObject{ int myInt; } @property
Let's assume I have an annotated bean property setter like this: public class Foo
I have an NSArray which holds Foo objects defined like so: @interface Foo :
I have an interface contract that looks like this: ICollection<FooBar> FindByPredicate(Expression<Func<FooBar,bool>> predicate); ICollection<Foo> FindByPredicate(Expression<Func<Foo,bool>>
Suppose I have this code... foo.h @interface Foo : NSObject { NSString *aString; //

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.