Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added a method to format an array as seperated list by a given delimiter

  • Loading branch information...
commit e58b5708a63dcbf9a9431058f53ba24e8c37435d 1 parent 169f344
@jk authored
Showing with 43 additions and 0 deletions.
  1. +14 −0 NSArrayAdditions.h
  2. +29 −0 NSArrayAdditions.m
View
14 NSArrayAdditions.h
@@ -0,0 +1,14 @@
+//
+// NSArrayAdditions.h
+// JobStairs
+//
+// Created by Jens Kohl on 23.02.10.
+// Copyright 2010 Jens Kohl. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@interface NSArray (JKAdditions)
+- (NSString*)asStringWithDelimiter:(NSString *)delimiter;
+@end
+
View
29 NSArrayAdditions.m
@@ -0,0 +1,29 @@
+//
+// NSArrayAdditions.m
+// JobStairs
+//
+// Created by Jens Kohl on 23.02.10.
+// Copyright 2010 Jens Kohl. All rights reserved.
+//
+
+#import "NSArrayAdditions.h"
+
+
+@implementation NSArray (JKAdditions)
+
+- (NSString*)asStringWithDelimiter:(NSString *)delimiter {
+ NSMutableString *string = [NSMutableString string];
+ NSUInteger countdown = [self count];
+
+ for (id item in self) {
+ [string appendString:[item description]];
+ countdown--;
+ if (countdown > 0) {
+ [string appendString:delimiter];
+ }
+ }
+
+ return [NSString stringWithString:string];
+}
+
+@end
Please sign in to comment.
Something went wrong with that request. Please try again.