pEpObjCAdapter/NSArray+Extension.m
author Dirk Zimmermann <dirk@pep-project.org>
Wed, 17 May 2017 09:27:57 +0200
changeset 187 1f630a05e444
permissions -rw-r--r--
IOSAD-15 more renames
     1 //
     2 //  NSArray+Extension.m
     3 //  pEpiOSAdapter
     4 //
     5 //  Created by Dirk Zimmermann on 03.05.17.
     6 //  Copyright © 2017 p≡p. All rights reserved.
     7 //
     8 
     9 #import "NSArray+Extension.h"
    10 
    11 @implementation ArrayTake
    12 
    13 - (instancetype)initWithElements:(NSArray * _Nonnull)elements rest:(NSArray * _Nonnull)rest
    14 {
    15     if (self = [super init]) {
    16         _elements = elements;
    17         _rest = rest;
    18     }
    19     return self;
    20 }
    21 
    22 @end
    23 
    24 @implementation NSArray (Extension)
    25 
    26 - (ArrayTake * _Nullable)takeOrNil:(NSInteger)count
    27 {
    28     if (self.count >= count) {
    29         NSInteger restCount = self.count - count;
    30         NSArray *elements = [self subarrayWithRange:NSMakeRange(0, count)];
    31         NSArray *rest = [self subarrayWithRange:NSMakeRange(count, restCount)];
    32         ArrayTake *taken = [[ArrayTake alloc] initWithElements:elements rest:rest];
    33         return taken;
    34     }
    35     return nil;
    36 }
    37 
    38 @end