Skip to content

Instantly share code, notes, and snippets.

@tedhagos
Created November 22, 2012 02:56
Show Gist options
  • Select an option

  • Save tedhagos/4129200 to your computer and use it in GitHub Desktop.

Select an option

Save tedhagos/4129200 to your computer and use it in GitHub Desktop.
delme
/*
Had trouble with [obj objname], it is not [obj getObjname], when
you are getting, simply call the instance member name, it is not
a string get/set pair with @property and @synthesize
Also, learn the following;
1. self
2. init
3. [super init], what is the call chain
This is the canonical constructor in Objective C
There are no static members of class in Objective C. The static keyword
does not (semantically) pertain to class members. There are only class
methods but no such thing as a class variable. Question then, can a class method
access an instance variable ... lets find out
*/
#import <Foundation/Foundation.h>
#import "Obj.h"
@implementation Obj
@synthesize objname;
- (id) init {
self = [super init];
if (self) {
NSLog(@"In the CTOR of Obj");
}
return self;
}
+ (void) foo {
//NSLog(@ "Class method foo printing %@ ", objname);
//Cannot do this.
NSLog(@"Class method foo");
}
- (void) goo {
NSLog(@ "Instance method goo printing %@", objname);
}
@end
///////////////////////////////////
int main() {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
Obj * obj = [[[Obj alloc] init] autorelease];
[obj setObjname: @"The object name"];
NSLog( @ "%@", [obj objname]);
[Obj foo];
[obj goo];
[pool drain];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment