summaryrefslogtreecommitdiff
path: root/Juick/Helpers/NSData+Hex.m
blob: 243a380c6d6c08bfc69c5e9547726f758ef41650 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//
//  NSData+Hex.m
//  Juick
//
//  Created by Vitaly Takmazov on 01/10/2019.
//  Copyright © 2019 com.juick. All rights reserved.
//

#import "NSData+Hex.h"

@implementation NSData (Hex)
- (NSString *)hexString {
    NSMutableString *string = [NSMutableString stringWithCapacity:self.length * 3];
    [self enumerateByteRangesUsingBlock:^(const void *bytes, NSRange byteRange, BOOL *stop){
        for (NSUInteger offset = 0; offset < byteRange.length; ++offset) {
            uint8_t byte = ((const uint8_t *)bytes)[offset];
            [string appendFormat:@"%02x", byte];
        }
    }];
    return string;
}
@end