mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
f65d552f6d
Begin process of prefixing categories on Foundation and UIKit. This follows Cocoa best practices. This makes sense given the number of third party libraries the project incorporates, which may include their own colliding category method names. Use OWS prefix on classes that may be used across apps.
39 lines
919 B
Objective-C
39 lines
919 B
Objective-C
#import "ArrayUtil.h"
|
|
#import "Constraints.h"
|
|
|
|
@implementation NSArray (Util)
|
|
|
|
-(NSData*)ows_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*)ows_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*)ows_concatArrays {
|
|
NSMutableArray* r = [NSMutableArray array];
|
|
for (id e in self) {
|
|
require([e isKindOfClass:NSArray.class]);
|
|
[r addObjectsFromArray:e];
|
|
}
|
|
return r;
|
|
}
|
|
|
|
@end
|