Getting an error in the example


So for the BMI example, I’ve gone over it ten times but can’t figure out what I’m doing wrong. Seems like I’ve typed it exactly like in the book.

I get 5 errors when I try and build.
"No visible @interface for Employee declares the selector ‘setWeightInKilos’
"No visible @interface for Employee declares the selector ‘setHeightinMeters’
"No visible @interface for Employee declares the selector ‘setEmployeeID’
"No visible @interface for Employee declares the selector ‘bodyMassIndex’
"No visible @interface for Employee declares the selector ‘employeeID’

Here is the code from the files:


[code]#import <Foundation/Foundation.h>

// The class Person inherits all the instance variables and methods defined by the class NSObject

@interface Person : NSObject
//It has two instance variables
float heightInMeters;
int weightInKilos;

// you will be able to set those instance variables using these methods

@property float heightInMeters;
@property int weightInKilos;

//This method calculates the Body Mass Index

  • (float)bodyMassIndex;



[code]#import “Person.h”

@implementation Person

@synthesize heightInMeters, weightInKilos;

  • (float)bodyMassIndex
    float h = [self heightInMeters];
    return [self weightInKilos] / (h * h);



[code]#import <Foundation/Foundation.h>
#import “Person.h”

@interface Employee : Person

int employeeID;


@property int employeeID;



[code]#import “Employee.h”

@implementation Employee

@synthesize employeeID;



[code]#import <Foundation/Foundation.h>
#import “Employee.h”

int main(int argc, const char * argv[])

