mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
38 lines
914 B
Objective-C
38 lines
914 B
Objective-C
#import "ArrayUtil.h"
|
|
#import "Constraints.h"
|
|
|
|
@implementation NSArray (Util)
|
|
|
|
-(NSData*) toUint8Data {
|
|
NSUInteger n = self.count;
|
|
uint8_t x[n];
|
|
for (NSUInteger i = 0; i < n; i++) {
|
|
x[i] = [(NSNumber*)self[i] unsignedCharValue];
|
|
}
|
|
return [NSData dataWithBytes:x length:n];
|
|
}
|
|
-(NSData*) concatDatas {
|
|
NSUInteger t = 0;
|
|
for (id d in self) {
|
|
require([d isKindOfClass:[NSData class]]);
|
|
t += [(NSData*)d length];
|
|
}
|
|
|
|
NSMutableData* result = [NSMutableData dataWithLength:t];
|
|
uint8_t* dst = [result mutableBytes];
|
|
for (NSData* d in self) {
|
|
memcpy(dst, [d bytes], d.length);
|
|
dst += d.length;
|
|
}
|
|
return result;
|
|
}
|
|
-(NSArray*) concatArrays {
|
|
NSMutableArray* r = [NSMutableArray array];
|
|
for (id e in self) {
|
|
require([e isKindOfClass:[NSArray class]]);
|
|
[r addObjectsFromArray:e];
|
|
}
|
|
return r;
|
|
}
|
|
|
|
@end
|