0

I have this hierarchy:

CreateAnObjectClass : NSObject

MySecondClass : MyBaseClass
    MyBaseClass : NSObject

in CreateAnObjectClass I want to create an instance of MySecondClass method and i want to pass a @property (strong,nonatomic) NSDictionary* myTemplate to myBaseClass.

For example:

CreateAnObjectClass *testObj = [[MySecondClass alloc] initWithTemplate:myTemplate];

And I know that calls both initializers from MyBaseClass and MySecondClass.

(id)initWithTemplate:(NSDictionary*)myTemplate
{
  self = [super init]

  return self;
}

My question is how I should designe initializers to myTamplate can be a property at MyBaseClass?

Jakub
  • 13,712
  • 17
  • 82
  • 139

1 Answers1

0

Like this:

- (id)initWithTemplate:(NSDictionary*)aTemplate
{
  self = [super init]
  if (self){
    self.myTemplate=aTemplate;
  }
  return self;
}

Edit 1:

Remember the following, calling this:

  self = [super init];

On the MySecondClass will call the init method on the MyBaseClass

Rui Peres
  • 25,741
  • 9
  • 87
  • 137
  • But this create a property in MySecondClass. I need it in MyBaseClass – Jakub May 08 '12 at 11:53
  • `MyBaseClass` is the super class of `MySecondClass`, so just put the init method on the `MyBaseClass`. – Rui Peres May 08 '12 at 11:55
  • As i said i already know that, but what i don't know if i have to pass myTemplate to initializer to MyBaseClass? I should have initWithTemplate: in MyBaseClass? – Jakub May 08 '12 at 14:24
  • Yes why not? I don't see why you didn't did that before. – Rui Peres May 08 '12 at 16:06