Last active
December 16, 2015 03:09
-
-
Save aug2uag/5367393 to your computer and use it in GitHub Desktop.
Objective-C constructor example
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
@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