Skip to content

Instantly share code, notes, and snippets.

@theiostream
Created November 10, 2013 17:03
Show Gist options
  • Save theiostream/7400856 to your computer and use it in GitHub Desktop.
Save theiostream/7400856 to your computer and use it in GitHub Desktop.
A pretty simple/dumb Objective-C pair object.
@interface Pair : NSObject {
@public
id obj1;
id obj2;
}
- (id)initWithObjects:(id)object, ...;
@end
@implementation Pair
- (id)initWithObjects:(id)object, ... {
if ((self = [super init])) {
va_list args;
va_start(args, object);
obj1 = [object retain];
obj2 = [va_arg(args, id) retain];
va_end(args);
}
return self;
}
- (void)dealloc {
[obj1 release];
[obj2 release];
[super dealloc];
}
@end
/* A simple Obj-C pair!
Initialization: Pair *x = [[Pair alloc] initWithObjects:obj1, obj2];
Member Getting: x->obj1; x->obj2;
Member setting: x->obj1 = [obj1 retain]; x->obj2 = [obj2 retain];
Releasing: [x release]; */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment