[SOLVED] Weird inheritance problem

Discussion in 'iOS Programming' started by SuperZeroIce, Jun 21, 2010.

  1. SuperZeroIce macrumors newbie

    Joined:
    Jun 5, 2010
    #1
    I'm constantly getting a warning from the compiler when initializing a subclass:
    Incompatible Objective-C types initializing 'struct Module *', expected 'struct Relais *'

    It happens when the following line is called:

    Code:
    Relais *object = [[Relais alloc] initWithIdentifier:identifier description:description];
    There's probably a very simple solution, but this is my second day of learning ObjC. And coming from the wonderful world of Java, I'm having a hard time figuring this one out :D

    Module.h:
    Code:
    #import <Foundation/Foundation.h>
    
    
    @interface Module : NSObject {
    	NSString *identifier;
    	NSString *description;
    	
    }
    
    -(Module *) initWithIdentifier: (NSString *) pIdentifier description: (NSString *) pDescription; 
    
    
    -(void) setIdentifier: (NSString *) pIdentifier;
    -(void) setDescription: (NSString *) pDescription;
    
    -(NSString *) identifier;
    -(NSString *) description;
    
    @end
    
    Module.m:
    Code:
    #import "Module.h"
    
    
    @implementation Module
    
    
    -(Module *) initWithIdentifier: (NSString *) pIdentifier description: (NSString *) pDescription
    {
    	self = [super init];
    	
    	if (self) {
    		[self setIdentifier:pIdentifier];
    		[self setDescription:pDescription];
    	}
    	
    	return self;
    }
    
    
    -(void) setIdentifier: (NSString *) pIdentifier
    {
    	identifier = pIdentifier;
    }
    
    -(void) setDescription: (NSString *) pDescription
    {
    	description = pDescription;
    }
    
    
    -(NSString *) identifier{
    	return identifier;
    }
    
    -(NSString *) description{
    	return description;
    }
    
    @end
    
    Relais.h:
    Code:
    #import <Foundation/Foundation.h>
    #import "Module.h"
    
    @interface Relais : Module {
    	BOOL aan;
    
    }
    
    -(Relais *) initWithIdentifier: (NSString *) pIdentifier description: (NSString *) pDescription;
    
    
    - (void) setAan: (BOOL) pAan;
    
    - (BOOL) aan;
    
    
    -(NSString *) aanCommando;
    -(NSString *) uitCommando;
    
    
    @end
    Relais.m
    Code:
    #import "Relais.h"
    
    
    @implementation Relais
    
    
    -(Relais *) initWithIdentifier: (NSString *) pIdentifier description: (NSString *) pDescription
    {
    	self = [super init];
    	
    	if (self) {
    		[self setIdentifier:pIdentifier];
    		[self setDescription:pDescription];
    	}
    	
    	return self;
    }
    
    
    
    - (void) setAan: (BOOL) pAan
    {
    	aan = pAan;
    }
    
    - (BOOL) aan
    {
    	
    	return aan;
    }
    
    
    -(NSString *) aanCommando {
    	return [identifier stringByAppendingString:@"%I"];
    	
    }
    -(NSString *) uitCommando {
    	return [identifier stringByAppendingString:@"%O"];
    	
    }
    
    
    @end
    Strangely enough the initWithIdentifier method IS called from the subclass 'Relais', and all methods from 'Relais' are indeed accessible :confused: :confused:
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    Generally all init/initWithX: methods should return id (and not Type *). Try changing both .h and .m files to that.
     
  3. SuperZeroIce thread starter macrumors newbie

    Joined:
    Jun 5, 2010

Share This Page