@autoreleasepool {
    //Create an instance of Employee
    Employee *person = [[Employee alloc] init];
    //Give the instance variables interesting values
    [person setWeightInKilos:96];
    [person setHeightInMeters:1.8];
    [person setEmployeeID:15];
    //Call the bodyMassIndex method
    float bmi = [person bodyMassIndex];
    NSLog(@"Employee %d has a BMI of %.2f", [person employeeID], bmi);
return 0;



This is very odd. Which file are the errors attached to? main.m?

Look at the directory in Finder. Are all the files appearing there?


Hi Aaron,

Yes. The files are attached to main.m and they’re all in the directory in the Finder. Everything seems fine… Just have no clue what the problem is.

In the issue navigator all of the errors have an “ARC issue” as the heading.


[quote=“AaronHillegass”]This is very odd. Which file are the errors attached to? main.m?

Look at the directory in Finder. Are all the files appearing there?[/quote]

So I just deleted the first program and made a new one… Copied and pasted everything in it and it started working properly. :confused:

No idea why it was giving me the errors… Wish I could figure it out.


If you are still getting those errors, you could try creating a new project with the same files for the Employee and Person classes.

I have used your code above, and I did not get those errors. (However, sometimes I have seen Xcode throwing weird errors at me in one minute and then seen them vanish without a trace in the next.)


Indeed, very strange. As developers, few things are as disheartening as feeling like starting over is the only way to get past a roadblock. I’d like to help understand why your existing code isn’t working. Might you be able to post a link to .zip containing your project directory?


Hi Everyone,

My name is Deepak and this is my first post

I have been getting the same errors and I think I figured out what was the problem (although I am not too sure why was that the problem)

In the main function, the statement where we try to assign value to weightInKilos and heightInMeters, which reads as follows

[person setweightInKilos : 96];
[person setheightInKilos : 1.8];

it seems like the compiler is not liking the fact that the ‘w’ in weightInKilos is in lower case and not uppercase. Similarly the ‘h’ in heightInKilos is in lower and that seems like the problem. Once I changed both ‘w’ and ‘h’ to ‘W’ and ‘H’ it started to work fine.

Does the setter method always have to follow this sort of a format?

Would be great if some one ca clarify…



You know what? You have discovered Objective-C’s fundamental naming rules for the accessors.

@interface Foo: NSObject
BarType bar;
FooBarType fooBar;


  • (BarType) bar;

  • (void)setBar:(BarType)bar;

  • (FooBarType) fooBar;

  • (void)setFooBar:(FooBarType)fooBar;



Hi Mikey,

Thanks for wanting to check it out.

How do I upload a file to the forums?

Would love to know what was wrong with it. It would totally suck being in the middle of developing an app and have this happen. :slight_smile:


My apologies for not seeing this sooner. I thought I was subscribed to topic replies.

Unfortunately, the forums currently have attachments disabled. I reccomend CloudApp or similar as a free public-file-upload service. I pay for a pro account because it makes my life so much easier.


I was having exactly the same type of error while doing the challenge, and I believe I have found the answer.

Again, my problem happend while doing the challenge, so the files/directory names will be different.

My errors were:

No visible @interface for ‘ForeignStockHolding’ declares the selector 'setPurchaseSharePrice:'
No visible @interface for ‘ForeignStockHolding’ declares the selector 'setCurrentSharePrice:'
No visible @interface for ‘ForeignStockHolding’ declares the selector ‘setNumberOfShares:’

But I confirmed that ForeignStockHolding was extending StockHolding, and everything looked fine. I did a bunch of searching looking for an inheritance bug in Xcode 4.3.3 as I just upgraded–no luck. I was so frustrated that I wanted to punch inanimate objects. :angry: Instead I decided to read through the forum posts on this chapter/challenge. After reading Aaron’s post I decided to take a look at the files on disk using the terminal. Everything looked fine at the top level of the project, the ‘Stocks’ directory im my case. Here is what my listing looked like:

-rw-r–r--@ 1 marc staff 316 Jun 30 10:52 ForeignStockHolding.h
-rw-r–r--@ 1 marc staff 247 Jun 30 10:52 ForeignStockHolding.m
-rw-r–r--@ 1 marc staff 529 Jun 29 23:26 StockHolding.h
-rw-r–r--@ 1 marc staff 445 Jun 29 23:12 StockHolding.m
drwxr-xr-x 7 marc staff 238 Jun 30 12:32 Stocks
drwxr-xr-x@ 5 marc staff 170 Jun 30 10:37 Stocks.xcodeproj

But when I listed the contents of the ‘Stocks’ directory under the ‘Stocks’ project directory (‘Stocks/Stocks’) I saw the problem. There was an additional ForeignStockHolding.h and ForeignStockHolding.m in that directory.

-rw-r–r--@ 1 marc staff 226 Jun 30 00:42 ForeignStockHolding.h
-rw-r–r--@ 1 marc staff 218 Jun 30 00:42 ForeignStockHolding.m
-rw-r–r--@ 1 marc staff 153 Jun 29 23:05 Stocks-Prefix.pch
-rw-r–r--@ 1 marc staff 3118 Jun 29 23:05 Stocks.1
-rw-r–r--@ 1 marc staff 1417 Jun 30 12:32 main.m

That version of ForeignStockHolding.h was inheriting from NSObject instead of StockHolding, and main.m was loading that version of the file. I know exactly how I got in this mess too. When I originally added the new ‘ForeignStockHolding’ Objective-C class, as the last page of the dialogs, there is a ‘Group’ dropdown that defaults to the currently selected directory in Xcode. I had the ‘Stocks/Stocks’ directory selected when I FIRST created the file. When it showed up in the wrong place in Xcode, I deleted it (via Xcode) and recreated it again (via Xcode), this time ensuring that I picked the correct Group (‘Stocks’). The problem is, Xcode never actually deleted the files from disk. They oddly do not show up in Xcode (even after closing the project, and restarting Xcode), but they are very much there on disk. This seems to be a bug with Xcode. My guess is that you also have multiple versions of the same file on disk–try looking in the ‘BMITime/BMITime’ directory. If not there use find, or Spotlight to find it for you.

Hope this helps clear things up–it certainly fixed things for me. :smiley: