Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
NSDataを指定サイズに分割する
/**
* NSDataを指定サイズに分割する
*
*/
+ (NSArray *)splitDataWithData:(NSData *)data splitSize:(int)size
{
NSRange dataRange;
NSInteger dataSize = data.length;
NSInteger dataSplitCount = dataSize/size;
dataRange.length = size;
dataRange.location = 0;
NSMutableArray *dataArray = [NSMutableArray array];
for(NSInteger cnt = 0;cnt<dataSplitCount;cnt++) {
[dataArray addObject:[data subdataWithRange:dataRange]];
dataRange.location += size;
}
// 最後のデータは、長さを調整してから処理を行う
dataRange.length = dataSize % size;
[dataArray addObject:[data subdataWithRange:dataRange]];
return dataArray;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment