Skip to content

Instantly share code, notes, and snippets.

@theiostream
Created November 10, 2013 17:03

Revisions

  1. theiostream revised this gist Nov 10, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Pair.m
    Original file line number Diff line number Diff line change
    @@ -33,4 +33,4 @@ - (void)dealloc {
    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];
    Releasing: [x release]; */
  2. theiostream created this gist Nov 10, 2013.
    36 changes: 36 additions & 0 deletions Pair.m
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    @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];