"No visible interface error" - initWithProductName

initWIthProductName() (which is in the parent class:BNRAppliance) is not accessible from child class (BNROwnedAppliance).

“BNRAppliance.h” is included in the BNROwnedAppliance.h" (as a super class). And there is initWithProductName() declaration in the “BNRAppliance.h”.

The error is "No visible @interface for ‘BNRAppliance’ declares the selector ‘initWithProductName’ "

Thanks in advance.

Could you paste some of your code to show what you are doing?

Here are the codes. Thanks.

BNRAppliance.h

#import <Foundation/Foundation.h>

@interface BNRAppliance : NSObject

@property (nonatomic, copy) NSString *productName;
@property (nonatomic) int voltage;

-(instancetype)initWithProductName:(NSString *)pn;

@end

BNRAppliance.m

#import "BNRAppliance.h"

@implementation BNRAppliance

-(instancetype)init
{
    return [self initWithProductName:@"Unknown"];
}

- (instancetype)initWithProductName:(NSString *)pn
{
    if ( self = [super init]) {
        
        _productName = [pn copy];
        _voltage = 120;
    }
    return self;
}

-(NSString*)description
{
    return [NSString stringWithFormat:@"<%@: %d volts", self.productName, self.voltage];
}
@end

BNROwnedAppliance.h

[code]#import “BNRAppliance.h”

@interface BNROwnedAppliance : BNRAppliance

@property (readonly) NSSet *ownerNames;

-(instancetype)initWithProductName:(NSString *)pn firstOwnerName:(NSString *)n;
-(void)addOwnerName:(NSString *)n;
-(void)removeOwnerName:(NSString *)n;

@end
[/code]

BNROwnedAppliance.m


#import "BNROwnedAppliance.h"

@interface BNROwnedAppliance ()
{
    NSMutableSet *_ownerNames;
}

@end


@implementation BNROwnedAppliance


- (instancetype)initWithProductName:(NSString *)pn firstOwnerName:(NSString *)n
{
    
    // Call the superclass's initializer
    if (self = [super initWithProductName:pn]){
       
        // Create a set to hold owners names
        _ownerNames = [[NSMutableSet alloc] init];
    
        // Is the first owner name non-nil?
        if (n) {
            [_ownerNames addObject:n];
        }
    }
// Return a pointer to the new object
return self;
}

-(void)addOwnerName:(NSString *)n
{
    [_ownerNames addObject:n];
}

-(void)removeOwnerName:(NSString *)n
{
    [_ownerNames removeObject:n];
}

-(NSSet *)ownerNames
{
    return [_ownerNames copy];
}

@end

Everything appears to be fine to me, so am not sure why you are getting the error you are.

Thanks for checking my code. I cleaned and rerun the code but it still has same error.