Error: no visible @interface for 'Employee' declares the sel


#1

Hi,

i’m currently learning objective-c by the “big nerd ranch”-book. I’ve repeated the code from chapter 18, but I’m getting errors. using 64bit macos 10.6 witch actual version of xcode.

I’ve posted this question already in stackoverflow.com: stackoverflow.com/questions/1300 … nheritance. I hope this forum is a better place for asking. Maybe I can help with my question further readers of this book. It’s exceptional that I post my problem in 2 platforms, since this is my first posting here.

compiler says:

[quote]Build target BMITime

CompileC /Users/pm/Library/Developer/Xcode/DerivedData/BMITime-cjqpmtvlmdoeiecyxbofznzjgpij/Build/Intermediates/BMITime.build/Debug/BMITime.build/Objects-normal/x86_64/main.o BMITime/main.m normal x86_64 objective-c com.apple.compilers.llvm.clang.1_0.compiler cd /Users/pm/Dropbox/objective-c/BMITime setenv LANG en_US.US-ASCII /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x objective-c -arch x86_64 -fmessage-length=0 -std=gnu99 -fobjc-arc -Wno-trigraphs -fpascal-strings -O0 -Wno-missing-field-initializers -Wno-missing-prototypes -Wreturn-type -Wno-implicit-atomic-properties -Wformat -Wno-missing-braces -Wparentheses -Wswitch -Wno-unused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wuninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-sign-compare -Wshorten-64-to-32 -Wpointer-sign -Wno-newline-eof -Wno-selector -Wno-strict-selector-match -Wno-undeclared-selector -Wno-deprecated-implementations -DDEBUG=1 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk -fasm-blocks -Wprotocol -Wdeprecated-declarations -mmacosx-version-min=10.7 -g -Wno-conversion -Wno-sign-conversion “-DIBOutlet=attribute((iboutlet))” “-DIBOutletCollection(ClassName)=attribute((iboutletcollection(ClassName)))” “-DIBAction=void)attribute((ibaction)” -iquote /Users/pm/Library/Developer/Xcode/DerivedData/BMITime-cjqpmtvlmdoeiecyxbofznzjgpij/Build/Intermediates/BMITime.build/Debug/BMITime.build/BMITime-generated-files.hmap -I/Users/pm/Library/Developer/Xcode/DerivedData/BMITime-cjqpmtvlmdoeiecyxbofznzjgpij/Build/Intermediates/BMITime.build/Debug/BMITime.build/BMITime-own-target-headers.hmap -I/Users/pm/Library/Developer/Xcode/DerivedData/BMITime-cjqpmtvlmdoeiecyxbofznzjgpij/Build/Intermediates/BMITime.build/Debug/BMITime.build/BMITime-all-target-headers.hmap -iquote /Users/pm/Library/Developer/Xcode/DerivedData/BMITime-cjqpmtvlmdoeiecyxbofznzjgpij/Build/Intermediates/BMITime.build/Debug/BMITime.build/BMITime-project-headers.hmap -I/Users/pm/Library/Developer/Xcode/DerivedData/BMITime-cjqpmtvlmdoeiecyxbofznzjgpij/Build/Products/Debug/include -I/Users/pm/Library/Developer/Xcode/DerivedData/BMITime-cjqpmtvlmdoeiecyxbofznzjgpij/Build/Intermediates/BMITime.build/Debug/BMITime.build/DerivedSources/x86_64 -I/Users/pm/Library/Developer/Xcode/DerivedData/BMITime-cjqpmtvlmdoeiecyxbofznzjgpij/Build/Intermediates/BMITime.build/Debug/BMITime.build/DerivedSources -F/Users/pm/Library/Developer/Xcode/DerivedData/BMITime-cjqpmtvlmdoeiecyxbofznzjgpij/Build/Products/Debug -include /Users/pm/Library/Developer/Xcode/DerivedData/BMITime-cjqpmtvlmdoeiecyxbofznzjgpij/Build/Intermediates/PrecompiledHeaders/BMITime-Prefix-bbjacqhmgaerfrhblktcvkpzzntb/BMITime-Prefix.pch -MMD -MT dependencies -MF /Users/pm/Library/Developer/Xcode/DerivedData/BMITime-cjqpmtvlmdoeiecyxbofznzjgpij/Build/Intermediates/BMITime.build/Debug/BMITime.build/Objects-normal/x86_64/main.d --serialize-diagnostics /Users/pm/Library/Developer/Xcode/DerivedData/BMITime-cjqpmtvlmdoeiecyxbofznzjgpij/Build/Intermediates/BMITime.build/Debug/BMITime.build/Objects-normal/x86_64/main.dia -c /Users/pm/Dropbox/objective-c/BMITime/BMITime/main.m -o /Users/pm/Library/Developer/Xcode/DerivedData/BMITime-cjqpmtvlmdoeiecyxbofznzjgpij/Build/Intermediates/BMITime.build/Debug/BMITime.build/Objects-normal/x86_64/main.o

/Users/pm/Dropbox/objective-c/BMITime/BMITime/main.m:21:10: error: no visible @interface for ‘Employee’ declares the selector ‘setWeightInKilos:’ [person setWeightInKilos:96]; ^ /Users/pm/Dropbox/objective-c/BMITime/BMITime/main.m:22:10: error: no visible @interface for ‘Employee’ declares the selector ‘setHeightInMeters:’ [person setHeightInMeters:1.8]; ^ /Users/pm/Dropbox/objective-c/BMITime/BMITime/main.m:26:22: error: no visible @interface for ‘Employee’ declares the selector ‘bodyMassIndex’ float bmi = [person bodyMassIndex]; ^ 3 errors generated.[/quote]

my code looks like this:

main.m

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

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

@autoreleasepool {

    // Erstellt eine Instanz von Person
    Employee *person = [[Employee alloc] init];

    // Gibt den Instanzvariablen interessante Werte
    [person setWeightInKilos:96];
    [person setHeightInMeters:1.8];
    [person setEmployeeID:15];

    // Ruft die Methode bodyMassIndex auf
    float bmi = [person bodyMassIndex];
    NSLog(@"Employee %d has a BMI of %f", [person employeeID], bmi);


}
return 0;

}[/code]

