Skip to content

Instantly share code, notes, and snippets.

@alexrozanski
Created March 6, 2010 22:26
Show Gist options
  • Select an option

  • Save alexrozanski/323983 to your computer and use it in GitHub Desktop.

Select an option

Save alexrozanski/323983 to your computer and use it in GitHub Desktop.

Revisions

  1. Perspx created this gist Mar 6, 2010.
    4 changes: 4 additions & 0 deletions NSArray+PXArrayAdditions.h
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    @interface NSArray (PXArrayAdditions)
    - (id)initWithObject:(id)object;
    - (id)firstObject;
    @end
    19 changes: 19 additions & 0 deletions NSArray+PXArrayAdditions.m
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    @implementation NSArray (PXArrayAdditions)

    - (id)initWithObject:(id)object
    {
    return [self initWithObjects:object,nil];
    }

    //Follows -lastObject in that returns nil if no objects present
    - (id)firstObject
    {
    if([self count]>0) {
    return [self objectAtIndex:0];
    }
    else {
    return nil;
    }
    }

    @end