Skip to content

Instantly share code, notes, and snippets.

@aug2uag
Last active December 16, 2015 03:09
Show Gist options
  • Save aug2uag/5367393 to your computer and use it in GitHub Desktop.
Save aug2uag/5367393 to your computer and use it in GitHub Desktop.
Objective-C constructor example
@interface ClassName : NSObject
{
int integer_instance_variable;
NSString *string_instance_variable;
//add ivars as needed
}
@end
@implementation ClassName
- (id)init
{
self = [super init];
if (self)
{
integer_instance variable = //enter number value here
string_instance_variable = //enter string value here
}
return self;
}
@end
int main()
{
NSAutoReleasePoll *pool = [[NSAutoReleasePool alloc] init];
ClassName *object_name = [[ClassName alloc] init];
[pool drain];
return 0;
}
@implementation ClassName
-(id) initWithNumber:(int)theNumberValue initWithString:(NSString *)theStringValue
{
if (self = [super init])
{
integer_instance_variable = theNumberValue;
string_instance_variable = theStringValue;
}
return self;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment