Working with Classes (inheriting), @ properties and Initialization I'm working on this Objective C programming assignment I found online.  I'm not sure if I have met all the requirements, especially part C. Any help or suggestion will be appreciated.


  Part 6
  
  a) Implement class A with properties a1, a2, and a3 (int,
  string, int).
  
  b) New objects are automatically initialized to 1, "hello", 1.
  
  c) Also provide initializer to any data and constructor (called
  without alloc) to do the same.
  
  d) Make sure %@ ob object of A will print all data.
  
  e) Then implement B inheriting from A. B adds property b (string). 
  
  f) Make sure B works as A, that is new object is initialized to 1, "hello", 1, and 3 (the new data). The rest also must work on B.


   //classA.h file
#import &lt;Foundation/Foundation.h&gt;

@interface ClassA : NSObject
// Part 6a
@property int a1;
@property NSString *a2;
@property int a3;

-(NSString *) description;
-(id) initWithA1: (int) x andA2: (NSString *) s andA3: (int) y;
-(id) init;
@end


//classA.m file
#import "ClassA.h"

@implementation ClassA



-(id) initWithA1:(int)x andA2:(NSString *)s andA3:(int)y {
    self = [super init];
    if (self) {
        self.a1 = x;
        self.a2 = s;
        self.a3 = y;
    }
    return self;
}

// part 6b
- (id) init {
    return [self initWithA1:1 andA2:@"hello" andA3:1];
}

// part 6d
-(NSString *) description {
    return [NSString stringWithFormat:@"ClassA a1 = %d , a2 = %@ , a3 = %d", self.a1, self.a2, self.a3];
}

@end


//classB.h file
#import "ClassA.h"

@interface ClassB : ClassA
@property int a1;
@property NSString *a2;
@property int a3;
@property NSString * b;

-(NSString *) description;
-(id) initWithA1:(int)x andA2:(NSString *)s andA3:(int)y andB: (NSString *) z;
-(id) init;
@end


//classB.m file
#import "ClassB.h"

@implementation ClassB

-(id) initWithA1:(int)x andA2:(NSString *)s andA3:(int)y andB:(NSString *)z {
    self = [super init];
    if (self) {
        self.a1 = x;
        self.a2 = s;
        self.a3 = y;
        self.b = z;
    }
    return self;
}

-(id) init {
    return [self initWithA1:1 andA2:@"hello" andA3:1 andB:@"3"];
}

-(NSString *) description {
    return [NSString stringWithFormat:@"ClassB a1 = %d , a2 = %@ , a3 = %d , b = %@" , self.a1, self.a2, self.a3, self.b];
}

@end



//viewController.m file
#import "ViewController.h"
#import "ClassA.h"
#import "ClassB.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    ClassA * a = [ClassA new];
    NSLog(@"%@", a);

    ClassB * j = [ClassB new];
    NSLog (@"%@", j);
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
This is my first review so bear that in mind when you are reading it.

The first thing I see is that in the initialization, you should not use the automatic setters and getters for properties.  The reason for this is that the object may not be completely initialized, and thus may fail.  So instead of doing: 

self.a1 = x;
self.a2 = s;
self.a3 = y;


access the properties directly like so:

_a1 = x; 
_a2 = s;
_a3 = y;


Otherwise, your init pattern is good, and bonus points for having a default -(id)init that calls your designated initializer.  

For the names of all of these, I would make sure to always use a more descriptive name.  It is probably okay in such a simple example to use a1, x, y, etc, but for anything more complicated, use names that describe in more detail exactly what the variable is.

In the description method it looks like you are calling the int values with %d.  I can't think of a reason not to use %i, but maybe I am wrong here.

One last thing, in the interface the spacing inside the declaration of -(id)initWithEtc is loose.  It looks correct in the implementation though.