Person.h

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

// Die Klasse Person erbt alle Instanzvariablen
// und Methoden, die von der Klasse NSObject definiert wurden
@interface Person : NSObject
{
// Sie hat zwei Instanzvariablen
float heightInMeters;
int weightInKilos;
}
@property float heightInMeters;
@property int weightInKilos;

// Diese Methode berechnet den Body-Mass-Index

  • (float)bodyMassIndex;
    @end[/code]

Employee.h

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

@interface Employee : NSObject
{
int employeeID;
}
@property int employeeID;
@end[/code]

Employee.m

[code]#import “Employee.h”

@implementation Employee

@synthesize employeeID;

@end[/code]

Person.m

[code]#import “Person.h”

@implementation Person

@synthesize heightInMeters, weightInKilos;

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

@end[/code]

I’m looking forward to your answer. :slight_smile:


#2

It took me a while to spot this simple error: You meant to type in Peson but instead typed in NSObject.

Turn off your AutoPilot :slight_smile:


#3

I ran into a similar problem… except I didn’t see an error in my code (comparing with the text in the book and here). The compiler complains that the setter methods for Person are not seen by Employee, with “No visible interface declares the selector…”

I ran it down to using “setweightInKilos” and “setheightInMeters” when declaring explicitly rather than “setWeightInKilos” and “setHeightInMeters” since upon seeing no errors in Person.h and Person.m after running and then modifying the class to use @property and @synthesize, I did not compile and run before moving on to adding the Employee class.

This might also be a good place for other newbies to look if they run into the error, since the capitalization is very specific in the synthesized methods and it is very easy to miss the first cap when declaring explicitly.

The clue should have been that the text color for the accessors was still black.