Skip to content

Instantly share code, notes, and snippets.

@goooooouwa
Created August 30, 2013 07:58
Show Gist options
  • Save goooooouwa/6387360 to your computer and use it in GitHub Desktop.
Save goooooouwa/6387360 to your computer and use it in GitHub Desktop.
This gist shows you how to define public and private method and property, also where to define instance variable.
//
// className.h
// Objective-C exploration
//
// Created by Greg Xu on 8/30/13.
// Copyright (c) 2013 Greg Xu. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface ClassName : NSObject {
//instance variables declaration can go here
NSString *instanceVariable;
}
//public properties and methods declaration goes here
@property NSString *publicProperty;
-(void)publicMethod;
@end
//
// className.m
// Objective-C exploration
//
// Created by Greg Xu on 8/30/13.
// Copyright (c) 2013 Greg Xu. All rights reserved.
//
#import "ClassName.h"
@interface ClassName () {
//instance variables declaration can also go here
NSString *anotherInstanceVariable;
}
//private properties and methods declaration goes here
@property NSString *privateProperty;
-(void)privateMethod;
@end
@implementation ClassName
-(void)publicMethod{
self.publicProperty = @"publicProperty";
self->instanceVariable = @"instanceVariable";
NSLog(@"publicMethod and %@ and %@",self.publicProperty, self->instanceVariable);
[self privateMethod];
}
-(void)privateMethod{
self.privateProperty = @"privateProperty";
self->anotherInstanceVariable = @"anotherInstanceVariable";
NSLog(@"privateMethod and %@ and %@",self.privateProperty, self->anotherInstanceVariable);
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment