(NSString *)description

I am running Xcode 9.0.
When I use this line of code in Chapter 21

  • (NSString *)description
    I get an error message telling me "Use of undeclared identifier ‘description’"
    I cannot figure out what this error message is telling me or how to fix it…
    Thanks for the help!

Please provide more information by posting enough code to make it easier to diagnose the problem.

If you paste your code between a pair of 3 back-tick characters like this:

```
Paste Your Code Here
```

It will be displayed nicely. For example:

//
//  Foo.h
//  ObjectiveCMatters
//
//  Created by Pretty Function on 7/10/17.
//  Copyright © 2017 examples. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface Foo : NSObject  {
}

@property (readonly) NSString * description;

@end
//
//  Foo.m
//  ObjectiveCMatters
//
//  Created by Pretty Function on 7/10/17.
//  Copyright © 2017 examples. All rights reserved.
//

#import "Foo.h"

@implementation Foo

- (NSString *)description {
    NSLog (@"%s", __func__);
    return @"Foo...";
}

@end
//
//  main.m
//  ObjectiveCMatters
//
//  Created by Pretty Function on 7/10/17.
//  Copyright © 2017 examples. All rights reserved.
//

#import "Foo.h"

int main (int argc, const char * argv[]) {
    @autoreleasepool {
        Foo * foo = [Foo new];
        NSLog (@"%@ %@", foo, foo.description);
    }
    return 0;
}

Thanks. Here is the code…
\\

#import “BNREmployee.h”
#import “BNRAsset.h”

@implementation BNREmployee

//Accessor for assets properties
-(void)setAssets:(NSArray *)a
{
_assets = [a mutableCopy];
}

  • (NSArray *)assets{
    return [_assets copy];
    }

  • (void)addAsset:(BNRAsset *)a
    {
    //Is asset nil?
    if (!_assets) {

      //Create the array
      _assets = [[NSMutableArray alloc]init];
    

    }
    [_assets addObject:a];
    }

  • (unsigned int)valueOfAssets
    {
    //Sum up the resale value of the assets
    unsigned int sum = 0;
    for (BNRAsset *a in _assets){
    sum += [a resaleValue];
    }
    return sum;

    }

  • (double)yearsOfEmployment
    {
    //Do I have a non-nil hire date?
    if (self.hireDate){
    //NSTimeInterval; is the same as double
    NSDate *now = [NSDate date];
    NSTimeInterval secs = [now timeIntervalSinceDate:self.hireDate];
    return secs / 31557600.0; //Seconds per year
    } else{
    return 0;
    }
    }

  • (float)bodyMassIndex
    {
    float normalBMI = [super bodyMassIndex];
    return normalBMI * 0.9;

    • (NSString *)description
      {
      return [NSString stringwithformat:@"<Employee %u: $%u in assets>", self.employeeID, self.valueOfAssets];
      }

    • (void)dealloc
      {
      NSLog(@“deallocating %@”, self);
      }

}

@end

\\

You are missing a closing } after the line

return normalBMI * 0.9;

This is causing the compiler to include the new function (NSString *)description… as part of the bodyMasIndex function declaration and it doesn’t know what to do with it.

As BrianL3D1 diagnosed, you have a syntax error.

As an aside, the code posted is still in a state of jumble :slight_smile: because instead of a pair of three back-tick characters (```), a pair of two back-slash characters (\\) were used.

When you ask for help next time, please place your code between a pair of three back-tick characters like this:

```
Place code here…
```

If you are using an Apple keyboard, you will find the back-tick character (`) on the same key for the tilde character (~).

Finally, coding requires paying undivided attention to details, no matter how tiny they are.