A sample interface in Objective-C

// Card.h file source code begin
#import <Foundation/Foundation.h>
@interface Card : NSObject

// this instance variable has a public access modifier
// strong indicates to object is being kept 
// as long as it is used and has no other references
// nonatomic corresponds to non thread safety
// non atomic also creates setter and getter methods
// asteriks used to indicated to a point defined on heap
@property (strong,nonatomic) NSString *contents

// primitive types do not need to be defined with asteriks
// moreover there is no strong and weak keywords to be defined 
// because primitives are not stored on heap
// we can also name the getter method of the getter in implementation
@property (nonatomic, getter=isChosen) BOOL chosen;
@property (nonatomic, getter=isMatched) BOOL matched 

@end
// Card.h file source code end


// Card.m file source code begin
#import "Card.h"

//a private interface can be defined
@interface Card(){
}
@end

@implementation Card

// setter and getter methods are automatically created,
// in case explicitly they can be created but no need for it
// because of definition in the header file,
// all the setter and getter methods are created
@synthesize contents = _contents;

// getter method
-(NSString *) contents{
	return _contents;
}

// setter method
-(void) setContents:(NSString *) contents{
	_contents = contents;
}

@end
// Card.m file source code end

Leave a Reply

Your email address will not be published. Required fields are marked *