Created
August 30, 2013 07:58
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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