1

OK, I'm confused. I have a class Employee, that I declare several properties for, which of course, synthesize and work fine. But in the implementation class, I extend the class like so:

@interface Employee ()
    @property (nonatomic) unsigned int employeeId;
@end

which I would think would allow me to do the following in main.m:

Employee emp = [[Employee alloc] init];
//use some other property accessor methods...
[emp setEmployeeId:123456];

//do some other stuff...

But the compiler chokes on the use of setEmployeeId with the following error "No visible interface for 'Employee' declares the selector 'setEmployeeId.'

Can anyone tell me why I shouldn't be able to use the extension the same way I'd use the other properties? Thanks for your help!!!

Tony Armstrong
  • 638
  • 7
  • 17

1 Answers1

3

Because your employeeId property is 'private' if you have declared it using an continuation category in the .m file of your class. This means the compiler won't 'see' the definition during compilation - hence the array.

Technically, you could still access it at runtime using KVC, but you should really decide if the property should be public or private.

If you're testing / messing around then you can redeclare the property in a local category to make it visible during compilation.

Wain
  • 118,658
  • 15
  • 128
  • 151
  • 1
    Yes, it is *only* about visibility (I got that wrong in my answer). You can even define the class extension in a separate header file and include that wherever you need it. – Martin R Apr 06 '14 at 16:38